Skip to content

Commit 7ac5a7c

Browse files
committed
Ignore service.name starting with service_unknown
Signed-off-by: Arve Knudsen <[email protected]>
1 parent d943bf8 commit 7ac5a7c

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

.chloggen/bugfix_target-info-required-attrs.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ issues: [32148]
1515
# (Optional) One or more lines of additional information to render under the primary note.
1616
# These lines will be padded with 2 spaces and then inserted directly into the document.
1717
# Use pipe (|) for multiline entries.
18-
subtext:
18+
subtext: 'If the service.name resource attribute starts with "unknown_service", it is considered undefined'
1919

2020
# If your change doesn't affect end users or the exported elements of any package,
2121
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.

pkg/translator/prometheusremotewrite/helper.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,10 @@ func timeSeriesSignature(datatype string, labels []prompb.Label) string {
151151
// logged. Resulting label names are sanitized.
152152
func createAttributes(resource pcommon.Resource, attributes pcommon.Map, externalLabels map[string]string, extras ...string) []prompb.Label {
153153
serviceName, haveServiceName := resource.Attributes().Get(conventions.AttributeServiceName)
154+
// SDKs operate with a default service name prefixed with "unknown_service", we should treat such values as undefined.
155+
if haveServiceName && strings.HasPrefix(serviceName.AsString(), "unknown_service") {
156+
haveServiceName = false
157+
}
154158
instance, haveInstanceID := resource.Attributes().Get(conventions.AttributeServiceInstanceID)
155159

156160
// Calculate the maximum possible number of labels we could return so we can preallocate l

pkg/translator/prometheusremotewrite/helper_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,10 @@ func TestAddResourceTargetInfo(t *testing.T) {
523523
resourceWithOnlyServiceID := pcommon.NewResource()
524524
resourceWithOnlyServiceID.Attributes().PutStr(conventions.AttributeServiceInstanceID, "service-instance-id")
525525
resourceWithOnlyServiceID.Attributes().PutStr("resource_attr", "resource-attr-val-1")
526+
// SDKs operate with a default service name prefixed with "unknown_service", we should treat such values as undefined.
527+
resourceWithOnlyUnknownServiceName := pcommon.NewResource()
528+
resourceWithOnlyUnknownServiceName.Attributes().PutStr(conventions.AttributeServiceName, "unknown_service: java")
529+
resourceWithOnlyUnknownServiceName.Attributes().PutStr("resource_attr", "resource-attr-val-1")
526530
for _, tc := range []struct {
527531
desc string
528532
resource pcommon.Resource
@@ -605,6 +609,12 @@ func TestAddResourceTargetInfo(t *testing.T) {
605609
},
606610
},
607611
},
612+
{
613+
desc: "with resource including unknown_service: java for service.name, and missing service.instance.id resource attribute",
614+
resource: resourceWithOnlyUnknownServiceName,
615+
timestamp: testdata.TestMetricStartTimestamp,
616+
expected: map[string]*prompb.TimeSeries{},
617+
},
608618
{
609619
desc: "with valid resource, with namespace",
610620
resource: resourceWithOnlyServiceName,

0 commit comments

Comments
 (0)