diff --git a/scripts/compare_metrics.py b/scripts/compare_metrics.py index 98f0af80bd6..8869f1826c6 100644 --- a/scripts/compare_metrics.py +++ b/scripts/compare_metrics.py @@ -6,7 +6,6 @@ import json -# Load the JSON files v1_metrics_path = "./V1_Metrics.json" v2_metrics_path = "./V2_Metrics.json" @@ -17,18 +16,22 @@ v2_metrics = json.load(file) # Extract names and labels of the metrics -def extract_metrics_with_labels(metrics): +def extract_metrics_with_labels(metrics, strip_prefix=None): result = {} for metric in metrics: name = metric['name'] + if strip_prefix and name.startswith(strip_prefix): + name = name[len(strip_prefix):] labels = {} if 'metrics' in metric and 'labels' in metric['metrics'][0]: labels = metric['metrics'][0]['labels'] result[name] = labels return result + v1_metrics_with_labels = extract_metrics_with_labels(v1_metrics) -v2_metrics_with_labels = extract_metrics_with_labels(v2_metrics) +v2_metrics_with_labels = extract_metrics_with_labels( + v2_metrics, strip_prefix="otelcol_") # Compare the metrics names and labels common_metrics = {} @@ -37,10 +40,7 @@ def extract_metrics_with_labels(metrics): for name, labels in v1_metrics_with_labels.items(): if name in v2_metrics_with_labels: - if labels == v2_metrics_with_labels[name]: - common_metrics[name] = labels - else: - v1_only_metrics[name] = labels + common_metrics[name] = labels else: v1_only_metrics[name] = labels @@ -54,9 +54,8 @@ def extract_metrics_with_labels(metrics): "v2_only_metrics": v2_only_metrics } -# Write the differences to a new JSON file differences_path = "./differences.json" with open(differences_path, 'w') as file: json.dump(differences, file, indent=4) -print(f"Differences written to {differences_path}") \ No newline at end of file +print(f"Differences written to {differences_path}")