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

disable generic tags feature #9853

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from 13 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
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ def instance_cache_shared_labels(field, value):
return True


def instance_check_generic_tags(field, value):
return False


def instance_collect_counters_with_distributions(field, value):
return False

Expand All @@ -64,6 +68,10 @@ def instance_connect_timeout(field, value):
return get_default_field_value(field, value)


def instance_disable_generic_tags(field, value):
return False


def instance_empty_default_hostname(field, value):
return False

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,12 @@ class Config:
aws_service: Optional[str]
cache_metric_wildcards: Optional[bool]
cache_shared_labels: Optional[bool]
check_generic_tags: Optional[bool]
cluster_arn: str
collect_counters_with_distributions: Optional[bool]
collect_histogram_buckets: Optional[bool]
connect_timeout: Optional[float]
disable_generic_tags: Optional[bool]
empty_default_hostname: Optional[bool]
enable_health_service_check: Optional[bool]
exclude_labels: Optional[Sequence[str]]
Expand Down
8 changes: 8 additions & 0 deletions apache/datadog_checks/apache/config_models/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,18 @@ def instance_aws_service(field, value):
return get_default_field_value(field, value)


def instance_check_generic_tags(field, value):
return False


def instance_connect_timeout(field, value):
return get_default_field_value(field, value)


def instance_disable_generic_tags(field, value):
return False


def instance_empty_default_hostname(field, value):
return False

Expand Down
2 changes: 2 additions & 0 deletions apache/datadog_checks/apache/config_models/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ class Config:
aws_host: Optional[str]
aws_region: Optional[str]
aws_service: Optional[str]
check_generic_tags: Optional[bool]
connect_timeout: Optional[float]
disable_generic_tags: Optional[bool]
empty_default_hostname: Optional[bool]
extra_headers: Optional[Mapping[str, Any]]
headers: Optional[Mapping[str, Any]]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ def instance_cache_shared_labels(field, value):
return True


def instance_check_generic_tags(field, value):
return False


def instance_collect_counters_with_distributions(field, value):
return False

Expand All @@ -60,6 +64,10 @@ def instance_connect_timeout(field, value):
return get_default_field_value(field, value)


def instance_disable_generic_tags(field, value):
return False


def instance_empty_default_hostname(field, value):
return False

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,11 @@ class Config:
aws_service: Optional[str]
cache_metric_wildcards: Optional[bool]
cache_shared_labels: Optional[bool]
check_generic_tags: Optional[bool]
collect_counters_with_distributions: Optional[bool]
collect_histogram_buckets: Optional[bool]
connect_timeout: Optional[float]
disable_generic_tags: Optional[bool]
empty_default_hostname: Optional[bool]
enable_health_service_check: Optional[bool]
entities: Optional[Sequence[Literal['controller', 'pool', 'serviceengine', 'virtualservice']]]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,18 @@ def shared_service_check_prefix(field, value):
return get_default_field_value(field, value)


def instance_check_generic_tags(field, value):
return False


def instance_collect_default_jvm_metrics(field, value):
return True


def instance_disable_generic_tags(field, value):
return False


def instance_empty_default_hostname(field, value):
return False

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ class Config:
allow_mutation = False

cassandra_aliasing: bool
check_generic_tags: Optional[bool]
collect_default_jvm_metrics: Optional[bool]
disable_generic_tags: Optional[bool]
empty_default_hostname: Optional[bool]
host: str
is_jmx: Optional[bool]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ def shared_service(field, value):
return get_default_field_value(field, value)


def instance_check_generic_tags(field, value):
return False


def instance_disable_generic_tags(field, value):
return False


def instance_empty_default_hostname(field, value):
return False

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class InstanceConfig(BaseModel):
class Config:
allow_mutation = False

check_generic_tags: Optional[bool]
disable_generic_tags: Optional[bool]
empty_default_hostname: Optional[bool]
host: Optional[str]
keyspaces: Sequence[str]
Expand Down
8 changes: 8 additions & 0 deletions consul/datadog_checks/consul/config_models/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,18 @@ def instance_catalog_checks(field, value):
return False


