Skip to content
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

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

Open
atoulme opened this issue Oct 29, 2024 · 3 comments · May be fixed by #37435
Labels
bug Something isn't working needs triage New item requiring triage processor/attributes Attributes processor

Comments

@atoulme
Copy link
Contributor

atoulme commented Oct 29, 2024

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

@atoulme atoulme added bug Something isn't working needs triage New item requiring triage labels Oct 29, 2024
@github-actions github-actions bot added the processor/attributes Attributes processor label Oct 29, 2024
Copy link
Contributor

Pinging code owners:

See Adding Labels via Comments if you do not have permissions to add labels yourself.

Copy link
Contributor

This issue has been inactive for 60 days. It will be closed in 60 days if there is no activity. To ping code owners by adding a component label, see Adding Labels via Comments, or if you are unsure of which component this issue relates to, please ping @open-telemetry/collector-contrib-triagers. If this issue is still relevant, please ping the code owners or leave a comment explaining why it is still relevant. Otherwise, please close it.

Pinging code owners:

See Adding Labels via Comments if you do not have permissions to add labels yourself.

@odubajDT
Copy link
Contributor

Hi, I would like to pick this issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs triage New item requiring triage processor/attributes Attributes processor
Projects
None yet
2 participants