Skip to content

Support entity for OTLP custom metrics #1529

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

Merged
merged 19 commits into from
Apr 10, 2025
Merged

Conversation

musa-asad
Copy link
Contributor

@musa-asad musa-asad commented Feb 5, 2025

Description of the issue

To support the Explore related feature in CloudWatch, the CloudWatch Agent sends an "Entity", which includes relevant metadata to correlate metrics or logs between resources (e.g., an EKS cluster) and services (e.g., a Java application). When the CloudWatch Agent runs in a Kubernetes cluster, we need to collect the namespace, workload name, and node name to populate the "Entity".

However, we currently only get Kubernetes metadata when Application Signals is enabled. For OTLP custom metrics, if Application Signals isn't configured, then we don't have a way to fetch Kubernetes metadata. To achieve this, we must migrate the logic the Application Signals Processor uses to get Kuberbetes metadata to a global extension, which can be used by other pipelines.

Description of changes

  • Improve cluster detection for components during translation.
  • Add fix in entity logic to fallback to workload name when unknown service is set by OTEL SDK.
  • Set the service name source to Instrumentation in entity when customer sets the service name OTEL resource attribute.
  • Add Kubernetes Metadata Extension to Translation for the OTLP Pipeline (translator/translate/otel)
    • Update sample yaml files to include new extension.
    • Create extension/k8smetadata/translator.go to reference the extension in translation.
    • Add translators.Extensions.Set(k8smetadata.NewTranslator()) to pipeline/host/translator.go for OTLP pipeline in Kubernetes contexts.
    • Enable entity in EMF logs for OTLP.
  • Update service/defaultcomponents/components.go to include "k8smetadata".
  • Get podIp from connection context in entity processor to extract the pod metadata in map.
  • Add Instance ID entity attribute only if the application node is same as agent node.
  • Update Application Signals Processor to use extension if available.
  • Add unit tests for new functionality.

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

Integration Tests

Workflow Status
View Workflow Run #14350034749

Application Signals E2E Tests

Workflow Status
View Workflow Run #14350034748

Manual Testing

Agent Logs

