Skip to content
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

E2e run #3

Open
wants to merge 46 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
9e51b06
script to scrape metrics
chahatsagarmain Dec 9, 2024
cf2ee87
minor change
chahatsagarmain Dec 9, 2024
3472d1e
fix dir path
chahatsagarmain Dec 9, 2024
1c12682
add metric upload to each test and changes in the scrape script
chahatsagarmain Dec 9, 2024
d5ae8f5
minor changes
chahatsagarmain Dec 11, 2024
5170c8e
changes
chahatsagarmain Dec 13, 2024
a3d3252
shell lint
chahatsagarmain Dec 13, 2024
b0ef4d4
minor changes
chahatsagarmain Dec 14, 2024
2244ea9
reviewed changes
chahatsagarmain Dec 15, 2024
283bc5c
added cache save
chahatsagarmain Dec 28, 2024
0152cb2
Merge branch 'main' into e2e-metrics
chahatsagarmain Dec 28, 2024
6adf944
fixes
chahatsagarmain Dec 28, 2024
c6703b6
add schema in key
chahatsagarmain Dec 28, 2024
adbe80f
test ci
chahatsagarmain Dec 28, 2024
d46316b
test ci
chahatsagarmain Dec 29, 2024
0da4dbb
minor changes
chahatsagarmain Dec 29, 2024
a479e7f
test ci with fixed expression
chahatsagarmain Dec 29, 2024
519104e
shared action and a happy new yar
chahatsagarmain Jan 1, 2025
23ba35f
minor fixes
chahatsagarmain Jan 1, 2025
b620f09
shared action
chahatsagarmain Jan 2, 2025
15c775b
Merge branch 'main' into e2e-metrics
chahatsagarmain Jan 2, 2025
07fdbec
add shell property
chahatsagarmain Jan 2, 2025
7f3fe77
compare metrics
chahatsagarmain Jan 3, 2025
8c81c82
fix path
chahatsagarmain Jan 3, 2025
a76bcde
fix compare
chahatsagarmain Jan 3, 2025
2b27c95
minor changes
chahatsagarmain Jan 3, 2025
77ed741
compare metrics using python libraries
chahatsagarmain Jan 4, 2025
22e97a2
check path
chahatsagarmain Jan 4, 2025
8da8a07
resolved comments
chahatsagarmain Jan 4, 2025
90464e2
use simple unified diff
chahatsagarmain Jan 4, 2025
19835c4
exit cases
chahatsagarmain Jan 4, 2025
63a64f3
simplified action
chahatsagarmain Jan 4, 2025
0a1787f
exit case
chahatsagarmain Jan 4, 2025
b30dad5
fetch tags after checkout
chahatsagarmain Jan 4, 2025
bbd4ebc
test workflow
chahatsagarmain Jan 5, 2025
e031693
test
chahatsagarmain Jan 5, 2025
908eb87
Merge branch 'main' of https://github.com/chahatsagarmain/jaeger into…
chahatsagarmain Jan 5, 2025
4955217
cache fix
chahatsagarmain Jan 5, 2025
bffd30d
test ci
chahatsagarmain Jan 5, 2025
84c5413
test ci 2
chahatsagarmain Jan 5, 2025
d650440
debug
chahatsagarmain Jan 5, 2025
37e0af1
test ci 3
chahatsagarmain Jan 5, 2025
6f64848
e2e_run
chahatsagarmain Jan 5, 2025
7e1b423
e2e_run 2
chahatsagarmain Jan 5, 2025
a79d63b
test
chahatsagarmain Jan 5, 2025
83b5a41
main chache
chahatsagarmain Jan 5, 2025
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
Prev Previous commit
Next Next commit
compare metrics using python libraries
Signed-off-by: chahatsagarmain <[email protected]>
  • Loading branch information
chahatsagarmain committed Jan 4, 2025
commit 77ed7412d4766c42c318e81b53ab998b669972e2
1 change: 1 addition & 0 deletions .github/actions/verify-metrics-snapshot/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ runs:
- name: Calculate diff between the snapshots
shell: bash
run: |
python3 -m pip install prometheus-client deepdiff
python3 ./scripts/e2e/compare_metrics.py --file1 ./.metrics/${{ inputs.snapshot }} --file2 ./.metrics/cached_${{ inputs.snapshot}} --output ./.metrics/diff_${{ inputs.snapshot }}

