Skip to content

Commit

Permalink
minor changes
Browse files Browse the repository at this point in the history
Signed-off-by: chahatsagarmain <[email protected]>
  • Loading branch information
chahatsagarmain committed Jan 6, 2025
1 parent 1bdb77f commit 157822d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
18 changes: 9 additions & 9 deletions .github/actions/verify-metrics-snapshot/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,45 +34,45 @@ runs:
id: check-cache
uses: actions/cache/restore@1bd1e32a3bdc45362d1e726936510720a7c30a57
with:
path: ./.metrics/cached_${{ inputs.snapshot}}
path: ./.metrics/release_${{ inputs.snapshot}}
key: ${{ env.v2_tag }}_${{ inputs.artifact_key }}
lookup-only: true

- name: Change file name before caching
if: ${{ (github.ref_name == 'main') && (steps.check-cache.outputs.cache-hit != 'true') }}
shell: bash
run: |
mv ./.metrics/${{ inputs.snapshot }} ./.metrics/cached_${{ inputs.snapshot}}
mv ./.metrics/${{ inputs.snapshot }} ./.metrics/release_${{ inputs.snapshot}}
- name: Cache scraped metrics for tagged release for longer retention
id: tagged-metrics
if: ${{ (github.ref_name == 'main') && (steps.check-cache.outputs.cache-hit != 'true') }}
uses: actions/cache/save@1bd1e32a3bdc45362d1e726936510720a7c30a57
with:
path: ./.metrics/cached_${{ inputs.snapshot}}
path: ./.metrics/release_${{ inputs.snapshot}}
key: ${{ env.v2_tag }}_${{ inputs.artifact_key }}

- name: Download the cached tagged metrics
id: cache-metrics
id: download-release-snapshot
uses: actions/cache/restore@1bd1e32a3bdc45362d1e726936510720a7c30a57
with:
path: ./.metrics/cached_${{ inputs.snapshot}}
path: ./.metrics/release_${{ 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'
id: compare-snapshots
if: steps.download-release-snapshot.outputs.cache-hit == 'true'
shell: bash
run: |
python3 -m pip install prometheus-client
python3 ./scripts/e2e/compare_metrics.py --file1 ./.metrics/${{ inputs.snapshot }} --file2 ./.metrics/cached_${{ inputs.snapshot}} --output ./.metrics/diff_${{ inputs.snapshot }}
if [ $? -eq 1 ]; then
echo "No differences found in metrics"
echo "Differences found in metrics"
exit 1
fi
- name: Upload the diff artifact
if: ${{ (steps.cache-metrics.outputs.cache-hit == 'true') && (steps.diff-check.outcome == 'failure') }}
if: ${{ (steps.download-release-snapshot.outputs.cache-hit == 'true') && (steps.compare-snapshots.outcome == 'failure') }}
uses: actions/upload-artifact@6f51ac03b9356f520e9adb1b1b7802705f340c2b # v4.5.0
with:
name: diff_${{ inputs.artifact_key }}
Expand Down
16 changes: 7 additions & 9 deletions scripts/e2e/compare_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# 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
Expand Down Expand Up @@ -63,16 +62,15 @@ def main():
diff_lines = generate_diff(file1_lines, file2_lines)

# Check if there are any differences
if not diff_lines:
print("No differences found between the metric files.")
sys.exit(1)

# Write diff to output file
write_diff_file(diff_lines, args.output)
if diff_lines:
print("differences found between the metric files.")
print("=== Metrics Comparison Results ===")
print(diff_lines)
write_diff_file(diff_lines, args.output)

print("\n=== Metrics Comparison Results ===")
print(diff_lines)
return 1

print("no difference found")
return 0

if __name__ == '__main__':
Expand Down

0 comments on commit 157822d

Please sign in to comment.