Skip to content
Merged
Changes from 2 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
42 changes: 40 additions & 2 deletions scripts/e2e/compare_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,41 @@
# }
}

METRIC_EXCLUSION_RULES = {
# excluding HTTP 5xx responses as these can be flaky
'http_5xx_errors': {
'condition': 'label_match',
'label': 'http_response_status_code',
'pattern': r'^5\d{2}$',
},

}


def should_exclude_metric(metric_name, labels):
"""
Determines if a metric should be excluded from comparison based on configured rules.

Args:
metric_name: The name of the metric
labels: Dictionary of labels for the metric

Returns:
tuple: (should_exclude: bool, reason: str or None)
"""
for rule_name, rule_config in METRIC_EXCLUSION_RULES.items():
condition = rule_config['condition']

if condition == 'label_match':
label = rule_config['label']
pattern = rule_config['pattern']
if label in labels and re.match(pattern, labels[label]):
return True


return False


def suppress_transient_labels(metric_name, labels):
"""
Suppresses transient labels in metrics based on configured patterns.
Expand Down Expand Up @@ -58,9 +93,12 @@ def parse_metrics(content):
for family in text_string_to_metric_families(content):
for sample in family.samples:
labels = dict(sample.labels)
#simply pop undesirable metric labels
labels.pop('service_instance_id',None)

should_exclude= should_exclude_metric(sample.name, labels)
if should_exclude:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
should_exclude= should_exclude_metric(sample.name, labels)
if should_exclude:
if should_exclude_metric(sample.name, labels):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it would be good to count these exclusions in stats

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it would be good to count these exclusions in stats

Like the ones posted in PR, if some stats are excluded?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes (although I am not sure excluding full metrics is a good thing, per the other comment).

continue

labels.pop('service_instance_id', None)
labels = suppress_transient_labels(sample.name, labels)

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