Wire resource attributes into Beholder ChipIngress emitters#2216
Conversation
✅ API Diff Results -
|
e6eabcc to
fdb6dee
Compare
✅ API Diff Results -
|
606a264 to
ada7f9b
Compare
| gopkg.in/yaml.v2 v2.4.0 // indirect | ||
| ) | ||
|
|
||
| replace github.com/smartcontractkit/chainlink-common/pkg/chipingress => ./pkg/chipingress |
There was a problem hiding this comment.
any way to avoid the local replace?
There was a problem hiding this comment.
For sure, will clean this up.
aa6b73c to
d6a531b
Compare
|
overall approach lgtm. Adding the CloudEvent extensions as the guaranteed propagation path makes sense, and we're keeping the gRPC header route for observability is reasonable |
2a6fa46 to
3ebb388
Compare
Pick up chip-ingress resource attribute propagation from smartcontractkit/chainlink-common#2216. Co-authored-by: Cursor <cursoragent@cursor.com>
e7e82a2 to
1f79a15
Compare
Pick up chip-ingress resource attribute propagation from smartcontractkit/chainlink-common#2216. Co-authored-by: Cursor <cursoragent@cursor.com>
Pick up chip-ingress resource attribute propagation from smartcontractkit/chainlink-common#2216. Co-authored-by: Cursor <cursoragent@cursor.com>
1f79a15 to
e1e0648
Compare
Pick up chip-ingress resource attribute propagation from smartcontractkit/chainlink-common#2216.
f5eda78 to
0a22a31
Compare
Pick up chip-ingress resource attribute propagation from smartcontractkit/chainlink-common#2216.
Pick up chip-ingress resource attribute propagation from smartcontractkit/chainlink-common#2216.
|
Split into two PRs:
|
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 8 out of 9 changed files in this pull request and generated 3 comments.
Comments suppressed due to low confidence (1)
pkg/beholder/chip_ingress_emitter.go:64
NewWithResourceAttributesstores the caller-providedmap[string]stringdirectly. Because maps are reference types, a caller could mutate the map after construction (or share it across goroutines), leading to data races or non-deterministic extensions. Copy the map before storing it internally.
var resourceAttrs *resourceAttrExtensions
if len(attrs) > 0 {
resourceAttrs = &resourceAttrExtensions{attrs: attrs}
}
| type ChipIngressBatchEmitterService struct { | ||
| services.Service | ||
| eng *services.Engine | ||
|
|
||
| batchClient *batch.Client | ||
| batchClient *batch.Client | ||
| resourceAttrs map[string]string | ||
|
|
| e := &ChipIngressBatchEmitterService{ | ||
| batchClient: batchClient, | ||
| metrics: metrics, | ||
| batchClient: batchClient, | ||
| resourceAttrs: resourceAttributesToStringMap(cfg.ResourceAttributes), | ||
| metrics: metrics, | ||
| } |
| attributes := newAttributes(attrKVs...) | ||
|
|
||
| event, err := chipingress.NewEvent(domain, entity, body, attributes) | ||
| event, err := chipingress.NewEventWithOpts(domain, entity, body, attributes, chipingress.WithResourceAttributeExtensions(e.resourceAttrs)) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to create CloudEvent: %w", err) | ||
| } |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 8 out of 9 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (1)
pkg/beholder/chip_ingress_emitter.go:64
- NewWithResourceAttributes stores the provided attrs map directly. Because Emit can be called concurrently, any external mutation of the map after construction could cause a data race (and surprising behavior). Consider defensively cloning the map before storing it in the emitter.
var resourceAttrs *resourceAttrExtensions
if len(attrs) > 0 {
resourceAttrs = &resourceAttrExtensions{attrs: attrs}
}
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 8 out of 9 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (2)
pkg/beholder/batch_emitter_service.go:26
- ChipIngressBatchEmitterService is an exported struct type; adding a
map[string]stringfield makes the type non-comparable, which can be an API-breaking change (similar to the concern noted in chip_ingress_emitter.go). Consider storing resource attributes behind a pointer wrapper (or another comparable container) to preserve type comparability, and only dereference it when stamping extensions.
type ChipIngressBatchEmitterService struct {
services.Service
eng *services.Engine
batchClient *batch.Client
resourceAttrs map[string]string
pkg/beholder/chip_ingress_emitter.go:64
- NewWithResourceAttributes stores the caller-provided
attrsmap directly. Because maps are mutable and not concurrency-safe, a caller mutating the map after construction (or concurrently with Emit) can cause data races or panics. Defensive-copy the map on entry before storing it on the emitter.
var resourceAttrs *resourceAttrExtensions
if len(attrs) > 0 {
resourceAttrs = &resourceAttrExtensions{attrs: attrs}
}
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 8 out of 9 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (2)
pkg/beholder/chip_ingress_emitter.go:64
- NewWithResourceAttributes stores the passed-in attrs map directly. Because maps are reference types, callers can mutate it after construction (or concurrently), which can change emitted events and potentially introduce data races. Consider defensively copying the map before storing it on the emitter.
var resourceAttrs *resourceAttrExtensions
if len(attrs) > 0 {
resourceAttrs = &resourceAttrExtensions{attrs: attrs}
}
pkg/beholder/batch_emitter_service.go:150
- emitInternal always uses NewEventWithOpts + WithResourceAttributeExtensions, even when no resource attributes are configured (resourceAttrs is an empty map). This adds overhead on every event and may inadvertently change behavior vs the previous NewEvent path. Consider only applying the opt when resourceAttrs is non-empty (mirroring ChipIngressEmitter.Emit).
attributes := newAttributes(attrKVs...)
event, err := chipingress.NewEventWithOpts(domain, entity, body, attributes, chipingress.WithResourceAttributeExtensions(e.resourceAttrs))
if err != nil {
return fmt.Errorf("failed to create CloudEvent: %w", err)
}
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 8 out of 9 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (1)
pkg/beholder/chip_ingress_emitter.go:64
- NewWithResourceAttributes stores the caller-provided
attrsmap directly on the emitter. If the caller later mutates that map (or shares it across goroutines), emits can race on concurrent map reads/writes. Since these attributes are meant to be static config, defensively clone the map before storing it.
var resourceAttrs *resourceAttrExtensions
if len(attrs) > 0 {
resourceAttrs = &resourceAttrExtensions{attrs: attrs}
}
Summary
Wire node resource attributes from
beholder.Config.ResourceAttributesinto the ChipIngress batch and sync emitters via CloudEvent extensions, so they reach thecretopic asce_<sanitized>Kafka headers.Changes
pkg/beholder/batch_emitter_service.go: store resource attributes and stamp them on each emitted event viachipingress.WithResourceAttributeExtensions.pkg/beholder/chip_ingress_emitter.go: same for the sync emitter.pkg/beholder/client.go: pass resource attributes into the ChipIngress client header provider.pkg/beholder/resource_attributes.go: addresourceAttributesToStringMaphelper.go.mod: bumppkg/chipingressto the resource-attributes branch (Add resource attribute support to ChipIngress client #2267).Related PRs
Test plan
go test ./pkg/beholder/...Notes
Co-authored-by: Cursorattribution has been removed from the commit history.ce_<name>headers immediately.pkg/durableemitterremains out of scope.