Skip to content
Open
5 changes: 5 additions & 0 deletions .changeset/beholder-metric-views-deny-attributes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"chainlink": patch
---

#added Add `Telemetry.MetricViewsDenyAttributes` config option to drop specified metric attribute keys from Beholder default views.
5 changes: 3 additions & 2 deletions core/cmd/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,9 @@ func newBeholderClient(
LogMaxQueueSize: cfgTelemetry.LogMaxQueueSize(),
// Due to OpenTelemetry semantics, histogram bucket boundaries must be set
// when the Beholder client is constructed.
MetricViews: metricViews(),
MetricCardinalityLimit: cfgTelemetry.MetricCardinalityLimit(),
MetricViews: metricViews(),
MetricViewsDenyAttributes: cfgTelemetry.MetricViewsDenyAttributes(),
MetricCardinalityLimit: cfgTelemetry.MetricCardinalityLimit(),
}

if cfgTracing.Enabled() {
Expand Down
3 changes: 3 additions & 0 deletions core/config/docs/core.toml
Original file line number Diff line number Diff line change
Expand Up @@ -928,6 +928,9 @@ LogExportMaxBatchSize = 512 # Default
LogExportInterval = '1s' # Default
# LogMaxQueueSize sets the maximum queue size used by the batcher
LogMaxQueueSize = 2048 # Default
# MetricViewsDenyAttributes lists attribute keys dropped before export (e.g. event_id).
# Empty disables default Beholder metric attribute deny views.
MetricViewsDenyAttributes = ['event_id'] # Default
# MetricCardinalityLimit sets the OTel SDK per-instrument attribute-set limit (0 disables).
MetricCardinalityLimit = 100000 # Default

Expand Down
1 change: 1 addition & 0 deletions core/config/telemetry_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type Telemetry interface {
LogExportMaxBatchSize() int
LogExportInterval() time.Duration
LogMaxQueueSize() int
MetricViewsDenyAttributes() []string
MetricCardinalityLimit() int
PrometheusBridge() PrometheusBridge
}
Expand Down
7 changes: 5 additions & 2 deletions core/config/toml/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -3002,13 +3002,13 @@
LogExportMaxBatchSize *int
LogExportInterval *commonconfig.Duration
LogMaxQueueSize *int

MetricCardinalityLimit *int
MetricViewsDenyAttributes []string
MetricCardinalityLimit *int

PrometheusBridge PrometheusBridge `toml:",omitempty"`
}

func (b *Telemetry) setFrom(f *Telemetry) {

Check warning on line 3011 in core/config/toml/types.go

View check run for this annotation

CL-sonarqube-production / SonarQube Code Analysis

Refactor this method to reduce its Cognitive Complexity from 33 to the 30 allowed.

[S3776] Cognitive Complexity of functions should not be too high See more on https://sonarqube.main.prod.cldev.sh/project/issues?id=smartcontractkit_chainlink&pullRequest=23085&issues=38b71be8-7bb3-4b2a-bf3c-b21dc0d101ef&open=38b71be8-7bb3-4b2a-bf3c-b21dc0d101ef
if v := f.Enabled; v != nil {
b.Enabled = v
}
Expand Down Expand Up @@ -3102,6 +3102,9 @@
if v := f.LogMaxQueueSize; v != nil {
b.LogMaxQueueSize = v
}
if v := f.MetricViewsDenyAttributes; v != nil {
b.MetricViewsDenyAttributes = v
}
if v := f.MetricCardinalityLimit; v != nil {
b.MetricCardinalityLimit = v
}
Expand Down
7 changes: 7 additions & 0 deletions core/services/chainlink/config_telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,14 @@ func (b *telemetryConfig) LogMaxQueueSize() int {
return *b.s.LogMaxQueueSize
}

func (b *telemetryConfig) MetricViewsDenyAttributes() []string {
return b.s.MetricViewsDenyAttributes
}

func (b *telemetryConfig) MetricCardinalityLimit() int {
if b.s.MetricCardinalityLimit == nil {
return 100000
}
return *b.s.MetricCardinalityLimit
}

Expand Down
21 changes: 21 additions & 0 deletions core/services/chainlink/config_telemetry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,27 @@ func TestTelemetryConfig_LogMaxQueueSize(t *testing.T) {
}
}

func TestTelemetryConfig_MetricViewsDenyAttributes(t *testing.T) {
t.Parallel()
tests := []struct {
name string
telemetry toml.Telemetry
expected []string
}{
{"DenylistSet", toml.Telemetry{MetricViewsDenyAttributes: []string{"event_id"}}, []string{"event_id"}},
{"DenylistNil", toml.Telemetry{MetricViewsDenyAttributes: nil}, nil},
{"DenylistEmpty", toml.Telemetry{MetricViewsDenyAttributes: []string{}}, []string{}},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
tc := telemetryConfig{s: tt.telemetry}
assert.Equal(t, tt.expected, tc.MetricViewsDenyAttributes())
})
}
}