def instance_check_generic_tags(field, value):
return False


def instance_connect_timeout(field, value):
return get_default_field_value(field, value)


def instance_disable_generic_tags(field, value):
return False


def instance_disable_legacy_service_tag(field, value):
return False

Expand Down
2 changes: 2 additions & 0 deletions consul/datadog_checks/consul/config_models/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ class Config:
aws_region: Optional[str]
aws_service: Optional[str]
catalog_checks: Optional[bool]
check_generic_tags: Optional[bool]
connect_timeout: Optional[float]
disable_generic_tags: Optional[bool]
disable_legacy_service_tag: Optional[bool]
empty_default_hostname: Optional[bool]
extra_headers: Optional[Mapping[str, Any]]
Expand Down
18 changes: 15 additions & 3 deletions datadog_checks_base/datadog_checks/base/checks/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
from ..utils.limiter import Limiter
from ..utils.metadata import MetadataManager
from ..utils.secrets import SecretsSanitizer
from ..utils.tagging import GENERIC_TAGS
from ..utils.tls import TlsContextWrapper

try:
Expand Down Expand Up @@ -188,6 +189,10 @@ def __init__(self, *args, **kwargs):
self.instance = instance # type: InstanceType
self.instances = instances # type: List[InstanceType]
self.warnings = [] # type: List[str]
self.check_generic_tags = is_affirmative(self.instance.get('check_generic_tags', False)) if instance else False
self.disable_generic_tags = (
is_affirmative(self.instance.get('disable_generic_tags', False)) if instance else False
)

# `self.hostname` is deprecated, use `datadog_agent.get_hostname()` instead
self.hostname = datadog_agent.get_hostname() # type: str
Expand Down Expand Up @@ -1087,13 +1092,20 @@ def _normalize_tags_type(self, tags, device_name=None, metric_name=None):
for tag in tags:
if tag is None:
continue

try:
tag = to_native_string(tag)
except UnicodeError:
self.log.warning('Encoding error with tag `%s` for metric `%s`, ignoring tag', tag, metric_name)
continue

normalized_tags.append(tag)
if self.check_generic_tags or self.disable_generic_tags:
tag_name, value = tag.split(':')
tag_is_generic = tag_name in GENERIC_TAGS
if not tag_is_generic or not self.disable_generic_tags:
normalized_tags.append(tag)
if tag_is_generic:
new_name = '{}_{}'.format(self.name, tag_name)
normalized_tags.append('{}:{}'.format(new_name, value))
else:
normalized_tags.append(tag)

return normalized_tags
15 changes: 15 additions & 0 deletions datadog_checks_base/tests/base/checks/test_agent_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,21 @@ def test_external_hostname(self):
else:
set_external_tags.assert_called_with([('hostnam\xc3\xa9', {'src_name': ['key1:val1']})])

@pytest.mark.parametrize(
"check_generic_tags, disable_generic_tags, expected_tags",
[
pytest.param(False, False, {"foo:bar", "cluster:my_cluster"}),
pytest.param(True, False, {"foo:bar", "cluster:my_cluster", "myintegration_cluster:my_cluster"}),
pytest.param(True, True, {"foo:bar", "myintegration_cluster:my_cluster"}),
pytest.param(False, True, {"foo:bar", "myintegration_cluster:my_cluster"}),
],
)
def test_generic_tags(self, check_generic_tags, disable_generic_tags, expected_tags):
instance = {'check_generic_tags': check_generic_tags, 'disable_generic_tags': disable_generic_tags}
check = AgentCheck('myintegration', {}, [instance])
tags = check._normalize_tags_type(tags=["foo:bar", "cluster:my_cluster"])
assert set(tags) == expected_tags


