diff --git a/datadog_checks_base/datadog_checks/base/stubs/aggregator.py b/datadog_checks_base/datadog_checks/base/stubs/aggregator.py index e057e24febbe5..3de381e3848bf 100644 --- a/datadog_checks_base/datadog_checks/base/stubs/aggregator.py +++ b/datadog_checks_base/datadog_checks/base/stubs/aggregator.py @@ -43,6 +43,8 @@ def check_tag_names(metric, tags): 'cluster_name', 'clustername', 'cluster', + 'clusterid', + 'cluster_id', 'env', 'host_name', 'hostname', diff --git a/mapr/assets/configuration/spec.yaml b/mapr/assets/configuration/spec.yaml index 49be2205fc1fa..5d564e8f65f08 100644 --- a/mapr/assets/configuration/spec.yaml +++ b/mapr/assets/configuration/spec.yaml @@ -46,5 +46,13 @@ files: value: example: 1 type: integer - + - name: disable_legacy_cluster_tag + description: | + Enable to stop submitting the tag `clustername`, which has been renamed to `mapr_cluster` and `clusterid` + which has been renamed to `mapr_cluster_id` + value: + type: boolean + display_default: false + example: true + enabled: true - template: instances/default diff --git a/mapr/datadog_checks/mapr/config_models/defaults.py b/mapr/datadog_checks/mapr/config_models/defaults.py index 303c3179a7b89..bf6168b534dfa 100644 --- a/mapr/datadog_checks/mapr/config_models/defaults.py +++ b/mapr/datadog_checks/mapr/config_models/defaults.py @@ -8,6 +8,10 @@ def shared_service(field, value): return get_default_field_value(field, value) +def instance_disable_legacy_cluster_tag(field, value): + return False + + def instance_empty_default_hostname(field, value): return False diff --git a/mapr/datadog_checks/mapr/config_models/instance.py b/mapr/datadog_checks/mapr/config_models/instance.py index 89661a85f728b..4863264bdebc1 100644 --- a/mapr/datadog_checks/mapr/config_models/instance.py +++ b/mapr/datadog_checks/mapr/config_models/instance.py @@ -17,6 +17,7 @@ class InstanceConfig(BaseModel): class Config: allow_mutation = False + disable_legacy_cluster_tag: Optional[bool] empty_default_hostname: Optional[bool] hostname: Optional[str] metric_whitelist: Optional[Sequence[str]] diff --git a/mapr/datadog_checks/mapr/data/conf.yaml.example b/mapr/datadog_checks/mapr/data/conf.yaml.example index 288e26580e527..65cb616ca0502 100644 --- a/mapr/datadog_checks/mapr/data/conf.yaml.example +++ b/mapr/datadog_checks/mapr/data/conf.yaml.example @@ -47,6 +47,12 @@ instances: # # streams_count: 1 + ## @param disable_legacy_cluster_tag - boolean - optional - default: false + ## Enable to stop submitting the tag `clustername`, which has been renamed to `mapr_cluster` and `clusterid` + ## which has been renamed to `mapr_cluster_id` + # + disable_legacy_cluster_tag: true + ## @param tags - list of strings - optional ## A list of tags to attach to every metric and service check emitted by this instance. ## diff --git a/mapr/datadog_checks/mapr/mapr.py b/mapr/datadog_checks/mapr/mapr.py index cf8cdc68cae27..b5df636f636e4 100644 --- a/mapr/datadog_checks/mapr/mapr.py +++ b/mapr/datadog_checks/mapr/mapr.py @@ -1,13 +1,14 @@ # (C) Datadog, Inc. 2019-present # All rights reserved # Licensed under a 3-clause BSD style license (see LICENSE) +import copy import json import os import re from six import iteritems -from datadog_checks.base import AgentCheck, ensure_unicode +from datadog_checks.base import AgentCheck, ensure_unicode, is_affirmative from datadog_checks.base.errors import CheckException from .common import ALLOWED_METRICS, COUNT_METRICS, GAUGE_METRICS, HISTOGRAM_METRICS, MONOTONIC_COUNTER_METRICS @@ -53,9 +54,9 @@ def __init__(self, name, init_config, instances): topic_name=self.hostname, ) self.allowed_metrics = [re.compile(w) for w in self.instance.get('metric_whitelist', [])] - self.base_tags = self.instance.get('tags', []) + self.custom_tags = self.instance.get('tags', []) self.has_ever_submitted_metrics = False - + self._disable_legacy_cluster_tag = is_affirmative(self.instance.get('disable_legacy_cluster_tag', False)) self.auth_ticket = self.instance.get('ticket_location', os.environ.get(TICKET_LOCATION_ENV_VAR)) if not self.auth_ticket: @@ -85,11 +86,11 @@ def check(self, _): conn = self.get_connection() except Exception: self.service_check( - SERVICE_CHECK, AgentCheck.CRITICAL, self.base_tags + ['topic:{}'.format(self.topic_path)] + SERVICE_CHECK, AgentCheck.CRITICAL, self.custom_tags + ['topic:{}'.format(self.topic_path)] ) raise else: - self.service_check(SERVICE_CHECK, AgentCheck.OK, self.base_tags + ['topic:{}'.format(self.topic_path)]) + self.service_check(SERVICE_CHECK, AgentCheck.OK, self.custom_tags + ['topic:{}'.format(self.topic_path)]) submitted_metrics_count = 0 @@ -146,7 +147,7 @@ def check(self, _): ) if submitted_metrics_count: - self.gauge(METRICS_SUBMITTED_METRIC_NAME, submitted_metrics_count, self.base_tags) + self.gauge(METRICS_SUBMITTED_METRIC_NAME, submitted_metrics_count, self.custom_tags) def get_connection(self): if self._conn: @@ -181,7 +182,20 @@ def should_collect_metric(self, metric_name): def submit_metric(self, metric): metric_name = metric['metric'] - tags = self.base_tags + ["{}:{}".format(k, v) for k, v in iteritems(metric['tags'])] + tags = copy.deepcopy(self.custom_tags) + for k, v in iteritems(metric['tags']): + if k == 'clustername': + tags.append("{}:{}".format('mapr_cluster', v)) + if not self._disable_legacy_cluster_tag: + self._log_deprecation(k, 'mapr_cluster') + tags.append("{}:{}".format(k, v)) + elif k == 'clusterid': + tags.append("{}:{}".format('mapr_cluster_id', v)) + if not self._disable_legacy_cluster_tag: + self._log_deprecation(k, 'mapr_cluster_id') + tags.append("{}:{}".format(k, v)) + else: + tags.append("{}:{}".format(k, v)) if 'buckets' in metric and metric_name in HISTOGRAM_METRICS: for bounds, value in metric['buckets'].items(): diff --git a/mapr/tests/common.py b/mapr/tests/common.py index 6d1ce4864708c..8ee0fc74606cd 100644 --- a/mapr/tests/common.py +++ b/mapr/tests/common.py @@ -5,7 +5,7 @@ HERE = get_here() -INSTANCE = {'ticket_location': 'foo'} +INSTANCE = {'ticket_location': 'foo', 'disable_legacy_cluster_tag': True} KAFKA_METRIC = { u'metric': u'mapr.process.context_switch_involuntary', diff --git a/mapr/tests/test_unit.py b/mapr/tests/test_unit.py index 92f2d1fca9433..7ead6d7f76734 100644 --- a/mapr/tests/test_unit.py +++ b/mapr/tests/test_unit.py @@ -55,9 +55,9 @@ def test_submit_gauge(instance, aggregator): 'mapr.process.context_switch_involuntary', value=6308, tags=[ - 'clustername:demo', + 'mapr_cluster:demo', 'process_name:apiserver', - 'clusterid:7616098736519857348', + 'mapr_cluster_id:7616098736519857348', 'fqdn:mapr-lab-2-ghs6.c.datadog-integrations-lab.internal', ], ) @@ -73,9 +73,9 @@ def test_submit_gauge_additional_tags(instance, aggregator): aggregator.assert_metric( 'mapr.process.context_switch_involuntary', tags=[ - 'clustername:demo', + 'mapr_cluster:demo', 'process_name:apiserver', - 'clusterid:7616098736519857348', + 'mapr_cluster_id:7616098736519857348', 'fqdn:mapr-lab-2-ghs6.c.datadog-integrations-lab.internal', 'foo:bar', 'baz:biz', @@ -89,8 +89,8 @@ def test_submit_bucket(instance, aggregator): check = MaprCheck('mapr', {}, [instance]) check.submit_metric(DISTRIBUTION_METRIC) expected_tags = [ - "clusterid:7616098736519857348", - "clustername:demo", + "mapr_cluster_id:7616098736519857348", + "mapr_cluster:demo", "fqdn:mapr-lab-2-dhk4.c.datadog-integrations-lab.internal", "noindex://primary", "rpc_type:put", diff --git a/mapr/tox.ini b/mapr/tox.ini index a5ac9082dce4f..e65426fdc6076 100644 --- a/mapr/tox.ini +++ b/mapr/tox.ini @@ -23,4 +23,3 @@ commands = pip install -r requirements.in pytest -v {posargs} setenv = - DDEV_SKIP_GENERIC_TAGS_CHECK=true