Skip to content

Commit 47ddfe5

Browse files
[ci] Sanitize transient metric labels before comparison (#7482)
## Which problem is this PR solving? - Fixes #7475 ## Description of the changes - Implemented an extensible transient label suppression system that normalizes known volatile labels before metric comparison: Kafka topics: jaeger-spans-\d+ → jaeger-spans- Configurable patterns: Easy to add new transient label types in the future ``` TRANSIENT_LABEL_PATTERNS = { # Main key: service/component identifier 'kafka': { # ← service (Level 1) # Nested key: specific label name within that service 'topic': { # ← label (Level 2) # Configuration values 'pattern': r'jaeger-spans-\d+', # ← Pattern to match 'replacement': 'jaeger-spans-' # ← Replacement value } } } ``` ## How was this change tested? - Local scripts + test data - CI did not generate metric change with this change. ## Checklist - [ ] I have read https://github.com/jaegertracing/jaeger/blob/master/CONTRIBUTING_GUIDELINES.md - [ ] I have signed all commits - [ ] I have added unit tests for the new functionality - [ ] I have run lint and test steps successfully - for `jaeger`: `make lint test` - for `jaeger-ui`: `npm run lint` and `npm run test` --------- Signed-off-by: Harshil Gupta <[email protected]>
1 parent 53326dd commit 47ddfe5

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

scripts/e2e/compare_metrics.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,48 @@
66
from difflib import unified_diff
77
from bisect import insort
88
from prometheus_client.parser import text_string_to_metric_families
9+
import re
10+
11+
# Configuration for transient labels that should be normalized during comparison
12+
TRANSIENT_LABEL_PATTERNS = {
13+
'kafka': {
14+
'topic': {
15+
'pattern': r'jaeger-spans-\d+',
16+
'replacement': 'jaeger-spans-'
17+
}
18+
},
19+
# Add more patterns here as needed
20+
# Example:
21+
# 'elasticsearch': {
22+
# 'index': {
23+
# 'pattern': r'jaeger-\d{4}-\d{2}-\d{2}',
24+
# 'replacement': 'jaeger-YYYY-MM-DD'
25+
# }
26+
# }
27+
}
28+
29+
def suppress_transient_labels(metric_name, labels):
30+
"""
31+
Suppresses transient labels in metrics based on configured patterns.
32+
33+
Args:
34+
metric_name: The name of the metric
35+
labels: Dictionary of labels for the metric
36+
37+
Returns:
38+
Dictionary of labels with transient values normalized
39+
"""
40+
labels_copy = labels.copy()
41+
42+
for service_pattern, label_configs in TRANSIENT_LABEL_PATTERNS.items():
43+
if service_pattern in metric_name:
44+
for label_name, pattern_config in label_configs.items():
45+
if label_name in labels_copy:
46+
pattern = pattern_config['pattern']
47+
replacement = pattern_config['replacement']
48+
labels_copy[label_name] = re.sub(pattern, replacement, labels_copy[label_name])
49+
50+
return labels_copy
951

1052
def read_metric_file(file_path):
1153
with open(file_path, 'r') as f:
@@ -18,6 +60,9 @@ def parse_metrics(content):
1860
labels = dict(sample.labels)
1961
#simply pop undesirable metric labels
2062
labels.pop('service_instance_id',None)
63+
64+
labels = suppress_transient_labels(sample.name, labels)
65+
2166
label_pairs = sorted(labels.items(), key=lambda x: x[0])
2267
label_str = ','.join(f'{k}="{v}"' for k,v in label_pairs)
2368
metric = f"{family.name}{{{label_str}}}"

0 commit comments

Comments
 (0)