class LimitedCheck(AgentCheck):
DEFAULT_METRIC_LIMIT = 10
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
- template: instances/tags
- template: instances/service
- template: instances/global
- name: disable_generic_tags
description: |
Generic tags such as `cluster` will be replaced by <integration_name>_cluster to avoid
getting mixed with other integraton tags.
value:
type: boolean
display_default: false
example: true
hidden: true
- name: check_generic_tags
description: |
When a generic tag is detected a matching <integration_name>_cluster will be emitted as well to avoid
hithwen marked this conversation as resolved.
Show resolved Hide resolved
getting mixed with other integraton tags
value:
type: boolean
display_default: false
example: true
hidden: true
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,18 @@ def instance_bearer_token_path(field, value):
return get_default_field_value(field, value)


def instance_check_generic_tags(field, value):
return False


def instance_connect_timeout(field, value):
return get_default_field_value(field, value)


def instance_disable_generic_tags(field, value):
return False


def instance_empty_default_hostname(field, value):
return False

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ class Config:
aws_service: Optional[str]
bearer_token_auth: Optional[bool]
bearer_token_path: Optional[str]
check_generic_tags: Optional[bool]
connect_timeout: Optional[float]
disable_generic_tags: Optional[bool]
empty_default_hostname: Optional[bool]
exclude_labels: Optional[Sequence[str]]
extra_headers: Optional[Mapping[str, Any]]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ def shared_service(field, value):
return get_default_field_value(field, value)


def instance_check_generic_tags(field, value):
return False


def instance_countonly(field, value):
return False

Expand All @@ -20,6 +24,10 @@ def instance_dirtagname(field, value):
return get_default_field_value(field, value)


def instance_disable_generic_tags(field, value):
return False


def instance_empty_default_hostname(field, value):
return False

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ class InstanceConfig(BaseModel):
class Config:
allow_mutation = False

check_generic_tags: Optional[bool]
countonly: Optional[bool]
directory: str
dirs_patterns_full: Optional[bool]
dirtagname: Optional[str]
disable_generic_tags: Optional[bool]
empty_default_hostname: Optional[bool]
exclude_dirs: Optional[Sequence[str]]
filegauges: Optional[bool]
Expand Down
8 changes: 8 additions & 0 deletions elastic/datadog_checks/elastic/config_models/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ def instance_cat_allocation_stats(field, value):
return False


def instance_check_generic_tags(field, value):
return False


def instance_cluster_stats(field, value):
return False

Expand All @@ -56,6 +60,10 @@ def instance_connect_timeout(field, value):
return get_default_field_value(field, value)


def instance_disable_generic_tags(field, value):
return False


def instance_disable_legacy_cluster_tag(field, value):
return False

Expand Down
2 changes: 2 additions & 0 deletions elastic/datadog_checks/elastic/config_models/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ class Config:
aws_region: Optional[str]
aws_service: Optional[str]
cat_allocation_stats: Optional[bool]
check_generic_tags: Optional[bool]
cluster_stats: Optional[bool]
connect_timeout: Optional[float]
disable_generic_tags: Optional[bool]
disable_legacy_cluster_tag: Optional[bool]
empty_default_hostname: Optional[bool]
extra_headers: Optional[Mapping[str, Any]]
Expand Down
8 changes: 8 additions & 0 deletions envoy/datadog_checks/envoy/config_models/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ def instance_cache_metrics(field, value):
return True


def instance_check_generic_tags(field, value):
return False


def instance_collect_server_info(field, value):
return True

Expand All @@ -52,6 +56,10 @@ def instance_connect_timeout(field, value):
return get_default_field_value(field, value)


def instance_disable_generic_tags(field, value):
return False


def instance_disable_legacy_cluster_tag(field, value):
return False

Expand Down
2 changes: 2 additions & 0 deletions envoy/datadog_checks/envoy/config_models/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ class Config:
aws_region: Optional[str]
aws_service: Optional[str]
cache_metrics: Optional[bool]
check_generic_tags: Optional[bool]
collect_server_info: Optional[bool]
connect_timeout: Optional[float]
disable_generic_tags: Optional[bool]
disable_legacy_cluster_tag: Optional[bool]
empty_default_hostname: Optional[bool]
excluded_metrics: Optional[Sequence[str]]
Expand Down
Loading