forked from jaegertracing/jaeger
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* script to scrape metrics Signed-off-by: chahatsagarmain <chahatsagar2003@gmail.com> * minor change Signed-off-by: chahatsagarmain <chahatsagar2003@gmail.com> * fix dir path Signed-off-by: chahatsagarmain <chahatsagar2003@gmail.com> * add metric upload to each test and changes in the scrape script Signed-off-by: chahatsagarmain <chahatsagar2003@gmail.com> * minor changes Signed-off-by: chahatsagarmain <chahatsagar2003@gmail.com> * changes Signed-off-by: chahatsagarmain <chahatsagar2003@gmail.com> * shell lint Signed-off-by: chahatsagarmain <chahatsagar2003@gmail.com> * minor changes Signed-off-by: chahatsagarmain <chahatsagar2003@gmail.com> * reviewed changes Signed-off-by: chahatsagarmain <chahatsagar2003@gmail.com> * added cache save Signed-off-by: chahatsagarmain <chahatsagar2003@gmail.com> * fixes Signed-off-by: chahatsagarmain <chahatsagar2003@gmail.com> * add schema in key Signed-off-by: chahatsagarmain <chahatsagar2003@gmail.com> * test ci Signed-off-by: chahatsagarmain <chahatsagar2003@gmail.com> * test ci Signed-off-by: chahatsagarmain <chahatsagar2003@gmail.com> * minor changes Signed-off-by: chahatsagarmain <chahatsagar2003@gmail.com> * test ci with fixed expression Signed-off-by: chahatsagarmain <chahatsagar2003@gmail.com> * shared action and a happy new yar Signed-off-by: chahatsagarmain <chahatsagar2003@gmail.com> * minor fixes Signed-off-by: chahatsagarmain <chahatsagar2003@gmail.com> * shared action Signed-off-by: chahatsagarmain <chahatsagar2003@gmail.com> * add shell property Signed-off-by: chahatsagarmain <chahatsagar2003@gmail.com> * compare metrics Signed-off-by: chahatsagarmain <chahatsagar2003@gmail.com> * fix path Signed-off-by: chahatsagarmain <chahatsagar2003@gmail.com> * fix compare Signed-off-by: chahatsagarmain <chahatsagar2003@gmail.com> * minor changes Signed-off-by: chahatsagarmain <chahatsagar2003@gmail.com> * compare metrics using python libraries Signed-off-by: chahatsagarmain <chahatsagar2003@gmail.com> * check path Signed-off-by: chahatsagarmain <chahatsagar2003@gmail.com> * resolved comments Signed-off-by: chahatsagarmain <chahatsagar2003@gmail.com> * use simple unified diff Signed-off-by: chahatsagarmain <chahatsagar2003@gmail.com> * exit cases Signed-off-by: chahatsagarmain <chahatsagar2003@gmail.com> * simplified action Signed-off-by: chahatsagarmain <chahatsagar2003@gmail.com> * exit case Signed-off-by: chahatsagarmain <chahatsagar2003@gmail.com> * fetch tags after checkout Signed-off-by: chahatsagarmain <chahatsagar2003@gmail.com> * test workflow Signed-off-by: chahatsagarmain <chahatsagar2003@gmail.com> * test Signed-off-by: chahatsagarmain <chahatsagar2003@gmail.com> * cache fix Signed-off-by: chahatsagarmain <chahatsagar2003@gmail.com> * test ci Signed-off-by: chahatsagarmain <chahatsagar2003@gmail.com> * test ci 2 Signed-off-by: chahatsagarmain <chahatsagar2003@gmail.com> * debug Signed-off-by: chahatsagarmain <chahatsagar2003@gmail.com> * test ci 3 Signed-off-by: chahatsagarmain <chahatsagar2003@gmail.com> * e2e_run Signed-off-by: chahatsagarmain <chahatsagar2003@gmail.com> * e2e_run 2 Signed-off-by: chahatsagarmain <chahatsagar2003@gmail.com> --------- Signed-off-by: chahatsagarmain <chahatsagar2003@gmail.com> Signed-off-by: chahat sagar <109112505+chahatsagarmain@users.noreply.github.com>
- Loading branch information
1 parent
7166159
commit 9325938
Showing
13 changed files
with
232 additions
and
9 deletions.
There are no files selected for viewing
This file contains 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,66 @@ | ||
# 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 | ||
cache_key: | ||
description: 'Cache key used for uploading and fetching the correct cached metric' | ||
required: true | ||
runs: | ||
using: 'composite' | ||
steps: | ||
- name: Upload Metrics Artifact | ||
uses: actions/upload-artifact@6f51ac03b9356f520e9adb1b1b7802705f340c2b # v4.5.0 | ||
with: | ||
name: ${{ inputs.artifact_key }} | ||
path: ./.metrics/${{ inputs.snapshot }} | ||
retention-days: 7 | ||
|
||
- name: Cache scraped metrics for tagged release for longer retention | ||
id: tagged-metrics | ||
if: contains(github.ref,'tags') | ||
uses: actions/cache/save@1bd1e32a3bdc45362d1e726936510720a7c30a57 | ||
with: | ||
path: ./.metrics/${{ inputs.snapshot }} | ||
key: ${{ github.ref_name }}_${{ inputs.artifact_key }} | ||
|
||
- name: Get v2 tag | ||
shell: bash | ||
run: | | ||
v2_tag=$(make echo-v2) | ||
echo "v2_tag=$v2_tag" >> $GITHUB_ENV | ||
echo "$v2_tag" | ||
- name: Download the cached tagged metrics | ||
id: cache-metrics | ||
uses: actions/cache/restore@1bd1e32a3bdc45362d1e726936510720a7c30a57 | ||
with: | ||
path: ./.metrics/cached_${{ inputs.snapshot}} | ||
key: ${{ env.v2_tag }}_${{ inputs.artifact_key }} | ||
|
||
- name: Calculate diff between the snapshots | ||
id: diff-check | ||
if: steps.cache-metrics.outputs.cache-hit == 'true' | ||
shell: bash | ||
run: | | ||
python3 -m pip install prometheus-client | ||
if ! python3 ./scripts/e2e/compare_metrics.py --file1 ./.metrics/${{ inputs.snapshot }} --file2 ./.metrics/cached_${{ inputs.snapshot}} --output ./.metrics/diff_${{ inputs.snapshot }}; then | ||
exit 1 | ||
fi | ||
- name: Upload the diff artifact | ||
if: steps.cache-metrics.outputs.cache-hit == 'true' && steps.diff-check.outcome == 'failure' | ||
uses: actions/upload-artifact@6f51ac03b9356f520e9adb1b1b7802705f340c2b # v4.5.0 | ||
with: | ||
name: diff_${{ inputs.artifact_key }} | ||
path: ./.metrics/diff_${{ inputs.snapshot }} | ||
retention-days: 7 | ||
|
||
|
This file contains 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 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 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 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 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 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 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 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 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 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 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 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,74 @@ | ||
# Copyright (c) 2024 The Jaeger Authors. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
import argparse | ||
import sys | ||
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, str(args.file1), str(args.file2)) | ||
|
||
# Check if there are any differences | ||
if not diff_lines: | ||
print("No differences found between the metric files.") | ||
sys.exit(0) | ||
|
||
# Write diff to output file | ||
write_diff_file(diff_lines, args.output) | ||
|
||
if __name__ == '__main__': | ||
main() |