-
Notifications
You must be signed in to change notification settings - Fork 213
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
Add k8sattributesprocessor to otlp pipeline with workload type detection #1524
Conversation
This reverts commit 74b183d.
It looks like the sample application I used return |
7f0a8f8
to
5e1b3aa
Compare
- cumulativetodelta/hostOtlpMetrics/cloudwatchlogs | ||
- k8sattributes/hostOtlpMetrics/cloudwatchlogs |
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.
should cumulativetodelta come after awsentity?
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.
From my understanding, the cumulativetodelta processor only touches numeric datapoint attributes, whereas awsentity only touches resource attributes, and sometimes string datapoint attributes to get service name information, which should be fine.
Albeit, my changes shouldn't have changed the position of the entity processor. I can move it after if you think it's safer. It looks like we do the same thing for the "hostDeltaMetrics"
pipeline, so we may have to change that too. I am fine with either option, but let me know.
translator/translate/otel/processor/k8sattributesprocessor/translator.go
Outdated
Show resolved
Hide resolved
translator/translate/otel/processor/k8sattributesprocessor/translator.go
Outdated
Show resolved
Hide resolved
translator/translate/otel/processor/k8sattributesprocessor/translator.go
Outdated
Show resolved
Hide resolved
@@ -90,6 +99,33 @@ func (d *EksDetector) getConfigMap(namespace string, name string) (map[string]st | |||
return configMap.Data, nil | |||
} | |||
|
|||
func (d *EksDetector) getWorkloadType() (string, error) { | |||
podName := os.Getenv("POD_NAME") |
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.
how will these env vars be set?
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.
They're set by the add-on.
POD_NAME
is set from the operator: https://github.com/aws/amazon-cloudwatch-agent-operator/blob/822b18ac6497d8c43c4b662a67c6738e53b10546/internal/manifests/collector/container.go#L75.K8S_NAMESPACE
is set from the helm-charts: https://github.com/aws-observability/helm-charts/blob/931216205b9f9ec5101eff80c3173736bbcd4c01/charts/amazon-cloudwatch-observability/templates/linux/cloudwatch-agent-custom-resource.yaml#L190.
For cases where the add-on isn't configured, I make sure to print out errors instead of failing the agent.
translator/util/sdkutil.go
Outdated
@@ -80,6 +80,16 @@ func DetectKubernetesMode(configuredMode string) string { | |||
|
|||
} | |||
|
|||
func DetectWorkloadType() string { |
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.
If we are returning a value, we should name the func "Get*"
also if we are checking for an error, maybe it's worth returning an error as well?
func DetectWorkloadType() string { | |
func GetWorkloadType() (string, error) { |
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.
We don't want to return an error (or warning) here since if it defaults to ""
, then it just means they are not on Kubernetes, which is fine. Though, I renamed to GetWorkloadType()
.
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 implement the Kubernetes Attributes Processor within the CloudWatch Agent.
Additionally, the process of fetching metadata with the Kubernetes Attributes Processor depends on the agent's workload type:
If the agent is running as a daemonset, we must configure a node filter. This prevents the agent from fetching metadata for pods on other nodes.
Hence, we must also implement workload type detection.
Description of changes
Revision 1
getWorkloadType()
intranslator/util/eksdetector/eksdetector.go
to query Kubernetes API withPOD_NAME
andK8S_NAMESPACE
environmental variables and retrieve workload type from pod information.Workload
value inIsEKSCache
.IsEKSCache
to use inDetectWorkloadType()
to return workload type.translator/context/context.go
.config-translator
binary.Revision 2
SetWorkloadType()
.getWorkloadType()
."Unknown"
to""
ingetWorkloadType()
since it serves no functional purpose.Revision 3
DetectWorkloadType()
toGetWorkloadType()
getWorkloadType()
.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
OTEL_EXPORTER_OTLP_ENDPOINT
tohttp://cloudwatch-agent.amazon-cloudwatch:4317
.make docker-build-amd64
and changed the image in the AmazonCloudWatchAgent custom resource.Kubernetes Attributes Processor
Debug Exporter Output:
K8s Metadata:
Entity Fields:
EMF Output:
K8s Metadata:
Workload Type Detection
DaemonSet:
![Screenshot 2025-02-03 at 1 17 06 AM](https://private-user-images.githubusercontent.com/165414028/408984702-ea47a336-30ff-4215-8f26-1b1d2a1ea056.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkxNTAxNTEsIm5iZiI6MTczOTE0OTg1MSwicGF0aCI6Ii8xNjU0MTQwMjgvNDA4OTg0NzAyLWVhNDdhMzM2LTMwZmYtNDIxNS04ZjI2LTFiMWQyYTFlYTA1Ni5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjUwMjEwJTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI1MDIxMFQwMTEwNTFaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT0yZjkwOTY3NjEzOGYzNzFkZTAzYzMyNjFlYjE1OGMxNzBjZjU4MzE3NmI2MWQ5M2NlMjZkYTMzMTFiMWMyZjhlJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCJ9.aWOO3nSWexnzHSsO4BH-0W6ybgsChIs6OlS2ezw96wM)
Deployment:
![Screenshot 2025-02-03 at 1 17 48 AM](https://private-user-images.githubusercontent.com/165414028/408984872-6dfa6b29-b8ee-4b8e-802d-0454e7b00208.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkxNTAxNTEsIm5iZiI6MTczOTE0OTg1MSwicGF0aCI6Ii8xNjU0MTQwMjgvNDA4OTg0ODcyLTZkZmE2YjI5LWI4ZWUtNGI4ZS04MDJkLTA0NTRlN2IwMDIwOC5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjUwMjEwJTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI1MDIxMFQwMTEwNTFaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT0wMTg2OTMwYzQwMjFmMzBiYTgyMTQ0YmEzODEwMDg5ZjkxMDFiMWMzOTc4NzY5OTMzYzRlNzFlZGVhMDQyZTI1JlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCJ9.1ouUgILh7reQwgI3pYlUS2l61klg7izusjGfv35sfCw)
Requirements
Before commit the code, please do the following steps.
make fmt
andmake fmt-sh
make lint