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

Fix retry parsing when metric has multiple metric parts #9189

Merged
merged 5 commits into from
Apr 20, 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
5 changes: 5 additions & 0 deletions envoy/datadog_checks/envoy/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,14 @@ def parse_metric(metric, retry=False, metric_mapping=METRIC_TREE):
parsed_metric = '.'.join(metric_parts)
if parsed_metric not in METRICS:
if retry:
skip_parts = []
# Retry parsing for metrics by skipping the last matched metric part
while len(metric_parts) > 1:
skip_part = metric_parts.pop()
if skip_part in skip_parts:
raise UnknownMetric
else:
skip_parts.append(skip_part)
(
metric_parts,
tag_value_builder,
Expand Down
2 changes: 1 addition & 1 deletion envoy/tests/docker/default/front-envoy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ static_resources:
type: LOGICAL_DNS
lb_policy: ROUND_ROBIN
load_assignment:
cluster_name: xds_cluster
cluster_name: service-xdr.default.eu-west-3-stg.internal.abcd.consul
endpoints:
- lb_endpoints:
- endpoint:
Expand Down
6 changes: 5 additions & 1 deletion envoy/tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ def test_retry_metric():

def test_retry_invalid_metric():
with pytest.raises(UnknownMetric):
parse_metric("cluster.internal.foo", retry=True)
parse_metric(
"cluster.ms-catalog-category-appli.default.eu-west-3-stg.internal"
".ba3374ca-fb2a-3f3e-9ea6-79e021188673.consul.http2.dropped_headers_with_underscores",
retry=True,
)


def test_http_router_filter():
Expand Down