From 89c64af10e314c98a68fe2cded0f66898373cbad Mon Sep 17 00:00:00 2001 From: Arve Knudsen Date: Wed, 3 Apr 2024 17:56:36 +0200 Subject: [PATCH 1/8] prometheusremotewrite: Don't generate target_info unless job is defined Signed-off-by: Arve Knudsen --- .../bugfix_target-info-required-attrs.yaml | 27 +++++++++ .../exporter_test.go | 4 +- .../prometheusremotewrite/helper.go | 27 +++++++++ .../prometheusremotewrite/helper_test.go | 59 +++++++++++++++---- 4 files changed, 104 insertions(+), 13 deletions(-) create mode 100644 .chloggen/bugfix_target-info-required-attrs.yaml diff --git a/.chloggen/bugfix_target-info-required-attrs.yaml b/.chloggen/bugfix_target-info-required-attrs.yaml new file mode 100644 index 0000000000000..2b65a49869d09 --- /dev/null +++ b/.chloggen/bugfix_target-info-required-attrs.yaml @@ -0,0 +1,27 @@ +# Use this changelog template to create an entry for release notes. + +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: bug_fix + +# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) +component: prometheusremotewrite + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Change prometheusremotewrite.FromMetrics so that the target_info metric is only generated if the OTel resource attribute service.name is defined. + +# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. +issues: [32148] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: The resource attribute service.name is mandatory according to the OTel spec. + +# If your change doesn't affect end users or the exported elements of any package, +# you should instead start your pull request title with [chore] or use the "Skip Changelog" label. +# Optional: The change log or logs in which this entry should be included. +# e.g. '[user]' or '[user, api]' +# Include 'user' if the change is relevant to end users. +# Include 'api' if there is a change to a library API. +# Default: '[user]' +change_logs: [user] diff --git a/exporter/prometheusremotewriteexporter/exporter_test.go b/exporter/prometheusremotewriteexporter/exporter_test.go index 7adcae6f83e35..6021c012ed372 100644 --- a/exporter/prometheusremotewriteexporter/exporter_test.go +++ b/exporter/prometheusremotewriteexporter/exporter_test.go @@ -490,14 +490,14 @@ func Test_PushMetrics(t *testing.T) { metrics: invalidTypeBatch, httpResponseCode: http.StatusAccepted, reqTestFunc: checkFunc, - expectedTimeSeries: 1, // the resource target metric. + expectedTimeSeries: 0, expectedFailedTranslations: 1, }, { name: "intSum_case", metrics: intSumBatch, reqTestFunc: checkFunc, - expectedTimeSeries: 5, + expectedTimeSeries: 4, httpResponseCode: http.StatusAccepted, }, { diff --git a/pkg/translator/prometheusremotewrite/helper.go b/pkg/translator/prometheusremotewrite/helper.go index 98761617049b3..ae17fc70e8d88 100644 --- a/pkg/translator/prometheusremotewrite/helper.go +++ b/pkg/translator/prometheusremotewrite/helper.go @@ -552,6 +552,33 @@ func addResourceTargetInfo(resource pcommon.Resource, settings Settings, timesta name = settings.Namespace + "_" + name } labels := createAttributes(resource, attributes, settings.ExternalLabels, model.MetricNameLabel, name) + haveJob := false + haveInstance := false + for _, l := range labels { + if l.Name == model.JobLabel { + haveJob = true + } else if l.Name == model.InstanceLabel { + haveInstance = true + } + if haveJob && haveInstance { + break + } + } + + if !haveJob { + // The resource attribute service.name is mandatory according to OTel spec. + // If it's missing, don't generate target_info. + return + } + if !haveInstance { + // The resource attribute service.instance.id is optional, but let's just be explicit + // as ideally the target info should also be identified through the instance label. + labels = append(labels, prompb.Label{ + Name: model.InstanceLabel, + Value: "", + }) + } + sample := &prompb.Sample{ Value: float64(1), // convert ns to ms diff --git a/pkg/translator/prometheusremotewrite/helper_test.go b/pkg/translator/prometheusremotewrite/helper_test.go index e55841911df78..50bed3c1800b7 100644 --- a/pkg/translator/prometheusremotewrite/helper_test.go +++ b/pkg/translator/prometheusremotewrite/helper_test.go @@ -12,6 +12,7 @@ import ( "github.com/prometheus/prometheus/model/timestamp" "github.com/prometheus/prometheus/prompb" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "go.opentelemetry.io/collector/pdata/pcommon" "go.opentelemetry.io/collector/pdata/pmetric" conventions "go.opentelemetry.io/collector/semconv/v1.6.1" @@ -510,10 +511,18 @@ func TestAddResourceTargetInfo(t *testing.T) { conventions.AttributeServiceInstanceID: "service-instance-id", } resourceWithServiceAttrs := pcommon.NewResource() - assert.NoError(t, resourceWithServiceAttrs.Attributes().FromRaw(resourceAttrMap)) + require.NoError(t, resourceWithServiceAttrs.Attributes().FromRaw(resourceAttrMap)) resourceWithServiceAttrs.Attributes().PutStr("resource_attr", "resource-attr-val-1") resourceWithOnlyServiceAttrs := pcommon.NewResource() - assert.NoError(t, resourceWithOnlyServiceAttrs.Attributes().FromRaw(resourceAttrMap)) + require.NoError(t, resourceWithOnlyServiceAttrs.Attributes().FromRaw(resourceAttrMap)) + // service.name is the one mandatory resource attribute. + resourceWithOnlyServiceName := pcommon.NewResource() + resourceWithOnlyServiceName.Attributes().PutStr(conventions.AttributeServiceName, "service-name") + resourceWithOnlyServiceName.Attributes().PutStr("resource_attr", "resource-attr-val-1") + // service.instance.id is an identifying resource attribute, but not mandatory + resourceWithOnlyServiceID := pcommon.NewResource() + resourceWithOnlyServiceID.Attributes().PutStr(conventions.AttributeServiceInstanceID, "service-instance-id") + resourceWithOnlyServiceID.Attributes().PutStr("resource_attr", "resource-attr-val-1") for _, tc := range []struct { desc string resource pcommon.Resource @@ -528,21 +537,41 @@ func TestAddResourceTargetInfo(t *testing.T) { }, { desc: "disable target info metric", - resource: testdata.GenerateMetricsNoLibraries().ResourceMetrics().At(0).Resource(), + resource: resourceWithOnlyServiceName, settings: Settings{DisableTargetInfo: true}, expected: map[string]*prompb.TimeSeries{}, }, { - desc: "with resource", + desc: "with resource missing both service.name and service.instance.id resource attributes", resource: testdata.GenerateMetricsNoLibraries().ResourceMetrics().At(0).Resource(), timestamp: testdata.TestMetricStartTimestamp, + expected: map[string]*prompb.TimeSeries{}, + }, + { + desc: "with resource including service.instance.id, but missing service.name resource attribute", + resource: resourceWithOnlyServiceID, + timestamp: testdata.TestMetricStartTimestamp, + expected: map[string]*prompb.TimeSeries{}, + }, + { + desc: "with resource including service.name, and missing service.instance.id resource attribute", + resource: resourceWithOnlyServiceName, + timestamp: testdata.TestMetricStartTimestamp, expected: map[string]*prompb.TimeSeries{ - "info-__name__-target_info-resource_attr-resource-attr-val-1": { + "info-__name__-target_info-instance--job-service-name-resource_attr-resource-attr-val-1": { Labels: []prompb.Label{ { - Name: "__name__", + Name: model.MetricNameLabel, Value: "target_info", }, + { + Name: model.InstanceLabel, + Value: "", + }, + { + Name: model.JobLabel, + Value: "service-name", + }, { Name: "resource_attr", Value: "resource-attr-val-1", @@ -558,17 +587,25 @@ func TestAddResourceTargetInfo(t *testing.T) { }, }, { - desc: "with resource, with namespace", - resource: testdata.GenerateMetricsNoLibraries().ResourceMetrics().At(0).Resource(), + desc: "with valid resource, with namespace", + resource: resourceWithOnlyServiceName, timestamp: testdata.TestMetricStartTimestamp, settings: Settings{Namespace: "foo"}, expected: map[string]*prompb.TimeSeries{ - "info-__name__-foo_target_info-resource_attr-resource-attr-val-1": { + "info-__name__-foo_target_info-instance--job-service-name-resource_attr-resource-attr-val-1": { Labels: []prompb.Label{ { - Name: "__name__", + Name: model.MetricNameLabel, Value: "foo_target_info", }, + { + Name: model.InstanceLabel, + Value: "", + }, + { + Name: model.JobLabel, + Value: "service-name", + }, { Name: "resource_attr", Value: "resource-attr-val-1", @@ -591,7 +628,7 @@ func TestAddResourceTargetInfo(t *testing.T) { "info-__name__-target_info-instance-service-instance-id-job-service-namespace/service-name-resource_attr-resource-attr-val-1": { Labels: []prompb.Label{ { - Name: "__name__", + Name: model.MetricNameLabel, Value: "target_info", }, { From d943bf83b7acd77413cc5c9f842d5e2932fc10b6 Mon Sep 17 00:00:00 2001 From: Arve Knudsen Date: Thu, 4 Apr 2024 17:04:35 +0200 Subject: [PATCH 2/8] Require for either job or instance label to be defined Signed-off-by: Arve Knudsen --- .../bugfix_target-info-required-attrs.yaml | 4 +- .../prometheusremotewrite/helper.go | 13 +----- .../prometheusremotewrite/helper_test.go | 43 +++++++++++++------ 3 files changed, 33 insertions(+), 27 deletions(-) diff --git a/.chloggen/bugfix_target-info-required-attrs.yaml b/.chloggen/bugfix_target-info-required-attrs.yaml index 2b65a49869d09..464395018f2fe 100644 --- a/.chloggen/bugfix_target-info-required-attrs.yaml +++ b/.chloggen/bugfix_target-info-required-attrs.yaml @@ -7,7 +7,7 @@ change_type: bug_fix component: prometheusremotewrite # A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). -note: Change prometheusremotewrite.FromMetrics so that the target_info metric is only generated if the OTel resource attribute service.name is defined. +note: Change prometheusremotewrite.FromMetrics so that the target_info metric is only generated if either of the OTel resource attributes service.name and service.instance.id is defined. # Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. issues: [32148] @@ -15,7 +15,7 @@ issues: [32148] # (Optional) One or more lines of additional information to render under the primary note. # These lines will be padded with 2 spaces and then inserted directly into the document. # Use pipe (|) for multiline entries. -subtext: The resource attribute service.name is mandatory according to the OTel spec. +subtext: # If your change doesn't affect end users or the exported elements of any package, # you should instead start your pull request title with [chore] or use the "Skip Changelog" label. diff --git a/pkg/translator/prometheusremotewrite/helper.go b/pkg/translator/prometheusremotewrite/helper.go index ae17fc70e8d88..7be886ecd2641 100644 --- a/pkg/translator/prometheusremotewrite/helper.go +++ b/pkg/translator/prometheusremotewrite/helper.go @@ -565,19 +565,10 @@ func addResourceTargetInfo(resource pcommon.Resource, settings Settings, timesta } } - if !haveJob { - // The resource attribute service.name is mandatory according to OTel spec. - // If it's missing, don't generate target_info. + if !haveJob && !haveInstance { + // We need at least one identifying label to generate target_info. return } - if !haveInstance { - // The resource attribute service.instance.id is optional, but let's just be explicit - // as ideally the target info should also be identified through the instance label. - labels = append(labels, prompb.Label{ - Name: model.InstanceLabel, - Value: "", - }) - } sample := &prompb.Sample{ Value: float64(1), diff --git a/pkg/translator/prometheusremotewrite/helper_test.go b/pkg/translator/prometheusremotewrite/helper_test.go index 50bed3c1800b7..1a8d7109d080f 100644 --- a/pkg/translator/prometheusremotewrite/helper_test.go +++ b/pkg/translator/prometheusremotewrite/helper_test.go @@ -515,11 +515,11 @@ func TestAddResourceTargetInfo(t *testing.T) { resourceWithServiceAttrs.Attributes().PutStr("resource_attr", "resource-attr-val-1") resourceWithOnlyServiceAttrs := pcommon.NewResource() require.NoError(t, resourceWithOnlyServiceAttrs.Attributes().FromRaw(resourceAttrMap)) - // service.name is the one mandatory resource attribute. + // service.name is an identifying resource attribute. resourceWithOnlyServiceName := pcommon.NewResource() resourceWithOnlyServiceName.Attributes().PutStr(conventions.AttributeServiceName, "service-name") resourceWithOnlyServiceName.Attributes().PutStr("resource_attr", "resource-attr-val-1") - // service.instance.id is an identifying resource attribute, but not mandatory + // service.instance.id is an identifying resource attribute. resourceWithOnlyServiceID := pcommon.NewResource() resourceWithOnlyServiceID.Attributes().PutStr(conventions.AttributeServiceInstanceID, "service-instance-id") resourceWithOnlyServiceID.Attributes().PutStr("resource_attr", "resource-attr-val-1") @@ -548,26 +548,45 @@ func TestAddResourceTargetInfo(t *testing.T) { expected: map[string]*prompb.TimeSeries{}, }, { - desc: "with resource including service.instance.id, but missing service.name resource attribute", + desc: "with resource including service.instance.id, and missing service.name resource attribute", resource: resourceWithOnlyServiceID, timestamp: testdata.TestMetricStartTimestamp, - expected: map[string]*prompb.TimeSeries{}, + expected: map[string]*prompb.TimeSeries{ + "info-__name__-target_info-instance-service-instance-id-resource_attr-resource-attr-val-1": { + Labels: []prompb.Label{ + { + Name: model.MetricNameLabel, + Value: "target_info", + }, + { + Name: model.InstanceLabel, + Value: "service-instance-id", + }, + { + Name: "resource_attr", + Value: "resource-attr-val-1", + }, + }, + Samples: []prompb.Sample{ + { + Value: 1, + Timestamp: 1581452772000, + }, + }, + }, + }, }, { desc: "with resource including service.name, and missing service.instance.id resource attribute", resource: resourceWithOnlyServiceName, timestamp: testdata.TestMetricStartTimestamp, expected: map[string]*prompb.TimeSeries{ - "info-__name__-target_info-instance--job-service-name-resource_attr-resource-attr-val-1": { + "info-__name__-target_info-job-service-name-resource_attr-resource-attr-val-1": { Labels: []prompb.Label{ { Name: model.MetricNameLabel, Value: "target_info", }, - { - Name: model.InstanceLabel, - Value: "", - }, { Name: model.JobLabel, Value: "service-name", @@ -592,16 +611,12 @@ func TestAddResourceTargetInfo(t *testing.T) { timestamp: testdata.TestMetricStartTimestamp, settings: Settings{Namespace: "foo"}, expected: map[string]*prompb.TimeSeries{ - "info-__name__-foo_target_info-instance--job-service-name-resource_attr-resource-attr-val-1": { + "info-__name__-foo_target_info-job-service-name-resource_attr-resource-attr-val-1": { Labels: []prompb.Label{ { Name: model.MetricNameLabel, Value: "foo_target_info", }, - { - Name: model.InstanceLabel, - Value: "", - }, { Name: model.JobLabel, Value: "service-name", From 7ac5a7cbee801c4c585c80b4a090a1caa827343c Mon Sep 17 00:00:00 2001 From: Arve Knudsen Date: Thu, 4 Apr 2024 17:27:25 +0200 Subject: [PATCH 3/8] Ignore service.name starting with service_unknown Signed-off-by: Arve Knudsen --- .chloggen/bugfix_target-info-required-attrs.yaml | 2 +- pkg/translator/prometheusremotewrite/helper.go | 4 ++++ pkg/translator/prometheusremotewrite/helper_test.go | 10 ++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/.chloggen/bugfix_target-info-required-attrs.yaml b/.chloggen/bugfix_target-info-required-attrs.yaml index 464395018f2fe..f7782e14edf37 100644 --- a/.chloggen/bugfix_target-info-required-attrs.yaml +++ b/.chloggen/bugfix_target-info-required-attrs.yaml @@ -15,7 +15,7 @@ issues: [32148] # (Optional) One or more lines of additional information to render under the primary note. # These lines will be padded with 2 spaces and then inserted directly into the document. # Use pipe (|) for multiline entries. -subtext: +subtext: 'If the service.name resource attribute starts with "unknown_service", it is considered undefined' # If your change doesn't affect end users or the exported elements of any package, # you should instead start your pull request title with [chore] or use the "Skip Changelog" label. diff --git a/pkg/translator/prometheusremotewrite/helper.go b/pkg/translator/prometheusremotewrite/helper.go index 7be886ecd2641..b171719c4baa8 100644 --- a/pkg/translator/prometheusremotewrite/helper.go +++ b/pkg/translator/prometheusremotewrite/helper.go @@ -151,6 +151,10 @@ func timeSeriesSignature(datatype string, labels []prompb.Label) string { // logged. Resulting label names are sanitized. func createAttributes(resource pcommon.Resource, attributes pcommon.Map, externalLabels map[string]string, extras ...string) []prompb.Label { serviceName, haveServiceName := resource.Attributes().Get(conventions.AttributeServiceName) + // SDKs operate with a default service name prefixed with "unknown_service", we should treat such values as undefined. + if haveServiceName && strings.HasPrefix(serviceName.AsString(), "unknown_service") { + haveServiceName = false + } instance, haveInstanceID := resource.Attributes().Get(conventions.AttributeServiceInstanceID) // Calculate the maximum possible number of labels we could return so we can preallocate l diff --git a/pkg/translator/prometheusremotewrite/helper_test.go b/pkg/translator/prometheusremotewrite/helper_test.go index 1a8d7109d080f..1c0e274d9bb9c 100644 --- a/pkg/translator/prometheusremotewrite/helper_test.go +++ b/pkg/translator/prometheusremotewrite/helper_test.go @@ -523,6 +523,10 @@ func TestAddResourceTargetInfo(t *testing.T) { resourceWithOnlyServiceID := pcommon.NewResource() resourceWithOnlyServiceID.Attributes().PutStr(conventions.AttributeServiceInstanceID, "service-instance-id") resourceWithOnlyServiceID.Attributes().PutStr("resource_attr", "resource-attr-val-1") + // SDKs operate with a default service name prefixed with "unknown_service", we should treat such values as undefined. + resourceWithOnlyUnknownServiceName := pcommon.NewResource() + resourceWithOnlyUnknownServiceName.Attributes().PutStr(conventions.AttributeServiceName, "unknown_service: java") + resourceWithOnlyUnknownServiceName.Attributes().PutStr("resource_attr", "resource-attr-val-1") for _, tc := range []struct { desc string resource pcommon.Resource @@ -605,6 +609,12 @@ func TestAddResourceTargetInfo(t *testing.T) { }, }, }, + { + desc: "with resource including unknown_service: java for service.name, and missing service.instance.id resource attribute", + resource: resourceWithOnlyUnknownServiceName, + timestamp: testdata.TestMetricStartTimestamp, + expected: map[string]*prompb.TimeSeries{}, + }, { desc: "with valid resource, with namespace", resource: resourceWithOnlyServiceName, From 981c9ec967a805fd9bdeed9d87701404bec5a8c9 Mon Sep 17 00:00:00 2001 From: Arve Knudsen Date: Thu, 11 Apr 2024 14:07:10 +0200 Subject: [PATCH 4/8] Tweak changelog note Signed-off-by: Arve Knudsen --- .chloggen/bugfix_target-info-required-attrs.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.chloggen/bugfix_target-info-required-attrs.yaml b/.chloggen/bugfix_target-info-required-attrs.yaml index f7782e14edf37..4664e02de62e1 100644 --- a/.chloggen/bugfix_target-info-required-attrs.yaml +++ b/.chloggen/bugfix_target-info-required-attrs.yaml @@ -7,7 +7,7 @@ change_type: bug_fix component: prometheusremotewrite # A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). -note: Change prometheusremotewrite.FromMetrics so that the target_info metric is only generated if either of the OTel resource attributes service.name and service.instance.id is defined. +note: Change prometheusremotewrite.FromMetrics so that the target_info metric is only generated if at least one identifying OTel resource attribute (service.name and/or service.instance.id) is defined. # Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. issues: [32148] From bc8ff90454ba8714e76917b31b2037fecf8fd898 Mon Sep 17 00:00:00 2001 From: Arve Knudsen Date: Thu, 25 Apr 2024 11:26:12 +0200 Subject: [PATCH 5/8] Don't ignore resources with unknown_service name prefix Signed-off-by: Arve Knudsen --- pkg/translator/prometheusremotewrite/helper.go | 5 ----- pkg/translator/prometheusremotewrite/helper_test.go | 5 ----- 2 files changed, 10 deletions(-) diff --git a/pkg/translator/prometheusremotewrite/helper.go b/pkg/translator/prometheusremotewrite/helper.go index 33b993fb69e66..d2ffc08a3717c 100644 --- a/pkg/translator/prometheusremotewrite/helper.go +++ b/pkg/translator/prometheusremotewrite/helper.go @@ -11,7 +11,6 @@ import ( "slices" "sort" "strconv" - "strings" "time" "unicode/utf8" @@ -106,10 +105,6 @@ func createAttributes(resource pcommon.Resource, attributes pcommon.Map, externa ignoreAttrs []string, logOnOverwrite bool, extras ...string) []prompb.Label { resourceAttrs := resource.Attributes() serviceName, haveServiceName := resourceAttrs.Get(conventions.AttributeServiceName) - // SDKs operate with a default service name prefixed with "unknown_service", we should treat such values as undefined. - if haveServiceName && strings.HasPrefix(serviceName.AsString(), "unknown_service") { - haveServiceName = false - } instance, haveInstanceID := resourceAttrs.Get(conventions.AttributeServiceInstanceID) // Calculate the maximum possible number of labels we could return so we can preallocate l diff --git a/pkg/translator/prometheusremotewrite/helper_test.go b/pkg/translator/prometheusremotewrite/helper_test.go index d4d1a1b896c82..da076064e2bf2 100644 --- a/pkg/translator/prometheusremotewrite/helper_test.go +++ b/pkg/translator/prometheusremotewrite/helper_test.go @@ -588,11 +588,6 @@ func TestAddResourceTargetInfo(t *testing.T) { {Name: "resource_attr", Value: "resource-attr-val-1"}, }, }, - { - desc: "with resource including unknown_service: java for service.name, and missing service.instance.id resource attribute", - resource: resourceWithOnlyUnknownServiceName, - timestamp: testdata.TestMetricStartTimestamp, - }, { desc: "with valid resource, with namespace", resource: resourceWithOnlyServiceName, From 65bbd87990f9b06ede0dfe2097a9a21fc974e71f Mon Sep 17 00:00:00 2001 From: Arve Knudsen Date: Thu, 25 Apr 2024 11:30:04 +0200 Subject: [PATCH 6/8] Update pkg/translator/prometheusremotewrite/helper.go Co-authored-by: Anthony Mirabella --- pkg/translator/prometheusremotewrite/helper.go | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/pkg/translator/prometheusremotewrite/helper.go b/pkg/translator/prometheusremotewrite/helper.go index d2ffc08a3717c..fa71891184eae 100644 --- a/pkg/translator/prometheusremotewrite/helper.go +++ b/pkg/translator/prometheusremotewrite/helper.go @@ -540,20 +540,15 @@ func addResourceTargetInfo(resource pcommon.Resource, settings Settings, timesta } labels := createAttributes(resource, attributes, settings.ExternalLabels, identifyingAttrs, false, model.MetricNameLabel, name) - haveJob := false - haveInstance := false + haveIdentifier := false for _, l := range labels { - if l.Name == model.JobLabel { - haveJob = true - } else if l.Name == model.InstanceLabel { - haveInstance = true - } - if haveJob && haveInstance { + if l.Name == model.JobLabel || l.Name == model.InstanceLabel { + haveIdentifier = true break } } - if !haveJob && !haveInstance { + if !haveIdentifier { // We need at least one identifying label to generate target_info. return } From eb4618a986e6576a119a4ff07effe6042fa663e6 Mon Sep 17 00:00:00 2001 From: Arve Knudsen Date: Thu, 25 Apr 2024 11:32:26 +0200 Subject: [PATCH 7/8] Fix changelog Signed-off-by: Arve Knudsen --- .chloggen/bugfix_target-info-required-attrs.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.chloggen/bugfix_target-info-required-attrs.yaml b/.chloggen/bugfix_target-info-required-attrs.yaml index 4664e02de62e1..0b2e207e75edf 100644 --- a/.chloggen/bugfix_target-info-required-attrs.yaml +++ b/.chloggen/bugfix_target-info-required-attrs.yaml @@ -15,7 +15,7 @@ issues: [32148] # (Optional) One or more lines of additional information to render under the primary note. # These lines will be padded with 2 spaces and then inserted directly into the document. # Use pipe (|) for multiline entries. -subtext: 'If the service.name resource attribute starts with "unknown_service", it is considered undefined' +subtext: # If your change doesn't affect end users or the exported elements of any package, # you should instead start your pull request title with [chore] or use the "Skip Changelog" label. From 04fafee8cd34cbc20d0bccfb4b2267e2d0d3bf11 Mon Sep 17 00:00:00 2001 From: Arve Knudsen Date: Thu, 25 Apr 2024 11:37:00 +0200 Subject: [PATCH 8/8] Drop stale test code Signed-off-by: Arve Knudsen --- pkg/translator/prometheusremotewrite/helper_test.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/pkg/translator/prometheusremotewrite/helper_test.go b/pkg/translator/prometheusremotewrite/helper_test.go index da076064e2bf2..cc2ce173ce26b 100644 --- a/pkg/translator/prometheusremotewrite/helper_test.go +++ b/pkg/translator/prometheusremotewrite/helper_test.go @@ -543,10 +543,6 @@ func TestAddResourceTargetInfo(t *testing.T) { resourceWithOnlyServiceID := pcommon.NewResource() resourceWithOnlyServiceID.Attributes().PutStr(conventions.AttributeServiceInstanceID, "service-instance-id") resourceWithOnlyServiceID.Attributes().PutStr("resource_attr", "resource-attr-val-1") - // SDKs operate with a default service name prefixed with "unknown_service", we should treat such values as undefined. - resourceWithOnlyUnknownServiceName := pcommon.NewResource() - resourceWithOnlyUnknownServiceName.Attributes().PutStr(conventions.AttributeServiceName, "unknown_service: java") - resourceWithOnlyUnknownServiceName.Attributes().PutStr("resource_attr", "resource-attr-val-1") for _, tc := range []struct { desc string resource pcommon.Resource