│ 2025-04-09T06:04:39Z D! {"caller":"k8smetadata/extension.go:106","msg":"GetPodMetadataFromPodIP: found metadata","kind":"extension","name":"k8smetadata","ip":"XX │
│ X.XX.XX.XX","workload":"sample-app","namespace":"default","node":"ip-XXX-XX-XX-XXX.us-west-2.compute.internal"}                                                   │
│ 2025-04-09T06:04:42Z D! {"caller":"awsemfexporter@v0.115.0/emf_exporter.go:105","msg":"Start processing resource metrics","kind":"exporter","data_type":"metrics" │
│ ,"name":"awsemf","labels":{"com.amazonaws.cloudwatch.entity.internal.aws.account.id":"506463145083","com.amazonaws.cloudwatch.entity.internal.deployment.environm │
│ ent":"eks:cwagent-otlp-beta-testing/default","com.amazonaws.cloudwatch.entity.internal.instance.id":"i-03ad05b8dc69166f1","com.amazonaws.cloudwatch.entit │
│ y.internal.k8s.cluster.name":"cwagent-otlp-beta-testing","com.amazonaws.cloudwatch.entity.internal.k8s.namespace.name":"default","com.amazonaws.cloudwatc │
│ h.entity.internal.k8s.node.name":"ip-XXX-XX-XX-XXX.us-west-2.compute.internal","com.amazonaws.cloudwatch.entity.internal.k8s.workload.name":"sample-app","com.ama │
│ zonaws.cloudwatch.entity.internal.platform.type":"AWS::EKS","com.amazonaws.cloudwatch.entity.internal.service.name":"sample-app","com.amazonaws.cloudwatch.entity │
│ .internal.service.name.source":"K8sWorkload","com.amazonaws.cloudwatch.entity.internal.type":"Service","host.arch":"amd64","host.name":"sample-app-55dc5df99b-rwg │
│ bw","os.description":"Linux 6.1.131-143.221.amzn2023.x86_64","os.type":"linux","process.command_line":"/usr/lib/jvm/java-17-openjdk-amd64:bin:java -javaagent:/aw │
│ s-observability/classpath/aws-opentelemetry-agent-1.17.0.jar","process.executable.path":"/usr/lib/jvm/java-17-openjdk-amd64:bin:java","process.pid":"","process.r │
│ untime.description":"Debian OpenJDK 64-Bit Server VM 17.0.4+8-Debian-1deb11u1","process.runtime.name":"OpenJDK Runtime Environment","process.runtime.version":"17 │
│ .0.4+8-Debian-1deb11u1","service.name":"unknown_service:java","telemetry.auto.version":"1.17.0-aws","telemetry.sdk.language":"java","telemetry.sdk.name":"opentel │
│ emetry","telemetry.sdk.version":"1.17.0"}}
│ 2025-04-09T06:05:59Z D! {"caller":"k8sclient/endpointslicewatcher.go:218","msg":"Received EndpointSlice Update","kind":"extension","name":"k8smetadata","oldSlice │
│ UID":"1f78b8db-8aca-43d5-b2da-df751cd686c8","newSliceUID":"1f78b8db-8aca-43d5-b2da-df751cd686c8","name":"sample-app-g7l4h","namespace":"default"}                 │
│ 2025-04-09T06:05:59Z D! {"caller":"k8sclient/endpointslicewatcher.go:276","msg":"Finished handling EndpointSlice Update","kind":"extension","name":"k8smetadata", │
│ "sliceUID":"1f78b8db-8aca-43d5-b2da-df751cd686c8"}                                                                                                                │
│ 2025-04-09T06:06:00Z D! {"caller":"k8sclient/endpointslicewatcher.go:118","msg":"Processing endpoint","kind":"extension","name":"k8smetadata","podName":"sample-a │
│ pp-55dc5df99b-bmg4n","namespace":"default","nodeName":"ip-XXX-XX-XX-XXX.us-west-2.compute.internal"}

PMD

{"Entities":[{"__type":"com.amazonaws.observability#Entity","KeyAttributes":{"Environment":"eks:cwagent-otlp-beta-testing/default","Type":"Service","Name":"sample-app"}},{"__type":"com.amazonaws.observability#Entity","Attributes":{"AWS.ServiceNameSource":"K8sWorkload"},"KeyAttributes":{"Environment":"eks:cwagent-otlp-beta-testing/default","Type":"Service","Name":"sample-app"}}]}

EMF

{ "AWS.ServiceNameSource": "K8sWorkload", "CloudWatchMetrics": [ { "Namespace": "CWAgent", "Dimensions": [ ["endpoint", "telemetry.sdk.language", "telemetry.sdk.version", "telemetry.sdk.name", "service.name" ] ], "Metrics": [ {"Name": "request_count", "Unit": "", "StorageResolution": 60 } ] } ], "EC2.InstanceId": "i-05240b6269dfa8f69","EKS.Cluster": "cwagent-otlp-beta-testing", "Environment": "eks:cwagent-otlp-beta-testing/default","K8s.Namespace": "default", "K8s.Node": "ip-XXX-XX-XX-XXX.us-west-2.compute.internal", "K8s.Workload": "otlp-http-metrics-app", "PlatformType": "AWS::EKS", "Service": "otlp-http-metrics-app", "Timestamp": "1744169779952","Version": "0", "endpoint": "/simulate", "service.name": "unknown_service", "telemetry.sdk.language": "python","telemetry.sdk.name": "opentelemetry", "telemetry.sdk.version": "1.18.0", "request_count": 14 }

Requirements

Before commit the code, please do the following steps.

  1. Run make fmt and make fmt-sh
  2. Run make lint

@musa-asad musa-asad changed the title Support entity for otlp custom metrics Add k8sattributesprocessor for custom metrics Feb 5, 2025
@musa-asad musa-asad force-pushed the feature-custom-metrics-entity branch 2 times, most recently from 7f0a8f8 to 5e1b3aa Compare February 5, 2025 08:18
@musa-asad musa-asad changed the title Add k8sattributesprocessor for custom metrics Support entity for custom metrics Feb 6, 2025
Copy link
Contributor

This PR was marked stale due to lack of activity.

@github-actions github-actions bot added the Stale label Feb 19, 2025
Copy link
Contributor

github-actions bot commented Mar 1, 2025

This PR was marked stale due to lack of activity.

@github-actions github-actions bot added the Stale label Mar 1, 2025
…r sets the service name OTEL resource attribute (#1565)
@github-actions github-actions bot removed the Stale label Mar 4, 2025
Copy link
Contributor

This PR was marked stale due to lack of activity.

@github-actions github-actions bot added the Stale label Mar 14, 2025
@github-actions github-actions bot removed the Stale label Mar 18, 2025
@musa-asad musa-asad self-assigned this Mar 18, 2025
@musa-asad musa-asad changed the title Support entity for custom metrics Support entity for OTLP custom metrics Mar 18, 2025
@musa-asad musa-asad marked this pull request as ready for review April 7, 2025 19:57
@musa-asad musa-asad requested a review from a team as a code owner April 7, 2025 19:57
@musa-asad musa-asad requested review from jefchien, lisguo, nathalapooja, sky333999 and mitali-salvi and removed request for lisguo, jefchien and nathalapooja April 7, 2025 20:06
@musa-asad musa-asad force-pushed the feature-custom-metrics-entity branch from 410aa11 to 1310484 Compare April 9, 2025 02:33
@musa-asad musa-asad requested review from lisguo and nathalapooja and removed request for sky333999 April 9, 2025 06:09
@musa-asad musa-asad removed the request for review from lisguo April 9, 2025 14:48
@musa-asad musa-asad merged commit 06e007c into main Apr 10, 2025
492 of 494 checks passed
@musa-asad musa-asad deleted the feature-custom-metrics-entity branch April 10, 2025 03:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants