-
Notifications
You must be signed in to change notification settings - Fork 214
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added fix in entity logic to fallback to workload name when unknown service is set by OTEL SDK #1554
Conversation
@@ -189,7 +189,7 @@ func (p *awsEntityProcessor) processMetrics(_ context.Context, md pmetric.Metric | |||
podInfo, ok := p.k8sscraper.(*k8sattributescraper.K8sAttributeScraper) | |||
// Perform fallback mechanism for service and environment name if they | |||
// are empty | |||
if entityServiceName == EMPTY && ok && podInfo != nil && podInfo.Workload != EMPTY { | |||
if (entityServiceName == EMPTY || strings.HasPrefix(entityServiceName, "unknown_service")) && ok && podInfo != nil && podInfo.Workload != EMPTY { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: wonder if we could use regex to match on ^unknown_service(?::.+)?$
to minimize edge cases?
EDIT: Nevermind, it uses HasPrefix
, which is fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: move "unknown_service" to a const
@@ -189,7 +189,7 @@ func (p *awsEntityProcessor) processMetrics(_ context.Context, md pmetric.Metric | |||
podInfo, ok := p.k8sscraper.(*k8sattributescraper.K8sAttributeScraper) | |||
// Perform fallback mechanism for service and environment name if they | |||
// are empty | |||
if entityServiceName == EMPTY && ok && podInfo != nil && podInfo.Workload != EMPTY { | |||
if (entityServiceName == EMPTY || strings.HasPrefix(entityServiceName, "unknown_service")) && ok && podInfo != nil && podInfo.Workload != EMPTY { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: move "unknown_service" to a const
}, | ||
}, | ||
{ | ||
name: "ResourceAttributeWithUnknownServiceNegativeCase", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there a test case where we are unable to retrieve the workload but the service name is "unknown_service" ?
…-cloudwatch-agent into otlp-unknown
Description of the issue
Describe the problem or feature in addition to a link to the issues.
If an application instrumented with an OTEL SDK doesn't specify the service.name as a resource attribute, it will return unknown_service:<process.executable.name> or unknown_service for its Service name: https://opentelemetry.io/docs/specs/semconv/attributes-registry/service/.
In the context of a service entity, this would populate the Service name to be an unknown service value.
com.amazonaws.cloudwatch.entity.internal.service.name: Str(unknown_service:java)
But for entity, we want the agent to fallback to workload when the service name is unknown.
Description of changes
How does this change address the problem?
Added logic in entity processor to check if the service name is prefixed with unknown_service, and fallback to workload.
License
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
Tests
Describe what tests you have done.
Unit tests
Manual tests
Removed resource attributes.
Changed OTEL_EXPORTER_OTLP_ENDPOINT to http://cloudwatch-agent.amazon-cloudwatch:4317.
k8s-attr
branch to replicate the issueBefore code change
After code change
Requirements
Before commit the code, please do the following steps.
make fmt
andmake fmt-sh
make lint