Skip to content

Commit

Permalink
Ignore service.name starting with service_unknown
Browse files Browse the repository at this point in the history
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
  • Loading branch information
aknuds1 committed Apr 4, 2024
1 parent d943bf8 commit 7ac5a7c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .chloggen/bugfix_target-info-required-attrs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions pkg/translator/prometheusremotewrite/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions pkg/translator/prometheusremotewrite/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 7ac5a7c

Please sign in to comment.