From 7ac5a7cbee801c4c585c80b4a090a1caa827343c Mon Sep 17 00:00:00 2001 From: Arve Knudsen Date: Thu, 4 Apr 2024 17:27:25 +0200 Subject: [PATCH] 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 464395018f2f..f7782e14edf3 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 7be886ecd264..b171719c4baa 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 1a8d7109d080..1c0e274d9bb9 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,