Skip to content

Commit 6afc753

Browse files
committed
chore: exclusion of flaky 5xx metrics added
Signed-off-by: Tushar Anand <[email protected]>
1 parent fbf3ccc commit 6afc753

File tree

1 file changed

+40
-2
lines changed

1 file changed

+40
-2
lines changed

scripts/e2e/compare_metrics.py

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,41 @@
2626
# }
2727
}
2828

29+
METRIC_EXCLUSION_RULES = {
30+
# excluding HTTP 5xx responses as these can be flaky
31+
'http_5xx_errors': {
32+
'condition': 'label_match',
33+
'label': 'http_response_status_code',
34+
'pattern': r'^5\d{2}$',
35+
},
36+
37+
}
38+
39+
40+
def should_exclude_metric(metric_name, labels):
41+
"""
42+
Determines if a metric should be excluded from comparison based on configured rules.
43+
44+
Args:
45+
metric_name: The name of the metric
46+
labels: Dictionary of labels for the metric
47+
48+
Returns:
49+
tuple: (should_exclude: bool, reason: str or None)
50+
"""
51+
for rule_name, rule_config in METRIC_EXCLUSION_RULES.items():
52+
condition = rule_config['condition']
53+
54+
if condition == 'label_match':
55+
label = rule_config['label']
56+
pattern = rule_config['pattern']
57+
if label in labels and re.match(pattern, labels[label]):
58+
return True
59+
60+
61+
return False, None
62+
63+
2964
def suppress_transient_labels(metric_name, labels):
3065
"""
3166
Suppresses transient labels in metrics based on configured patterns.
@@ -58,9 +93,12 @@ def parse_metrics(content):
5893
for family in text_string_to_metric_families(content):
5994
for sample in family.samples:
6095
labels = dict(sample.labels)
61-
#simply pop undesirable metric labels
62-
labels.pop('service_instance_id',None)
6396

97+
should_exclude= should_exclude_metric(sample.name, labels)
98+
if should_exclude:
99+
continue
100+
101+
labels.pop('service_instance_id', None)
64102
labels = suppress_transient_labels(sample.name, labels)
65103

66104
label_pairs = sorted(labels.items(), key=lambda x: x[0])

0 commit comments

Comments
 (0)