Skip to content

Commit

Permalink
Add endpoint tag to legacy (DataDog#16478)
Browse files Browse the repository at this point in the history
* add endpoint tag to legacy

* changelog

* grammar nit

* lint

* lint
  • Loading branch information
steveny91 authored Dec 21, 2023
1 parent 7355f9e commit 1bf6702
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
1 change: 1 addition & 0 deletions envoy/changelog.d/16478.added
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add a `endpoint` tag to every metric in the legacy version of the check
2 changes: 2 additions & 0 deletions envoy/datadog_checks/envoy/envoy.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ def __init__(self, name, init_config, instances):
if self.stats_url is None:
raise ConfigurationError('Envoy configuration setting `stats_url` is required')

self.custom_tags.append("endpoint:{}".format(self.stats_url))

included_metrics = {
re.sub(r'^envoy\\?\.', '', s, 1)
for s in self.instance.get(
Expand Down
10 changes: 9 additions & 1 deletion envoy/tests/legacy/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,17 @@ def test_success(aggregator, check, dd_run_check):
if collected_metrics and collected_metrics[0].name not in UNIQUE_METRICS:
expected_tags = [t for t in METRICS[metric]['tags'] if t]
for tag_set in expected_tags:
# Iterate over the expected tags and check that they're present in the collected_metric's tags.
# We iterate over each collected metric and we see if the metric has more than 1 tag. If it does, we
# iterate over each tag attached to the metric to see if the tags are in the tag_set of expected_tags.
# Since an endpoint tag is added to each metric, checking for the metric specific tags parsed from the
# metric, should only be done if the metric has more tags than just the endpoint tag.
assert all(
all(any(tag in mt for mt in m.tags) for tag in tag_set) for m in collected_metrics if m.tags
all(any(tag in mt for mt in m.tags) for tag in tag_set)
for m in collected_metrics
if len(m.tags) > 1
), ('tags ' + str(expected_tags) + ' not found in ' + metric)

metrics_collected += len(collected_metrics)
assert metrics_collected >= 445

Expand Down
15 changes: 10 additions & 5 deletions envoy/tests/legacy/test_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,12 @@ def test_metadata_not_collected(datadog_agent, check):
@pytest.mark.parametrize(
('fixture_file', 'metrics', 'standard_tags', 'additional_tags'),
[
('./legacy/stat_prefix', EXT_METRICS, ['cluster_name:foo', 'envoy_cluster:foo'], ['stat_prefix:bar']),
(
'./legacy/stat_prefix',
EXT_METRICS,
['cluster_name:foo', 'envoy_cluster:foo'],
['stat_prefix:bar'],
),
(
'./legacy/rbac_metric.txt',
RBAC_METRICS,
Expand All @@ -269,7 +274,7 @@ def test_metadata_not_collected(datadog_agent, check):
"rbac_prefix_shadow",
],
)
def test_stats_prefix_ext_auth(
def test_stats_prefix_optional_tags(
aggregator,
fixture_path,
mock_http_response,
Expand All @@ -281,8 +286,8 @@ def test_stats_prefix_ext_auth(
additional_tags,
):
instance = INSTANCES['main']
tags = standard_tags
tags_prefix = tags + additional_tags
standard_tags.append('endpoint:{}'.format(instance["stats_url"]))
tags_prefix = standard_tags + additional_tags
c = check(instance)
mock_http_response(file_path=fixture_path(fixture_file)).return_value
dd_run_check(c)
Expand All @@ -296,7 +301,7 @@ def test_stats_prefix_ext_auth(
value=index + len(metrics),
tags=tags_prefix,
)
aggregator.assert_metric(metric, value=index, tags=tags)
aggregator.assert_metric(metric, value=index, tags=standard_tags)


def test_local_rate_limit_metrics(aggregator, fixture_path, mock_http_response, check, dd_run_check):
Expand Down

0 comments on commit 1bf6702

Please sign in to comment.