-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Validation for required attributes #865
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ package beholder | |
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"github.com/go-playground/validator/v10" | ||
"go.opentelemetry.io/otel/attribute" | ||
|
@@ -22,9 +23,9 @@ type Metadata struct { | |
// The version of the CL node. | ||
NodeVersion string | ||
// mTLS public key for the node operator. This is used as an identity key but with the added benefit of being able to provide signatures. | ||
NodeCsaKey string | ||
NodeCsaKey string `validate:"required"` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @4of9, are these going to be added as resource attributes to beholder config (since they are static) or we want to pass them as regular attributes? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was thinkin There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same applies to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We might want to add validation for resource attributes as well. |
||
// Signature from CSA private key. | ||
NodeCsaSignature string | ||
NodeCsaSignature string `validate:"required"` | ||
DonID string | ||
// The RDD network name the CL node is operating with. | ||
NetworkName []string | ||
|
@@ -41,6 +42,7 @@ type Metadata struct { | |
CapabilityVersion string | ||
CapabilityName string | ||
NetworkChainID string | ||
Timestamp time.Time | ||
} | ||
|
||
func (m Metadata) Attributes() Attributes { | ||
|
@@ -61,6 +63,7 @@ func (m Metadata) Attributes() Attributes { | |
"capability_version": m.CapabilityVersion, | ||
"capability_name": m.CapabilityName, | ||
"network_chain_id": m.NetworkChainID, | ||
"timestamp": m.Timestamp, | ||
} | ||
} | ||
|
||
|
@@ -160,6 +163,8 @@ func OtelAttr(key string, value any) otellog.KeyValue { | |
return otellog.Bool(key, v) | ||
case []byte: | ||
return otellog.Bytes(key, v) | ||
case time.Time: | ||
return otellog.Int64(key, v.Unix()) | ||
case nil: | ||
return otellog.Empty(key) | ||
case otellog.Value: | ||
|
@@ -211,13 +216,15 @@ func (m *Metadata) FromAttributes(attrs Attributes) *Metadata { | |
m.CapabilityName = v.(string) | ||
case "network_chain_id": | ||
m.NetworkChainID = v.(string) | ||
case "timestamp": | ||
m.Timestamp = v.(time.Time) | ||
} | ||
} | ||
return m | ||
} | ||
|
||
func NewMetadata(attrs Attributes) *Metadata { | ||
m := &Metadata{} | ||
m := &Metadata{Timestamp: time.Now().UTC()} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @nanchano, We should try not to use attributes with unbounded cardinality. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I could be wrong, but the unbounded cardinality issue is a problem for metrics, not for custom events, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How would we wanna represent a timestamp then? As a string and let clients parse it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It probably should be inside the custom message payload.
We can put it in the attribute and get back to it later. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Loki suffer from labels hight cardinality as well:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, but custom events are not sent to Loki, so the cardinality issue is at play here, I think |
||
m.FromAttributes(attrs) | ||
return m | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this would be an attribute, the signature will be coming through the authentication headers