Skip to content

[processor/attributes] Configuration options meant for traces-only should not pass validation on metrics. #36077

Closed
@atoulme

Description

@atoulme

Component(s)

processor/attributes

What happened?

Description

The attributes processor offers configuration options specific to traces or metrics.

When using a trace-only configuration option on the attributes processor with a metrics pipeline, validation passes and the option is silently ignored.

Steps to Reproduce

Use this attributes processor definition with a metrics pipeline:

attributes/servicesmetrics:
  include:
    match_type: strict
    services:
      - foo
  actions:
    - key: service.name
      value: bar
      action: insert
func TestMetricsUsedWithServices(t *testing.T) {
	cm, err := confmaptest.LoadConf(filepath.Join("testdata", "config.yaml"))
	require.NoError(t, err)

	factory := NewFactory()
	cfg := factory.CreateDefaultConfig()

	sub, err := cm.Sub("attributes/servicesmetrics")

	require.NoError(t, err)
	require.NoError(t, sub.Unmarshal(cfg))

	assert.NoError(t, component.ValidateConfig(cfg))

	sink := consumertest.MetricsSink{}

	p, err := NewFactory().CreateMetrics(context.Background(), processortest.NewNopSettings(), cfg, &sink)
	require.NoError(t, err)

	require.NoError(t, p.Start(context.Background(), componenttest.NewNopHost()))

	m := pmetric.NewMetrics()
	subM := m.ResourceMetrics().AppendEmpty().ScopeMetrics().AppendEmpty().Metrics().AppendEmpty()
	subM.SetName("myMetric")
	subM.SetEmptyGauge().DataPoints().AppendEmpty().SetDoubleValue(1.0)

	require.NoError(t, p.ConsumeMetrics(context.Background(), m))

	newSubM := sink.AllMetrics()[0].ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(0)

	newSubM.Gauge().DataPoints().At(0).Attributes().Range(func(k string, v pcommon.Value) bool {
		t.Logf("Key: %q, Value: %v", k, v.AsRaw())
		return true
	})
	assert.Equal(t, 0, newSubM.Gauge().DataPoints().At(0).Attributes().Len())
}

Expected Result

Validation should have failed or at least the attribute should not have been set.

Actual Result

The condition is ignored and the attribute is set.

=== RUN   TestMetricsUsedWithServices
    attributes_metric_test.go:497: Key: "service.name", Value: bar
    attributes_metric_test.go:500: 
        	Error Trace: attributes_metric_test.go:500
        	Error:      	Not equal: 
        	            	expected: 0
        	            	actual  : 1
        	Test:       	TestMetricsUsedWithServices
--- FAIL: TestMetricsUsedWithServices (0.00s)

Collector version

0.112.0

Environment information

Environment

OS: (e.g., "Ubuntu 20.04")
Compiler(if manually compiled): (e.g., "go 14.2")

OpenTelemetry Collector configuration

No response

Log output

No response

Additional context

No response

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions