Skip to content

Add setting container ID as UDP origin for Dogstatsd metrics - #9338

Closed
kenpetti-toasttab wants to merge 2 commits into
DataDog:mainfrom
kenpetti-toasttab:container_id_entity_id
Closed

Add setting container ID as UDP origin for Dogstatsd metrics#9338
kenpetti-toasttab wants to merge 2 commits into
DataDog:mainfrom
kenpetti-toasttab:container_id_entity_id

Conversation

@kenpetti-toasttab

@kenpetti-toasttab kenpetti-toasttab commented Oct 1, 2021

Copy link
Copy Markdown

What does this PR do?

Currently, using the dd.internal.entity_id Statsd tag to manually set a Dogstatsd metric's origin is only supported in Kubernetes. This change allows a user to set a metric's origin to a container ID.

If the value of dd.internal.entity_id is a UUID, assume it is a Kubernetes pod UID and set k8sOrigin. Otherwise, assume it is a container ID and set origin.

Additionally, the existing tests for k8sOrigin all used non-UUIDs, which does not conform to the real Kubernetes format for pod UIDs, defined here. This PR updates the tests to reflect the correct format.

Motivation

We are currently running Datadog agents in ECS as sidecars on Fargate. In this setup, we can't use UDS (can't have a shared socket), so we have to use UDP to send metrics. Because we're using UDP, the metrics don't have an origin, so attaching auto-discovered tags to the incoming metrics does not work.

If we can manually set the origin in our metrics, then we can attach auto-discovered tags to the metrics.

Additional Notes

Currently, it is assumed that the value of entityIDValue is a Kubernetes Pod UID, which is what the usage example in the Datadog docs indicates. However, the user could set DD_ENTITY_ID to whatever value they like and the entity ID would still be kubernetes_pod_uid://<not a pod UID>. I'm unsure if that use-case is intentional, but it does seems counter intuitive.

The assumption that DD_ENTITY_ID will be a Pod UID as per the documentation is strictly enforced by this PR, as it validates that the incoming value is a UUID to determine if it is a Kubernetes origin or not.

Also, this PR assumes that any non-UUID dd.internal.entity_id should be a container ID and used as origin. This is also a large assumption, but there is no set format for container IDs, so I could not validate the value was in fact a container ID. I'd love suggestions otherwise.

Describe how to test your changes

I did the following to test

  • Added 2 new test cases for cases where dd.internal.entity_id is a container ID, not a UUID
  • Updated existing tests that were using non-UUIDs for k8sOrigin to use UUIDs, to match the K8s Pod UID spec

I ran the test command as per the README

Checklist

  • A release note has been added or the changelog/no-changelog label has been applied.
  • The need-change/operator and need-change/helm labels has been applied if applicable.
  • The appropriate team/.. label has been applied, if known.
  • If known, an appropriate milestone has been selected; otherwise the Triage milestone is set.
  • The config template has been updated if applicable.

Note: Adding GitHub labels is only possible for contributors with write access.

@kenpetti-toasttab
kenpetti-toasttab requested a review from a team as a code owner October 1, 2021 02:12
@bits-bot

bits-bot commented Oct 1, 2021

Copy link
Copy Markdown
Collaborator

CLA assistant check
All committers have signed the CLA.

@olivielpeau
olivielpeau requested a review from a team October 1, 2021 09:30
@kenpetti-toasttab kenpetti-toasttab changed the title Adding support in Dogstatsd for setting UDP origin as a container ID via dd.internal.entity_id Setting UDP origin as a container ID via dd.internal.entity_id in Dogstatsd Oct 1, 2021
@kenpetti-toasttab kenpetti-toasttab changed the title Setting UDP origin as a container ID via dd.internal.entity_id in Dogstatsd Add setting container ID as UDP origin for Dogstatsd metrics Oct 1, 2021
…D based on the `dd.internal.entity_id` metric tag.

* Added tests for the above
* Updated tests to make the `kubernetes_pod_uid` values actually UUIDs rather than fake test data.
@kenpetti-toasttab

Copy link
Copy Markdown
Author

@djmitche I've added release notes, can you confirm that they look ok? Also, there are the tag-related checks (milestone, team_label) that I think you need to address, since I can't add tags.

@djmitche

djmitche commented Oct 1, 2021

Copy link
Copy Markdown
Contributor

I'll leave both of those to the @DataDog/container-integrations team. My review is more of a lower-level "looks correct", while they can better answer "is this a good idea."

@ahmed-mez ahmed-mez left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @kenpetti-toasttab for the contribution, I added a suggestion to make sure we don't break compatibility and make it possible to support UUIDs even outside of kubernetes in the future. Thanks!

Comment thread pkg/dogstatsd/enrich.go
Comment on lines +53 to +59
// All Kubernetes pod entityIDs are in UUID format. If the entityIDValueis a valid UUID, set
// k8sOrigin using the KubePodTaggerEntityPrefix, otherwise set origin with the ContainerEntityPrefix
if _, err := uuid.Parse(entityIDValue); err == nil {
k8sOrigin = kubelet.KubePodTaggerEntityPrefix + entityIDValue
} else {
origin = containers.ContainerEntityPrefix + entityIDValue
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not assume that a UUID can only be a k8s pod UUID. I'm thinking it would be better if the dsd client added the container_id:// prefix when needed.
Then we can call this function , if the string is not an entity name we just add the kubelet.KubePodTaggerEntityPrefix prefix (default behaviour) otherwise we just set the origin without adding any prefix.
This ensures backward compatibility.

@dd-octo-sts

dd-octo-sts Bot commented Oct 20, 2025

Copy link
Copy Markdown
Contributor

This pull request has been automatically marked as stale because it has not had activity in the past 15 days.

It will be closed in 30 days if no further activity occurs. If this pull request is still relevant, adding a comment or pushing new commits will keep it open. Also, you can always reopen the pull request if you missed the window.

Thank you for your contributions!

@jacjtito

Copy link
Copy Markdown

Hi,

We are closing this PR as there was no recent activity on it. Feel free to reopen it if you still need the feature.
Thanks

@jacjtito jacjtito closed this Feb 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants