Skip to content
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

[workloadmeta] Add support for "labels as tags" #9542

Merged
merged 4 commits into from
Oct 19, 2021

Conversation

davidor
Copy link
Member

@davidor davidor commented Oct 15, 2021

What does this PR do?

Introduces a new option "container_labels_as_tags" that allows the agent to extract container label values and set them as metric tags values. It's equivalent to the existing "docker_labels_as_tags", but it also works with containerd.

This PR also adds support for that new option in the tagger workloadmeta collector.

This PR also fixes a regression. The new containerd collector didn't support advanced options in env as tags like: '{"*":"_%%env%%"}'. That has been fixed.

Describe how to test your changes

This needs to be tested on Kubernetes. Also, this only works in containerd >= 1.5.6 because previous versions didn't propagate labels correctly. At the moment of writing this, kind does not come with that containerd version by default, but you can install it in a custom image like explained here: kubernetes-sigs/kind#1637 (comment)

  • Set DD_CONTAINER_LABELS_AS_TAGS to: "{"test_label": "test_label_as_tag"}", for example.
  • Deploy the agent on Kubernetes.
  • Build a Docker image with labels and deploy it to your Kubernetes cluster. For example:
FROM redis
LABEL test_label=test_val
  • Check agent tagger-list and verify that the tag "test_label_as_tag" has the value "test_val" in the workloadmeta-container section of the container that you deployed.
  • Check that advanced "as tags" configs (documented here) work. Both with envs and tags. You can try something like: set DD_CONTAINER_ENV_AS_TAGS to {"*":"ENVPREFIX_%%env%%"} and set DD_CONTAINER_LABELS_AS_TAGS to {"*":"LABELPREFIX_%%label%%"}. You should see those prefixes in agent tagger-list.

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.

@davidor davidor added this to the 7.33.0 milestone Oct 15, 2021
@davidor davidor requested review from a team as code owners October 15, 2021 13:52
@davidor davidor force-pushed the davidor/containerd-labels-as-tags branch from 9a7c5ba to 5424676 Compare October 19, 2021 09:34
@davidor davidor force-pushed the davidor/containerd-labels-as-tags branch from 5424676 to 0509a93 Compare October 19, 2021 09:42
@davidor
Copy link
Member Author

davidor commented Oct 19, 2021

Rebased on top of master to get the latest changes in the workloadmeta code.

@davidor davidor force-pushed the davidor/containerd-labels-as-tags branch from 0509a93 to 09b9166 Compare October 19, 2021 09:45
Copy link
Contributor

@ahmed-mez ahmed-mez left a comment

Choose a reason for hiding this comment

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

Thanks! ✅

Could you just update the PR description / testing section to mention that container_env_as_tags and container_labels_as_tags should support and be tested with advanced configs like '{"*":"<PREFIX>_%%label%%"}' as documented here ? thanks!

@davidor
Copy link
Member Author

davidor commented Oct 19, 2021

@ahmed-mez I updated the PR description and testing instructions.

@davidor davidor merged commit a557708 into main Oct 19, 2021
@davidor davidor deleted the davidor/containerd-labels-as-tags branch October 19, 2021 12:47
zandrewitte pushed a commit to StackVista/stackstate-agent that referenced this pull request Nov 17, 2022
* [config] Add container_labels_as_tags

* [tagger/workloadmeta] Use container_labels_as_tags option

* Add release note

* [workloadmeta] Use utils.InitMetadataAsTags for container envs and labels
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