Skip to content

Commit

Permalink
Make is_leader tag optional (#3114)
Browse files Browse the repository at this point in the history
  • Loading branch information
ofek authored Feb 14, 2019
1 parent 2edef7f commit f744b97
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
5 changes: 5 additions & 0 deletions etcd/datadog_checks/etcd/data/conf.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ instances:
#
# prometheus_url: http://localhost:2379/metrics

## @param leader_tag - boolean - optional - default: true
## Whether or not to tag with `is_leader:true` or `is_leader:false`.
#
# leader_tag: true

## @param send_histograms_buckets - boolean - optional - default: true
## Histogram buckets can be noisy and generate many tags.
## Set send_histograms_buckets to true to pull them.
Expand Down
4 changes: 3 additions & 1 deletion etcd/datadog_checks/etcd/etcd.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,9 @@ def check_post_v3(self, instance):
)

tags = []
self.add_leader_state_tag(scraper_config, tags)

if is_affirmative(instance.get('leader_tag', True)):
self.add_leader_state_tag(scraper_config, tags)

scraper_config['_metric_tags'][:] = tags

Expand Down
19 changes: 19 additions & 0 deletions etcd/tests/test_etcd.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# (C) Datadog, Inc. 2018
# All rights reserved
# Licensed under a 3-clause BSD style license (see LICENSE)
from copy import deepcopy

import pytest
import requests
from six import itervalues
Expand Down Expand Up @@ -52,6 +54,23 @@ def test_check(aggregator, instance):
assert aggregator.metrics_asserted_pct > 80


@preview
def test_check_no_leader_tag(aggregator, instance):
instance = deepcopy(instance)
instance['leader_tag'] = False

check = Etcd('etcd', {}, {}, [instance])
check.check(instance)

for metric in itervalues(METRIC_MAP):
try:
aggregator.assert_metric(metric, tags=[])
except AssertionError:
pass

assert aggregator.metrics_asserted_pct > 80


@preview
def test_service_check(aggregator, instance):
check = Etcd(CHECK_NAME, None, {}, [instance])
Expand Down

0 comments on commit f744b97

Please sign in to comment.