- name: Upload the diff artifact
Expand Down
100 changes: 32 additions & 68 deletions scripts/e2e/compare_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,78 +2,48 @@
# SPDX-License-Identifier: Apache-2.0

import argparse
import re
import sys
import json
import deepdiff
from pathlib import Path
from prometheus_client.parser import text_string_to_metric_families

def read_metric_file(file_path):
with open(file_path, 'r') as f:
return f.readlines()

def parse_metric_line(line):

# Skip empty lines or comments
line = line.strip()
if not line or line.startswith('#'):
return None

# Extract metric name and labels section
match = re.match(r'([^{]+)(?:{(.+)})?(?:\s+[-+]?[0-9.eE+-]+)?$', line)
if not match:
return None

name = match.group(1)
labels_str = match.group(2) or ''

# Parse labels into a frozenset of (key, value) tuples
labels = []
if labels_str:
for label in labels_str.split(','):
label = label.strip()
if '=' in label:
key, value = label.split('=', 1)
labels.append((key.strip(), value.strip()))

# Sort labels and convert to frozenset for comparison
return (name, frozenset(sorted(labels)))
def parse_metrics(content):
metrics = {}
for family in text_string_to_metric_families(content):
for sample in family.samples:
key = (family.name, frozenset(sorted(sample.labels.items())))
metrics[key] = {
'name': family.name,
'labels': dict(sample.labels),
}
return metrics

def generate_diff(file1_lines, file2_lines, file1_name, file2_name):
def generate_diff(file1_content, file2_content):
if isinstance(file1_content, list):
file1_content = ''.join(file1_content)
if isinstance(file2_content, list):
file2_content = ''.join(file2_content)

# Parse metrics from both files
metrics1 = {} # {(name, labels_frozenset): original_line}
metrics2 = {}

for line in file1_lines:
parsed = parse_metric_line(line)
if parsed:
metrics1[parsed] = line.strip()

for line in file2_lines:
parsed = parse_metric_line(line)
if parsed:
metrics2[parsed] = line.strip()

# Generate diff
diff_lines = []
diff_lines.append(f'--- {file1_name}')
diff_lines.append(f'+++ {file2_name}')

# Find metrics unique to file1 (removed metrics)
for metric in sorted(set(metrics1.keys()) - set(metrics2.keys())):
name, labels = metric
diff_lines.append(f'-{metrics1[metric]}')

# Find metrics unique to file2 (added metrics)
for metric in sorted(set(metrics2.keys()) - set(metrics1.keys())):
name, labels = metric
diff_lines.append(f'+{metrics2[metric]}')

return diff_lines
metrics1 = parse_metrics(file1_content)
metrics2 = parse_metrics(file2_content)

# Compare metrics ignoring values
diff = deepdiff.DeepDiff(metrics1, metrics2,ignore_order=True,exclude_paths=["root['value']"])
diff_dict = diff.to_dict()
diff_dict['metrics_in_tagged_only'] = diff_dict.pop('dictionary_item_added')
diff_dict['metrics_in_current_only'] = diff_dict.pop('dictionary_item_removed')
diff_json = json.dumps(diff_dict,indent=4,default=tuple,sort_keys=True)
return diff_json

def write_diff_file(diff_lines, output_path):

with open(output_path, 'w') as f:
f.write('\n'.join(diff_lines))
f.write(diff_lines)
f.write('\n') # Add final newline
print(f"Diff file successfully written to: {output_path}")

Expand All @@ -86,19 +56,13 @@ def main():

args = parser.parse_args()

# Convert paths to absolute paths
file1_path = Path(args.file1).absolute()
file2_path = Path(args.file2).absolute()
output_path = Path(args.output).absolute()
file1_path = Path(args.file1)
file2_path = Path(args.file2)
output_path = Path(args.output)

# Read input files
file1_lines = read_metric_file(file1_path)
file2_lines = read_metric_file(file2_path)

# No cached file found
if not file1_lines or not file2_lines:
print("No cached file")
sys.exit(0)

# Generate diff
diff_lines = generate_diff(file1_lines, file2_lines, str(file1_path), str(file2_path))
Expand Down