-
Notifications
You must be signed in to change notification settings - Fork 2.9k
fix: improve metrics comparison CI readability #8341
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
Changes from all commits
4ed916d
5062b64
abc5eab
2a74cfc
8baaccc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -111,7 +111,7 @@ def parse_metrics(content): | |
| return metrics,metrics_exclusion_count | ||
|
|
||
|
|
||
| def generate_diff(file1_content, file2_content): | ||
| def generate_diff(baseline_content, current_content): | ||
| """Compare two Prometheus metrics snapshots and return a unified diff of metric names. | ||
|
|
||
| The input files are raw Prometheus text exposition format, scraped directly from | ||
|
|
@@ -132,21 +132,26 @@ def generate_diff(file1_content, file2_content): | |
| The diff is performed on these sorted, value-free metric strings. If the two | ||
| snapshots produce the same set of strings the diff is empty and this function | ||
| returns ''. When there are differences, the return value is a unified diff | ||
| using the standard convention: | ||
| - lines = present in baseline but absent from current → regression/removed | ||
| + lines = present in current but absent from baseline → newly added | ||
| followed by optional comment lines reporting how many metrics were excluded, e.g.: | ||
| # Metrics excluded from A: 3 | ||
| # Metrics excluded from B: 5 | ||
| # Metrics excluded from baseline: 3 | ||
| # Metrics excluded from current: 5 | ||
| These comment lines (prefixed with `# `) are appended only when the diff is | ||
| non-empty; they are informational context, not metric differences themselves. | ||
| """ | ||
| if isinstance(file1_content, list): | ||
| file1_content = ''.join(file1_content) | ||
| if isinstance(file2_content, list): | ||
| file2_content = ''.join(file2_content) | ||
| if isinstance(baseline_content, list): | ||
| baseline_content = ''.join(baseline_content) | ||
| if isinstance(current_content, list): | ||
| current_content = ''.join(current_content) | ||
|
|
||
| metrics1,excluded_metrics_count1 = parse_metrics(file1_content) | ||
| metrics2,excluded_metrics_count2 = parse_metrics(file2_content) | ||
| baseline_metrics, excluded_count_baseline = parse_metrics(baseline_content) | ||
| current_metrics, excluded_count_current = parse_metrics(current_content) | ||
|
|
||
| diff = list(unified_diff(metrics1, metrics2, lineterm='', n=0)) | ||
| # unified_diff(baseline, current): - = in baseline but not current (removed/regression), | ||
| # + = in current but not baseline (newly added). | ||
| diff = list(unified_diff(baseline_metrics, current_metrics, lineterm='', n=0)) | ||
|
|
||
| # Exclusion counts are informational context appended to the diff output. | ||
| # They must not be written when the diff itself is empty: two snapshots with | ||
|
|
@@ -155,12 +160,12 @@ def generate_diff(file1_content, file2_content): | |
| if len(diff) == 0: | ||
| return '' | ||
|
|
||
| total_excluded = excluded_metrics_count1 + excluded_metrics_count2 | ||
| total_excluded = excluded_count_baseline + excluded_count_current | ||
|
|
||
| exclusion_lines = '' | ||
| if total_excluded > 0: | ||
| exclusion_lines = f'\n# Metrics excluded from A: {excluded_metrics_count1}\n# Metrics excluded from B: {excluded_metrics_count2}' | ||
| exclusion_lines = f'\n# Metrics excluded from baseline: {excluded_count_baseline}\n# Metrics excluded from current: {excluded_count_current}' | ||
|
|
||
| return '\n'.join(diff) + exclusion_lines | ||
|
|
||
| def write_diff_file(diff_lines, output_path): | ||
|
|
@@ -172,20 +177,20 @@ def write_diff_file(diff_lines, output_path): | |
|
|
||
| def main(): | ||
| parser = argparse.ArgumentParser(description='Generate diff between two Jaeger metric files') | ||
| parser.add_argument('--file1', help='Path to first metric file') | ||
| parser.add_argument('--file2', help='Path to second metric file') | ||
| parser.add_argument('--current', help='Path to the current metric file (e.g. from the PR)') | ||
| parser.add_argument('--baseline', help='Path to the baseline metric file (e.g. from main branch)') | ||
| parser.add_argument('--output', '-o', default='metrics_diff.txt', | ||
| help='Output diff file path (default: metrics_diff.txt)') | ||
|
|
||
| args = parser.parse_args() | ||
|
|
||
| # Read input files | ||
| file1_lines = read_metric_file(args.file1) | ||
| file2_lines = read_metric_file(args.file2) | ||
| baseline_lines = read_metric_file(args.baseline) | ||
| current_lines = read_metric_file(args.current) | ||
|
|
||
|
Comment on lines
179
to
+190
|
||
| # Generate diff | ||
| diff_lines = generate_diff(file1_lines, file2_lines) | ||
| diff_lines = generate_diff(baseline_lines, current_lines) | ||
|
|
||
| # Check if there are any differences | ||
| if diff_lines: | ||
| print("differences found between the metric files.") | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The inline comment says artifact_id is a “non-negative integer”, but the code requires
artifact_id > 0(and the following comment notes GitHub IDs are always > 0). Update the comment to match the actual validation (positive integer) to avoid confusion during future security reviews.