Skip to content

Commit

Permalink
Support ignoring instance tags
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmed-mez committed May 21, 2021
1 parent 4e728a1 commit c1e59a9
Show file tree
Hide file tree
Showing 25 changed files with 262 additions and 0 deletions.
9 changes: 9 additions & 0 deletions amazon_msk/datadog_checks/amazon_msk/data/conf.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,15 @@ instances:
# <KEY_2>:
# - '*'

## @param ignore_tags - list of strings - optional
## A list of tags to ignore, the "*" wildcard can be used to match multiple tag strings.
#
# ignore_tags:
# - <FULL:TAG>
# - <TAG_PREFIX*>
# - <*TAG_SUFFIX>
# - <*SUBSTRING*>

## @param proxy - mapping - optional
## This overrides the `proxy` setting in `init_config`.
##
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,15 @@ instances:
# <KEY_2>:
# - '*'

## @param ignore_tags - list of strings - optional
## A list of tags to ignore, the "*" wildcard can be used to match multiple tag strings.
#
# ignore_tags:
# - <FULL:TAG>
# - <TAG_PREFIX*>
# - <*TAG_SUFFIX>
# - <*SUBSTRING*>

## @param proxy - mapping - optional
## This overrides the `proxy` setting in `init_config`.
##
Expand Down
9 changes: 9 additions & 0 deletions cilium/datadog_checks/cilium/data/conf.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,15 @@ instances:
# <KEY_2>:
# - '*'

## @param ignore_tags - list of strings - optional
## A list of tags to ignore, the "*" wildcard can be used to match multiple tag strings.
#
# ignore_tags:
# - <FULL:TAG>
# - <TAG_PREFIX*>
# - <*TAG_SUFFIX>
# - <*SUBSTRING*>

## @param proxy - mapping - optional
## This overrides the `proxy` setting in `init_config`.
##
Expand Down
9 changes: 9 additions & 0 deletions cockroachdb/datadog_checks/cockroachdb/data/conf.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,15 @@ instances:
# <KEY_2>:
# - '*'

## @param ignore_tags - list of strings - optional
## A list of tags to ignore, the "*" wildcard can be used to match multiple tag strings.
#
# ignore_tags:
# - <FULL:TAG>
# - <TAG_PREFIX*>
# - <*TAG_SUFFIX>
# - <*SUBSTRING*>

## @param proxy - mapping - optional
## This overrides the `proxy` setting in `init_config`.
##
Expand Down
9 changes: 9 additions & 0 deletions coredns/datadog_checks/coredns/data/conf.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,15 @@ instances:
# <KEY_2>:
# - '*'

## @param ignore_tags - list of strings - optional
## A list of tags to ignore, the "*" wildcard can be used to match multiple tag strings.
#
# ignore_tags:
# - <FULL:TAG>
# - <TAG_PREFIX*>
# - <*TAG_SUFFIX>
# - <*SUBSTRING*>

## @param proxy - mapping - optional
## This overrides the `proxy` setting in `init_config`.
##
Expand Down
9 changes: 9 additions & 0 deletions crio/datadog_checks/crio/data/conf.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,15 @@ instances:
# <KEY_2>:
# - '*'

## @param ignore_tags - list of strings - optional
## A list of tags to ignore, the "*" wildcard can be used to match multiple tag strings.
#
# ignore_tags:
# - <FULL:TAG>
# - <TAG_PREFIX*>
# - <*TAG_SUFFIX>
# - <*SUBSTRING*>

## @param proxy - mapping - optional
## This overrides the `proxy` setting in `init_config`.
##
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,21 @@ def create_scraper_configuration(self, instance=None):
# Custom tags that will be sent with each metric
config['custom_tags'] = instance.get('tags', [])

# Some tags can be ignored to reduce the cardinality.
# This can be useful for cost optimization in containerized environments
# when the openmetrics check is configured to collect custom metrics.
# Even when the Agent's Tagger is configured to add low-cardinality tags only,
# some tags can still generate unwanted metric contexts (e.g pod annotations as tags).
ignore_tags = instance.get('ignore_tags', default_instance.get('ignore_tags', []))
if ignore_tags:
ignored_tag_patterns = set()
for ignored_tag in ignore_tags:
ignored_tag_patterns.add(translate(ignored_tag))

if ignored_tag_patterns:
ignored_tags_re = compile('|'.join(ignored_tag_patterns))
config['custom_tags'] = [tag for tag in config['custom_tags'] if not ignored_tags_re.search(tag)]

# Additional tags to be sent with each metric
config['_metric_tags'] = []

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,21 @@ def __init__(self, check, config):
if not isinstance(entry, str):
raise ConfigurationError(f'Entry #{i} of setting `tags` must be a string')

# Some tags can be ignored to reduce the cardinality.
# This can be useful for cost optimization in containerized environments
# when the openmetrics check is configured to collect custom metrics.
# Even when the Agent's Tagger is configured to add low-cardinality tags only,
# some tags can still generate unwanted metric contexts (e.g pod annotations as tags).
ignore_tags = config.get('ignore_tags', [])
if ignore_tags:
ignored_tag_patterns = set()
for ignored_tag in ignore_tags:
ignored_tag_patterns.add(fnmatch.translate(ignored_tag))

if ignored_tag_patterns:
ignored_tags_re = re.compile('|'.join(ignored_tag_patterns))
custom_tags = [tag for tag in custom_tags if not ignored_tags_re.search(tag)]

# 16 KiB seems optimal, and is also the standard chunk size of the Bittorrent protocol:
# https://www.bittorrent.org/beps/bep_0003.html
self.request_size = int(float(config.get('request_size') or 16) * KIBIBYTE)
Expand Down
22 changes: 22 additions & 0 deletions datadog_checks_base/tests/openmetrics/test_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -550,3 +550,25 @@ def test_excluded_metric(self, aggregator, dd_run_check, mock_http_response):
)

aggregator.assert_all_metrics_covered()


class TestIgnoreTags:
def test(self, aggregator, dd_run_check, mock_http_response):
mock_http_response(
"""
# HELP go_memstats_alloc_bytes Number of bytes allocated and still in use.
# TYPE go_memstats_alloc_bytes gauge
go_memstats_alloc_bytes 6.396288e+06
"""
)

all_tags = ['foo', 'foofoo', 'bar', 'bar:baz']
ignored_tags = ['foo*', 'bar:baz']
check = get_check({'metrics': ['go_memstats_alloc_bytes'], 'tags': all_tags, 'ignore_tags': ignored_tags})
dd_run_check(check)

aggregator.assert_metric(
'test.go_memstats_alloc_bytes', 6396288, metric_type=aggregator.GAUGE, tags=['endpoint:test', 'bar']
)

aggregator.assert_all_metrics_covered()
17 changes: 17 additions & 0 deletions datadog_checks_base/tests/test_openmetrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -2781,3 +2781,20 @@ def test_empty_namespace(aggregator, mocked_prometheus_check, text_data, ref_gau
check.process_metric(ref_gauge, config)

aggregator.assert_metric('process.vm.bytes', count=1)


def test_ignore_tags(aggregator, mocked_prometheus_check, ref_gauge):
"""
Test that tags matching ignored tag patterns are properly discarded.
"""
check = mocked_prometheus_check
instance = copy.deepcopy(PROMETHEUS_CHECK_INSTANCE)
instance['tags'] = ['foo', 'foofoo', 'bar', 'bar:baz']
instance['ignore_tags'] = ['foo*', 'bar:baz']

config = check.get_scraper_config(instance)
config['_dry_run'] = False

check.process_metric(ref_gauge, config)

aggregator.assert_metric('prometheus.process.vm.bytes', tags=['bar'], count=1)
Original file line number Diff line number Diff line change
Expand Up @@ -300,5 +300,16 @@
value:
example: false
type: boolean
- name: ignore_tags
description: A list of tags to ignore, the "*" wildcard can be used to match multiple tag strings.
value:
type: array
items:
type: string
example:
- <FULL:TAG>
- <TAG_PREFIX*>
- <*TAG_SUFFIX>
- <*SUBSTRING*>
- template: instances/http
- template: instances/default
Original file line number Diff line number Diff line change
Expand Up @@ -167,5 +167,16 @@
example:
<KEY_1>: [<LABEL_1>, <LABEL_2>]
<KEY_2>: ['*']
- name: ignore_tags
description: A list of tags to ignore, the "*" wildcard can be used to match multiple tag strings.
value:
type: array
items:
type: string
example:
- <FULL:TAG>
- <TAG_PREFIX*>
- <*TAG_SUFFIX>
- <*SUBSTRING*>
- template: instances/http
- template: instances/default
9 changes: 9 additions & 0 deletions etcd/datadog_checks/etcd/data/conf.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,15 @@ instances:
# <KEY_2>:
# - '*'

## @param ignore_tags - list of strings - optional
## A list of tags to ignore, the "*" wildcard can be used to match multiple tag strings.
#
# ignore_tags:
# - <FULL:TAG>
# - <TAG_PREFIX*>
# - <*TAG_SUFFIX>
# - <*SUBSTRING*>

## @param proxy - mapping - optional
## This overrides the `proxy` setting in `init_config`.
##
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,15 @@ instances:
# <KEY_2>:
# - '*'

## @param ignore_tags - list of strings - optional
## A list of tags to ignore, the "*" wildcard can be used to match multiple tag strings.
#
# ignore_tags:
# - <FULL:TAG>
# - <TAG_PREFIX*>
# - <*TAG_SUFFIX>
# - <*SUBSTRING*>

## @param proxy - mapping - optional
## This overrides the `proxy` setting in `init_config`.
##
Expand Down
9 changes: 9 additions & 0 deletions gitlab/datadog_checks/gitlab/data/conf.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,15 @@ instances:
# <KEY_2>:
# - '*'

## @param ignore_tags - list of strings - optional
## A list of tags to ignore, the "*" wildcard can be used to match multiple tag strings.
#
# ignore_tags:
# - <FULL:TAG>
# - <TAG_PREFIX*>
# - <*TAG_SUFFIX>
# - <*SUBSTRING*>

## @param proxy - mapping - optional
## This overrides the `proxy` setting in `init_config`.
##
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,15 @@ instances:
# <KEY_2>:
# - '*'

## @param ignore_tags - list of strings - optional
## A list of tags to ignore, the "*" wildcard can be used to match multiple tag strings.
#
# ignore_tags:
# - <FULL:TAG>
# - <TAG_PREFIX*>
# - <*TAG_SUFFIX>
# - <*SUBSTRING*>

## @param proxy - mapping - optional
## This overrides the `proxy` setting in `init_config`.
##
Expand Down
9 changes: 9 additions & 0 deletions haproxy/datadog_checks/haproxy/data/conf.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,15 @@ instances:
# <KEY_2>:
# - '*'

## @param ignore_tags - list of strings - optional
## A list of tags to ignore, the "*" wildcard can be used to match multiple tag strings.
#
# ignore_tags:
# - <FULL:TAG>
# - <TAG_PREFIX*>
# - <*TAG_SUFFIX>
# - <*SUBSTRING*>

## @param proxy - mapping - optional
## This overrides the `proxy` setting in `init_config`.
##
Expand Down
9 changes: 9 additions & 0 deletions istio/datadog_checks/istio/data/conf.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,15 @@ instances:
# <KEY_2>:
# - '*'

## @param ignore_tags - list of strings - optional
## A list of tags to ignore, the "*" wildcard can be used to match multiple tag strings.
#
# ignore_tags:
# - <FULL:TAG>
# - <TAG_PREFIX*>
# - <*TAG_SUFFIX>
# - <*SUBSTRING*>

## @param proxy - mapping - optional
## This overrides the `proxy` setting in `init_config`.
##
Expand Down
9 changes: 9 additions & 0 deletions kong/datadog_checks/kong/data/conf.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,15 @@ instances:
#
# telemetry: false

## @param ignore_tags - list of strings - optional
## A list of tags to ignore, the "*" wildcard can be used to match multiple tag strings.
#
# ignore_tags:
# - <FULL:TAG>
# - <TAG_PREFIX*>
# - <*TAG_SUFFIX>
# - <*SUBSTRING*>

## @param proxy - mapping - optional
## This overrides the `proxy` setting in `init_config`.
##
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,15 @@ instances:
# <KEY_2>:
# - '*'

## @param ignore_tags - list of strings - optional
## A list of tags to ignore, the "*" wildcard can be used to match multiple tag strings.
#
# ignore_tags:
# - <FULL:TAG>
# - <TAG_PREFIX*>
# - <*TAG_SUFFIX>
# - <*SUBSTRING*>

## @param proxy - mapping - optional
## This overrides the `proxy` setting in `init_config`.
##
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,15 @@ instances:
# <KEY_2>:
# - '*'

## @param ignore_tags - list of strings - optional
## A list of tags to ignore, the "*" wildcard can be used to match multiple tag strings.
#
# ignore_tags:
# - <FULL:TAG>
# - <TAG_PREFIX*>
# - <*TAG_SUFFIX>
# - <*SUBSTRING*>

## @param proxy - mapping - optional
## This overrides the `proxy` setting in `init_config`.
##
Expand Down
9 changes: 9 additions & 0 deletions linkerd/datadog_checks/linkerd/data/conf.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,15 @@ instances:
# <KEY_2>:
# - '*'

## @param ignore_tags - list of strings - optional
## A list of tags to ignore, the "*" wildcard can be used to match multiple tag strings.
#
# ignore_tags:
# - <FULL:TAG>
# - <TAG_PREFIX*>
# - <*TAG_SUFFIX>
# - <*SUBSTRING*>

## @param proxy - mapping - optional
## This overrides the `proxy` setting in `init_config`.
##
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,15 @@ instances:
# <KEY_2>:
# - '*'

## @param ignore_tags - list of strings - optional
## A list of tags to ignore, the "*" wildcard can be used to match multiple tag strings.
#
# ignore_tags:
# - <FULL:TAG>
# - <TAG_PREFIX*>
# - <*TAG_SUFFIX>
# - <*SUBSTRING*>

## @param proxy - mapping - optional
## This overrides the `proxy` setting in `init_config`.
##
Expand Down
Loading

0 comments on commit c1e59a9

Please sign in to comment.