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

Allow tags that are just a value with no key #11973

Merged
merged 1 commit into from
May 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions datadog_checks_base/datadog_checks/base/checks/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1223,10 +1223,19 @@ def _normalize_tags_type(self, tags, device_name=None, metric_name=None):
return normalized_tags

def degeneralise_tag(self, tag):
tag_name, value = tag.split(':', 1)
split_tag = tag.split(':', 1)
if len(split_tag) > 1:
tag_name, value = split_tag
else:
tag_name = tag
value = None

if tag_name in GENERIC_TAGS:
new_name = '{}_{}'.format(self.name, tag_name)
return '{}:{}'.format(new_name, value)
if value:
return '{}:{}'.format(new_name, value)
else:
return new_name
else:
return tag

Expand Down
6 changes: 3 additions & 3 deletions datadog_checks_base/tests/base/checks/test_agent_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -638,14 +638,14 @@ def test_external_hostname(self):
@pytest.mark.parametrize(
"disable_generic_tags, expected_tags",
[
pytest.param(False, {"foo:bar", "cluster:my_cluster"}),
pytest.param(True, {"foo:bar", "myintegration_cluster:my_cluster"}),
pytest.param(False, {"foo:bar", "cluster:my_cluster", "version", "bar"}),
pytest.param(True, {"foo:bar", "myintegration_cluster:my_cluster", "myintegration_version", "bar"}),
],
)
def test_generic_tags(self, disable_generic_tags, expected_tags):
instance = {'disable_generic_tags': disable_generic_tags}
check = AgentCheck('myintegration', {}, [instance])
tags = check._normalize_tags_type(tags=["foo:bar", "cluster:my_cluster"])
tags = check._normalize_tags_type(tags=["foo:bar", "cluster:my_cluster", "version", "bar"])
assert set(tags) == expected_tags

@pytest.mark.parametrize(
Expand Down