Skip to content

Commit

Permalink
Disable generic tags - option 2 (DataDog#10027)
Browse files Browse the repository at this point in the history
* Transform generic tags
* Add config option
* Sync models

Co-authored-by: Paul <[email protected]>
  • Loading branch information
hithwen and coignetp authored Sep 9, 2021
1 parent 40d9ceb commit 6a7abf9
Show file tree
Hide file tree
Showing 141 changed files with 383 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,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 @@ -72,6 +72,7 @@ class Config:
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
4 changes: 4 additions & 0 deletions apache/datadog_checks/apache/config_models/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,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
1 change: 1 addition & 0 deletions apache/datadog_checks/apache/config_models/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class Config:
aws_region: Optional[str]
aws_service: Optional[str]
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 @@ -60,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_empty_default_hostname(field, value):
return False

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class Config:
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
4 changes: 4 additions & 0 deletions cassandra/datadog_checks/cassandra/config_models/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ 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 @@ -19,6 +19,7 @@ class Config:

cassandra_aliasing: 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,10 @@ def shared_service(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,6 +17,7 @@ class InstanceConfig(BaseModel):
class Config:
allow_mutation = False

disable_generic_tags: Optional[bool]
empty_default_hostname: Optional[bool]
host: Optional[str]
keyspaces: Sequence[str]
Expand Down
4 changes: 4 additions & 0 deletions consul/datadog_checks/consul/config_models/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,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_service_tag(field, value):
return False

Expand Down
1 change: 1 addition & 0 deletions consul/datadog_checks/consul/config_models/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class Config:
aws_service: Optional[str]
catalog_checks: 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
20 changes: 16 additions & 4 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,9 @@ def __init__(self, *args, **kwargs):
self.instance = instance # type: InstanceType
self.instances = instances # type: List[InstanceType]
self.warnings = [] # type: List[str]
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 +1091,21 @@ 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.disable_generic_tags:
normalized_tags.append(self.degeneralise_tag(tag))
else:
normalized_tags.append(tag)
return normalized_tags

def degeneralise_tag(self, tag):
tag_name, value = tag.split(':')
if tag_name in GENERIC_TAGS:
new_name = '{}_{}'.format(self.name, tag_name)
return '{}:{}'.format(new_name, value)
else:
return tag
13 changes: 13 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,19 @@ def test_external_hostname(self):
else:
set_external_tags.assert_called_with([('hostnam\xc3\xa9', {'src_name': ['key1:val1']})])

@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"}),
],
)
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"])
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,12 @@
- 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
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,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 @@ -65,6 +65,7 @@ class Config:
bearer_token_auth: Optional[bool]
bearer_token_path: Optional[str]
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
4 changes: 4 additions & 0 deletions directory/datadog_checks/directory/config_models/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,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 @@ -21,6 +21,7 @@ class Config:
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
4 changes: 4 additions & 0 deletions elastic/datadog_checks/elastic/config_models/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,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
1 change: 1 addition & 0 deletions elastic/datadog_checks/elastic/config_models/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class Config:
cat_allocation_stats: 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
4 changes: 4 additions & 0 deletions envoy/datadog_checks/envoy/config_models/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,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
1 change: 1 addition & 0 deletions envoy/datadog_checks/envoy/config_models/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class Config:
cache_metrics: 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
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,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 @@ -65,6 +65,7 @@ class Config:
bearer_token_auth: Optional[bool]
bearer_token_path: Optional[str]
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
4 changes: 4 additions & 0 deletions glusterfs/datadog_checks/glusterfs/config_models/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ def shared_service(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,6 +17,7 @@ class InstanceConfig(BaseModel):
class Config:
allow_mutation = False

disable_generic_tags: Optional[bool]
empty_default_hostname: Optional[bool]
min_collection_interval: Optional[float]
service: Optional[str]
Expand Down
4 changes: 4 additions & 0 deletions go_expvar/datadog_checks/go_expvar/config_models/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,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 @@ -50,6 +50,7 @@ class Config:
aws_region: Optional[str]
aws_service: Optional[str]
connect_timeout: Optional[float]
disable_generic_tags: Optional[bool]
empty_default_hostname: Optional[bool]
expvar_url: str
extra_headers: Optional[Mapping[str, Any]]
Expand Down
4 changes: 4 additions & 0 deletions gunicorn/datadog_checks/gunicorn/config_models/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ def shared_service(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
1 change: 1 addition & 0 deletions gunicorn/datadog_checks/gunicorn/config_models/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class InstanceConfig(BaseModel):
class Config:
allow_mutation = False

disable_generic_tags: Optional[bool]
empty_default_hostname: Optional[bool]
gunicorn: Optional[str]
min_collection_interval: Optional[float]
Expand Down
4 changes: 4 additions & 0 deletions haproxy/datadog_checks/haproxy/config_models/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ def instance_count_status_by_service(field, value):
return True


def instance_disable_generic_tags(field, value):
return False


def instance_disable_legacy_service_tag(field, value):
return False

Expand Down
1 change: 1 addition & 0 deletions haproxy/datadog_checks/haproxy/config_models/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class Config:
collect_status_metrics_by_host: Optional[bool]
connect_timeout: Optional[float]
count_status_by_service: Optional[bool]
disable_generic_tags: Optional[bool]
disable_legacy_service_tag: Optional[bool]
empty_default_hostname: Optional[bool]
enable_service_check: Optional[bool]
Expand Down
4 changes: 4 additions & 0 deletions harbor/datadog_checks/harbor/config_models/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,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
1 change: 1 addition & 0 deletions harbor/datadog_checks/harbor/config_models/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class Config:
aws_region: Optional[str]
aws_service: Optional[str]
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 @@ -76,6 +76,10 @@ def instance_days_warning(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 @@ -48,6 +48,7 @@ class Config:
data: Optional[Union[Mapping[str, Any], str]]
days_critical: Optional[int]
days_warning: Optional[int]
disable_generic_tags: Optional[bool]
empty_default_hostname: Optional[bool]
extra_headers: Optional[Mapping[str, Any]]
headers: Optional[Mapping[str, Any]]
Expand Down
Loading

0 comments on commit 6a7abf9

Please sign in to comment.