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

[AD] Add docker labels as tags in AD #3564

Merged
merged 3 commits into from Nov 3, 2017
Merged

[AD] Add docker labels as tags in AD #3564

merged 3 commits into from Nov 3, 2017

Conversation

hkaj
Copy link
Member

@hkaj hkaj commented Nov 2, 2017

Note: Please remember to review the Datadog Contribution Guidelines
if you have not yet done so.

What does this PR do?

Add docker labels as tags for auto discovery.

Motivation

User request.

Testing Guidelines

Added unit tests for it.

Additional Notes

Anything else we should know when reviewing?

Copy link
Contributor

@xvello xvello left a comment

Choose a reason for hiding this comment

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

Logic LGTM, two nitpicks

# Docker labels as tags
# We can extract docker labels and add them as tags to all metrics reported by service discovery.
# All you have to do is supply a comma-separated list of label names to extract from containers when found.
#
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd add a reference to docker_daemon's collect_labels_as_tags for docker/kube metrics

for test in no_label_test_data:
self.assertEqual(test[1], DockerUtil().extract_container_tags(test[0], []))

for test in labeled_test_data:
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

"""Returns a list of tags based on a container and a label name list"""
tags = []
labels = ctr.get('Config', {}).get('Labels', {})
for lbl_name, lbl_val in labels.iteritems():
Copy link
Contributor

Choose a reason for hiding this comment

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

Just to be extra-safe, let's add a if not labels: return tags, I had the issue of a Config/Env being present but None instead of missing. See #3528

Copy link
Member Author

Choose a reason for hiding this comment

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

good catch!

Copy link
Contributor

@xvello xvello left a comment

Choose a reason for hiding this comment

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

🌮

@xvello xvello changed the title [WIP] Add docker labels as tags in AD [AD] Add docker labels as tags in AD Nov 3, 2017
@olivielpeau olivielpeau modified the milestones: 5.19.0, 5.20.0 Nov 3, 2017
@hkaj
Copy link
Member Author

hkaj commented Nov 3, 2017

unrelated CI failure, merging.

@hkaj hkaj merged commit 9ebf748 into master Nov 3, 2017
@hkaj hkaj deleted the haissam/ad-docker-lbls branch November 3, 2017 10:44
@hkaj hkaj modified the milestones: 5.20.0, 5.19.0 Nov 3, 2017
olivielpeau pushed a commit that referenced this pull request Nov 3, 2017
* [AD] Add docker labels as tags

* Add tests

* address review comments
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.

None yet

3 participants