-
Notifications
You must be signed in to change notification settings - Fork 2.6k
[ci] Scrape and verify metrics at the end of e2e tests #6330
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
Merged
Merged
Changes from all commits
Commits
Show all changes
63 commits
Select commit
Hold shift + click to select a range
9e51b06
script to scrape metrics
chahatsagarmain cf2ee87
minor change
chahatsagarmain 3472d1e
fix dir path
chahatsagarmain 1c12682
add metric upload to each test and changes in the scrape script
chahatsagarmain d5ae8f5
minor changes
chahatsagarmain 5170c8e
changes
chahatsagarmain a3d3252
shell lint
chahatsagarmain b0ef4d4
minor changes
chahatsagarmain 2244ea9
reviewed changes
chahatsagarmain 283bc5c
added cache save
chahatsagarmain 0152cb2
Merge branch 'main' into e2e-metrics
chahatsagarmain 6adf944
fixes
chahatsagarmain c6703b6
add schema in key
chahatsagarmain adbe80f
test ci
chahatsagarmain d46316b
test ci
chahatsagarmain 0da4dbb
minor changes
chahatsagarmain a479e7f
test ci with fixed expression
chahatsagarmain 519104e
shared action and a happy new yar
chahatsagarmain 23ba35f
minor fixes
chahatsagarmain b620f09
shared action
chahatsagarmain 15c775b
Merge branch 'main' into e2e-metrics
chahatsagarmain 07fdbec
add shell property
chahatsagarmain 7f3fe77
compare metrics
chahatsagarmain 8c81c82
fix path
chahatsagarmain a76bcde
fix compare
chahatsagarmain 2b27c95
minor changes
chahatsagarmain 77ed741
compare metrics using python libraries
chahatsagarmain 22e97a2
check path
chahatsagarmain 8da8a07
resolved comments
chahatsagarmain 90464e2
use simple unified diff
chahatsagarmain 19835c4
exit cases
chahatsagarmain 63a64f3
simplified action
chahatsagarmain 0a1787f
exit case
chahatsagarmain b30dad5
fetch tags after checkout
chahatsagarmain d81694e
changes
chahatsagarmain 6f5355c
exit code
chahatsagarmain 1bdb77f
print diff
chahatsagarmain 157822d
minor changes
chahatsagarmain 2ea739b
added comment
chahatsagarmain 20514ab
test
chahatsagarmain 8d92555
fetch depth 0
chahatsagarmain a7f2b67
changes
chahatsagarmain 1b16c35
Merge branch 'main' into e2e-metrics
chahatsagarmain ef56c4e
Merge branch 'main' into e2e-metrics
chahatsagarmain b93d66d
cummulative diff
chahatsagarmain e51bb3e
Merge branch 'e2e-metrics' of https://github.com/chahatsagarmain/jaeg…
chahatsagarmain 41693c5
minor changes
chahatsagarmain 4ffb260
use restore key
chahatsagarmain f1dc438
Merge branch 'main' into e2e-metrics
chahatsagarmain 1249fdc
resolved changes
chahatsagarmain 6cb60ef
Merge branch 'e2e-metrics' of https://github.com/chahatsagarmain/jaeg…
chahatsagarmain 98968eb
fix
chahatsagarmain e43b1e3
fix
chahatsagarmain af10a81
change save path
chahatsagarmain 5c8dfec
Merge branch 'main' into e2e-metrics
chahatsagarmain b29098a
fix restore keys
chahatsagarmain 1accdfd
Merge branch 'e2e-metrics' of https://github.com/chahatsagarmain/jaeg…
chahatsagarmain 5e2eac1
minor change in name
chahatsagarmain b6bd4c0
remove txt
chahatsagarmain 9dad779
minor changes
chahatsagarmain be73e93
Update .github/workflows/ci-e2e-badger.yaml
yurishkuro f3b63e9
Update .github/actions/verify-metrics-snapshot/action.yaml
yurishkuro 9d232bb
Merge branch 'main' into e2e-metrics
yurishkuro File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# Copyright (c) 2023 The Jaeger Authors. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
name: 'Verify Metric Snapshot and Upload Metrics' | ||
description: 'Upload or cache the metrics data after verification' | ||
inputs: | ||
snapshot: | ||
description: 'Path to the metric file' | ||
required: true | ||
artifact_key: | ||
description: 'Artifact key used for uploading and fetching artifacts' | ||
required: true | ||
runs: | ||
using: 'composite' | ||
steps: | ||
- name: Upload current metrics snapshot | ||
uses: actions/upload-artifact@6f51ac03b9356f520e9adb1b1b7802705f340c2b # v4.5.0 | ||
with: | ||
name: ${{ inputs.artifact_key }} | ||
path: ./.metrics/${{ inputs.snapshot }}.txt | ||
retention-days: 7 | ||
|
||
# The github cache restore successfully restores when cache saved has same key and same path. | ||
# Hence to restore release metric with name relese_{metric_name} , the name must be changed to the same. | ||
- name: Change file name before caching | ||
if: github.ref_name == 'main' | ||
shell: bash | ||
run: | | ||
mv ./.metrics/${{ inputs.snapshot }}.txt ./.metrics/baseline_${{ inputs.snapshot }}.txt | ||
|
||
- name: Cache metrics snapshot on main branch for longer retention | ||
if: github.ref_name == 'main' | ||
uses: actions/cache/save@1bd1e32a3bdc45362d1e726936510720a7c30a57 | ||
with: | ||
path: ./.metrics/baseline_${{ inputs.snapshot }}.txt | ||
key: ${{ inputs.artifact_key }}_${{ github.run_id }} | ||
|
||
# Use restore keys to match prefix and fetch the latest cache | ||
# Here , restore keys is an ordered list of prefixes that need to be matched | ||
- name: Download the cached tagged metrics | ||
id: download-release-snapshot | ||
if: github.ref_name != 'main' | ||
uses: actions/cache/restore@1bd1e32a3bdc45362d1e726936510720a7c30a57 | ||
with: | ||
path: ./.metrics/baseline_${{ inputs.snapshot }}.txt | ||
key: ${{ inputs.artifact_key }} | ||
restore-keys: | | ||
${{ inputs.artifact_key }} | ||
|
||
- name: Calculate diff between the snapshots | ||
id: compare-snapshots | ||
if: ${{ (github.ref_name != 'main') && (steps.download-release-snapshot.outputs.cache-matched-key != '') }} | ||
shell: bash | ||
run: | | ||
python3 -m pip install prometheus-client | ||
python3 ./scripts/e2e/compare_metrics.py --file1 ./.metrics/${{ inputs.snapshot }}.txt --file2 ./.metrics/baseline_${{ inputs.snapshot }}.txt --output ./.metrics/diff_${{ inputs.snapshot }}.txt | ||
if [ $? -eq 1 ]; then | ||
echo "🛑 Differences found in metrics" | ||
exit 1 | ||
yurishkuro marked this conversation as resolved.
Show resolved
Hide resolved
|
||
fi | ||
|
||
- name: Upload the diff artifact | ||
if: ${{ (github.ref_name != 'main') && (steps.compare-snapshots.outcome == 'failure') }} | ||
uses: actions/upload-artifact@6f51ac03b9356f520e9adb1b1b7802705f340c2b # v4.5.0 | ||
with: | ||
name: diff_${{ inputs.artifact_key }} | ||
path: ./.metrics/diff_${{ inputs.snapshot }}.txt | ||
retention-days: 7 | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,3 +50,4 @@ sha256sum.combined.txt | |
resource.syso | ||
.gocache | ||
test-results.json | ||
.metrics/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# Copyright (c) 2024 The Jaeger Authors. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
import argparse | ||
from difflib import unified_diff | ||
from bisect import insort | ||
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_metrics(content): | ||
metrics = [] | ||
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) | ||
label_pairs = sorted(labels.items(), key=lambda x: x[0]) | ||
label_str = ','.join(f'{k}="{v}"' for k,v in label_pairs) | ||
metric = f"{family.name}{{{label_str}}}" | ||
insort(metrics , metric) | ||
|
||
return metrics | ||
|
||
|
||
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) | ||
|
||
metrics1 = parse_metrics(file1_content) | ||
metrics2 = parse_metrics(file2_content) | ||
|
||
diff = unified_diff(metrics1, metrics2,lineterm='',n=0) | ||
|
||
return '\n'.join(diff) | ||
|
||
def write_diff_file(diff_lines, output_path): | ||
|
||
with open(output_path, 'w') as f: | ||
f.write(diff_lines) | ||
f.write('\n') # Add final newline | ||
print(f"Diff file successfully written to: {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('--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) | ||
|
||
# Generate diff | ||
diff_lines = generate_diff(file1_lines, file2_lines) | ||
|
||
# Check if there are any differences | ||
if diff_lines: | ||
print("differences found between the metric files.") | ||
print("=== Metrics Comparison Results ===") | ||
print(diff_lines) | ||
write_diff_file(diff_lines, args.output) | ||
|
||
return 1 | ||
|
||
print("no difference found") | ||
return 0 | ||
|
||
if __name__ == '__main__': | ||
main() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.