diff --git a/pkg/distributor/otel_test.go b/pkg/distributor/otel_test.go index deffa2d6ae..5066a345a6 100644 --- a/pkg/distributor/otel_test.go +++ b/pkg/distributor/otel_test.go @@ -26,7 +26,6 @@ import ( "github.com/prometheus/common/model" "github.com/prometheus/prometheus/model/labels" "github.com/prometheus/prometheus/prompb" - prometheustranslator "github.com/prometheus/prometheus/storage/remote/otlptranslator/prometheus" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "go.opentelemetry.io/collector/pdata/pcommon" @@ -50,6 +49,7 @@ func TestOTelMetricsToTimeSeries(t *testing.T) { }, []string{tenantID, "group"}) resourceAttrs := map[string]string{ "service.name": "service name", + "service.namespace": "service namespace", "service.instance.id": "service ID", "existent-attr": "resource value", // This one is for testing conflict with metric attribute. @@ -59,32 +59,6 @@ func TestOTelMetricsToTimeSeries(t *testing.T) { // This one is for testing conflict with auto-generated instance attribute. "instance": "resource value", } - expTargetInfoLabels := []mimirpb.LabelAdapter{ - { - Name: labels.MetricName, - Value: "target_info", - }, - } - for k, v := range resourceAttrs { - switch k { - case "service.name": - k = "job" - case "service.instance.id": - k = "instance" - case "job", "instance": - // Ignore, as these labels are generated from service.name and service.instance.id - continue - default: - k = prometheustranslator.NormalizeLabel(k, false) - } - expTargetInfoLabels = append(expTargetInfoLabels, mimirpb.LabelAdapter{ - Name: k, - Value: v, - }) - } - slices.SortStableFunc(expTargetInfoLabels, func(a, b mimirpb.LabelAdapter) int { - return strings.Compare(a.Name, b.Name) - }) md := pmetric.NewMetrics() { @@ -105,6 +79,7 @@ func TestOTelMetricsToTimeSeries(t *testing.T) { name string promoteResourceAttributes []string expectedLabels []mimirpb.LabelAdapter + expectedInfoLabels []mimirpb.LabelAdapter }{ { name: "Successful conversion without resource attribute promotion", @@ -120,13 +95,35 @@ func TestOTelMetricsToTimeSeries(t *testing.T) { }, { Name: "job", - Value: "service name", + Value: "service namespace/service name", }, { Name: "metric_attr", Value: "metric value", }, }, + expectedInfoLabels: []mimirpb.LabelAdapter{ + { + Name: "__name__", + Value: "target_info", + }, + { + Name: "existent_attr", + Value: "resource value", + }, + { + Name: "metric_attr", + Value: "resource value", + }, + { + Name: "job", + Value: "service namespace/service name", + }, + { + Name: "instance", + Value: "service ID", + }, + }, }, { name: "Successful conversion with resource attribute promotion", @@ -142,7 +139,7 @@ func TestOTelMetricsToTimeSeries(t *testing.T) { }, { Name: "job", - Value: "service name", + Value: "service namespace/service name", }, { Name: "metric_attr", @@ -153,6 +150,28 @@ func TestOTelMetricsToTimeSeries(t *testing.T) { Value: "resource value", }, }, + expectedInfoLabels: []mimirpb.LabelAdapter{ + { + Name: "__name__", + Value: "target_info", + }, + { + Name: "existent_attr", + Value: "resource value", + }, + { + Name: "metric_attr", + Value: "resource value", + }, + { + Name: "job", + Value: "service namespace/service name", + }, + { + Name: "instance", + Value: "service ID", + }, + }, }, { name: "Successful conversion with resource attribute promotion, conflicting resource attributes are ignored", @@ -168,7 +187,7 @@ func TestOTelMetricsToTimeSeries(t *testing.T) { }, { Name: "job", - Value: "service name", + Value: "service namespace/service name", }, { Name: "existent_attr", @@ -179,6 +198,28 @@ func TestOTelMetricsToTimeSeries(t *testing.T) { Value: "metric value", }, }, + expectedInfoLabels: []mimirpb.LabelAdapter{ + { + Name: "__name__", + Value: "target_info", + }, + { + Name: "existent_attr", + Value: "resource value", + }, + { + Name: "instance", + Value: "service ID", + }, + { + Name: "job", + Value: "service namespace/service name", + }, + { + Name: "metric_attr", + Value: "resource value", + }, + }, }, } for _, tc := range testCases { @@ -205,7 +246,7 @@ func TestOTelMetricsToTimeSeries(t *testing.T) { } assert.ElementsMatch(t, ts.Labels, tc.expectedLabels) - assert.ElementsMatch(t, targetInfo.Labels, expTargetInfoLabels) + assert.ElementsMatch(t, targetInfo.Labels, tc.expectedInfoLabels) }) } }