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 #9791

Merged
merged 4 commits into from
Jul 29, 2021
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
2 changes: 2 additions & 0 deletions datadog_checks_base/datadog_checks/base/stubs/aggregator.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ def check_tag_names(metric, tags):
'cluster_name',
'clustername',
'cluster',
'clusterid',
'cluster_id',
'env',
'host_name',
'hostname',
Expand Down
10 changes: 9 additions & 1 deletion mapr/assets/configuration/spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions mapr/datadog_checks/mapr/config_models/defaults.py
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_disable_legacy_cluster_tag(field, value):
return False


def instance_empty_default_hostname(field, value):
return False

Expand Down
1 change: 1 addition & 0 deletions mapr/datadog_checks/mapr/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_legacy_cluster_tag: Optional[bool]
empty_default_hostname: Optional[bool]
hostname: Optional[str]
metric_whitelist: Optional[Sequence[str]]
Expand Down
6 changes: 6 additions & 0 deletions mapr/datadog_checks/mapr/data/conf.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -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.
##
Expand Down
28 changes: 21 additions & 7 deletions mapr/datadog_checks/mapr/mapr.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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():
Expand Down
2 changes: 1 addition & 1 deletion mapr/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
12 changes: 6 additions & 6 deletions mapr/tests/test_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
],
)
Expand All @@ -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',
Expand All @@ -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",
Expand Down
1 change: 0 additions & 1 deletion mapr/tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,3 @@ commands =
pip install -r requirements.in
pytest -v {posargs}
setenv =
DDEV_SKIP_GENERIC_TAGS_CHECK=true