func TestTelemetryConfig_MetricCardinalityLimit(t *testing.T) {
t.Parallel()
tests := []struct {
Expand Down
1 change: 1 addition & 0 deletions core/services/chainlink/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,7 @@ func TestConfig_Marshal(t *testing.T) {
LogExportMaxBatchSize: new(512),
LogExportInterval: ptrDuration(1 * time.Second),
LogMaxQueueSize: new(2048),
MetricViewsDenyAttributes: []string{"event_id"},
MetricCardinalityLimit: new(100000),

PrometheusBridge: toml.PrometheusBridge{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ LogExportTimeout = '1s'
LogExportMaxBatchSize = 512
LogExportInterval = '1s'
LogMaxQueueSize = 2048
MetricViewsDenyAttributes = ['event_id']
MetricCardinalityLimit = 100000

[Telemetry.PrometheusBridge]
Expand Down
1 change: 1 addition & 0 deletions core/services/chainlink/testdata/config-full.toml
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ LogExportTimeout = '1s'
LogExportMaxBatchSize = 512
LogExportInterval = '1s'
LogMaxQueueSize = 2048
MetricViewsDenyAttributes = ['event_id']
MetricCardinalityLimit = 100000

[Telemetry.ResourceAttributes]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ LogExportTimeout = '1s'
LogExportMaxBatchSize = 512
LogExportInterval = '1s'
LogMaxQueueSize = 2048
MetricViewsDenyAttributes = ['event_id']
MetricCardinalityLimit = 100000

[Telemetry.PrometheusBridge]
Expand Down
1 change: 1 addition & 0 deletions core/web/resolver/testdata/config-empty-effective.toml
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ LogExportTimeout = '1s'
LogExportMaxBatchSize = 512
LogExportInterval = '1s'
LogMaxQueueSize = 2048
MetricViewsDenyAttributes = ['event_id']
MetricCardinalityLimit = 100000

[Telemetry.PrometheusBridge]
Expand Down
1 change: 1 addition & 0 deletions core/web/resolver/testdata/config-full.toml
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ LogExportTimeout = '1s'
LogExportMaxBatchSize = 512
LogExportInterval = '1s'
LogMaxQueueSize = 2048
MetricViewsDenyAttributes = ['event_id']
MetricCardinalityLimit = 100000

[Telemetry.ResourceAttributes]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ LogExportTimeout = '1s'
LogExportMaxBatchSize = 512
LogExportInterval = '1s'
LogMaxQueueSize = 2048
MetricViewsDenyAttributes = ['event_id']
MetricCardinalityLimit = 100000

[Telemetry.PrometheusBridge]
Expand Down
8 changes: 8 additions & 0 deletions docs/CONFIG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2412,6 +2412,7 @@ LogExportTimeout = '1s' # Default
LogExportMaxBatchSize = 512 # Default
LogExportInterval = '1s' # Default
LogMaxQueueSize = 2048 # Default
MetricViewsDenyAttributes = ['event_id'] # Default
MetricCardinalityLimit = 100000 # Default
```
Telemetry holds OTEL settings.
Expand Down Expand Up @@ -2603,6 +2604,13 @@ LogMaxQueueSize = 2048 # Default
```
LogMaxQueueSize sets the maximum queue size used by the batcher

### MetricViewsDenyAttributes
```toml
MetricViewsDenyAttributes = ['event_id'] # Default
```
MetricViewsDenyAttributes lists attribute keys dropped before export (e.g. event_id).
Empty disables default Beholder metric attribute deny views.

### MetricCardinalityLimit
```toml
MetricCardinalityLimit = 100000 # Default
Expand Down
1 change: 1 addition & 0 deletions plugins/loop_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ func (m *LoopRegistry) Register(id string) (*RegisteredLoop, error) {
envCfg.TelemetryLogExportMaxBatchSize = m.cfgTelemetry.LogExportMaxBatchSize()
envCfg.TelemetryLogExportInterval = m.cfgTelemetry.LogExportInterval()
envCfg.TelemetryLogMaxQueueSize = m.cfgTelemetry.LogMaxQueueSize()
envCfg.TelemetryMetricViewsDenyAttributes = m.cfgTelemetry.MetricViewsDenyAttributes()
limit := m.cfgTelemetry.MetricCardinalityLimit()
envCfg.TelemetryMetricCardinalityLimit = &limit
envCfg.TelemetryPrometheusBridgeEnabled = m.cfgTelemetry.PrometheusBridge().Enabled()
Expand Down
4 changes: 4 additions & 0 deletions plugins/loop_registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ func (m mockCfgTelemetry) LogExportMaxBatchSize() int { return 512 }
func (m mockCfgTelemetry) LogExportInterval() time.Duration { return 5 * time.Second }
func (m mockCfgTelemetry) LogMaxQueueSize() int { return 2048 }

func (m mockCfgTelemetry) MetricViewsDenyAttributes() []string {
return []string{"event_id"}
}
func (m mockCfgTelemetry) MetricCardinalityLimit() int { return 100000 }

func (m mockCfgTelemetry) PrometheusBridge() config.PrometheusBridge {
Expand Down Expand Up @@ -272,6 +275,7 @@ func TestLoopRegistry_Register(t *testing.T) {
require.Equal(t, 512, envCfg.TelemetryLogExportMaxBatchSize)
require.Equal(t, 5*time.Second, envCfg.TelemetryLogExportInterval)
require.Equal(t, 2048, envCfg.TelemetryLogMaxQueueSize)
require.Equal(t, []string{"event_id"}, envCfg.TelemetryMetricViewsDenyAttributes)
require.NotNil(t, envCfg.TelemetryMetricCardinalityLimit)
require.Equal(t, 100000, *envCfg.TelemetryMetricCardinalityLimit)

Expand Down
1 change: 1 addition & 0 deletions testdata/scripts/config/merge_raw_configs.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,7 @@ LogExportTimeout = '1s'
LogExportMaxBatchSize = 512
LogExportInterval = '1s'
LogMaxQueueSize = 2048
MetricViewsDenyAttributes = ['event_id']
MetricCardinalityLimit = 100000

[Telemetry.PrometheusBridge]
Expand Down
1 change: 1 addition & 0 deletions testdata/scripts/node/validate/default.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,7 @@ LogExportTimeout = '1s'
LogExportMaxBatchSize = 512
LogExportInterval = '1s'
LogMaxQueueSize = 2048
MetricViewsDenyAttributes = ['event_id']
MetricCardinalityLimit = 100000

[Telemetry.PrometheusBridge]
Expand Down
1 change: 1 addition & 0 deletions testdata/scripts/node/validate/defaults-override.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@ LogExportTimeout = '1s'
LogExportMaxBatchSize = 512
LogExportInterval = '1s'
LogMaxQueueSize = 2048
MetricViewsDenyAttributes = ['event_id']
MetricCardinalityLimit = 100000

[Telemetry.PrometheusBridge]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ LogExportTimeout = '1s'
LogExportMaxBatchSize = 512
LogExportInterval = '1s'
LogMaxQueueSize = 2048
MetricViewsDenyAttributes = ['event_id']
MetricCardinalityLimit = 100000

[Telemetry.PrometheusBridge]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ LogExportTimeout = '1s'
LogExportMaxBatchSize = 512
LogExportInterval = '1s'
LogMaxQueueSize = 2048
MetricViewsDenyAttributes = ['event_id']
MetricCardinalityLimit = 100000

[Telemetry.PrometheusBridge]
Expand Down
1 change: 1 addition & 0 deletions testdata/scripts/node/validate/disk-based-logging.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ LogExportTimeout = '1s'
LogExportMaxBatchSize = 512
LogExportInterval = '1s'
LogMaxQueueSize = 2048
MetricViewsDenyAttributes = ['event_id']
MetricCardinalityLimit = 100000

[Telemetry.PrometheusBridge]
Expand Down
1 change: 1 addition & 0 deletions testdata/scripts/node/validate/fallback-override.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,7 @@ LogExportTimeout = '1s'
LogExportMaxBatchSize = 512
LogExportInterval = '1s'
LogMaxQueueSize = 2048
MetricViewsDenyAttributes = ['event_id']
MetricCardinalityLimit = 100000

[Telemetry.PrometheusBridge]
Expand Down
1 change: 1 addition & 0 deletions testdata/scripts/node/validate/invalid-ocr-p2p.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,7 @@ LogExportTimeout = '1s'
LogExportMaxBatchSize = 512
LogExportInterval = '1s'
LogMaxQueueSize = 2048
MetricViewsDenyAttributes = ['event_id']
MetricCardinalityLimit = 100000

[Telemetry.PrometheusBridge]
Expand Down
1 change: 1 addition & 0 deletions testdata/scripts/node/validate/invalid.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,7 @@ LogExportTimeout = '1s'
LogExportMaxBatchSize = 512
LogExportInterval = '1s'
LogMaxQueueSize = 2048
MetricViewsDenyAttributes = ['event_id']
MetricCardinalityLimit = 100000

[Telemetry.PrometheusBridge]
Expand Down
1 change: 1 addition & 0 deletions testdata/scripts/node/validate/valid.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@ LogExportTimeout = '1s'
LogExportMaxBatchSize = 512
LogExportInterval = '1s'
LogMaxQueueSize = 2048
MetricViewsDenyAttributes = ['event_id']
MetricCardinalityLimit = 100000

[Telemetry.PrometheusBridge]
Expand Down
1 change: 1 addition & 0 deletions testdata/scripts/node/validate/warnings.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ LogExportTimeout = '1s'
LogExportMaxBatchSize = 512
LogExportInterval = '1s'
LogMaxQueueSize = 2048
MetricViewsDenyAttributes = ['event_id']
MetricCardinalityLimit = 100000

[Telemetry.PrometheusBridge]
Expand Down
Loading