|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +set -eu -o pipefail |
| 4 | + |
| 5 | +# Check if two arguments are provided (paths to past.json and current.json) |
| 6 | +if [ $# -ne 2 ]; then |
| 7 | + echo "Usage: $0 <path_to_past.json> <path_to_current.json>" |
| 8 | + exit 1 |
| 9 | +fi |
| 10 | + |
| 11 | +# Extract the file paths from command-line arguments |
| 12 | +past_json_path="$1" |
| 13 | +current_json_path="$2" |
| 14 | + |
| 15 | +# Read the contents of past.json and current.json into variables |
| 16 | +past_data=$(cat "$past_json_path") |
| 17 | +current_data=$(cat "$current_json_path") |
| 18 | + |
| 19 | +# Function to compare P90 values for a given statistic |
| 20 | +compare_stat_p90() { |
| 21 | + local past_value="$1" |
| 22 | + local current_value="$2" |
| 23 | + local stat_name="$3" |
| 24 | + |
| 25 | + # Calculate 110% of the past value |
| 26 | + local threshold=$(calculate_threshold "$past_value") |
| 27 | + |
| 28 | + # Compare the current value with the threshold |
| 29 | + if (( $(awk 'BEGIN {print ("'"$current_value"'" > "'"$threshold"'")}') )); then |
| 30 | + echo "ERROR: $stat_name - Current P90 value ($current_value) exceeds the 110% threshold ($threshold) of the past P90 value ($past_value)" |
| 31 | + return 1 |
| 32 | + fi |
| 33 | + |
| 34 | + return 0 |
| 35 | +} |
| 36 | + |
| 37 | +calculate_threshold() { |
| 38 | + local past_value="$1" |
| 39 | + awk -v past="$past_value" 'BEGIN { print past * 1.1 }' |
| 40 | +} |
| 41 | + |
| 42 | +# Loop through each object in past.json and compare P90 values with current.json for all statistics |
| 43 | +compare_p90_values() { |
| 44 | + local past_json="$1" |
| 45 | + local current_json="$2" |
| 46 | + |
| 47 | + local test_names=$(echo "$past_json" | jq -r '.benchmarkTests[].testName') |
| 48 | + |
| 49 | + # Use a flag to indicate if any regression has been detected |
| 50 | + local regression_detected=0 |
| 51 | + |
| 52 | + for test_name in $test_names; do |
| 53 | + echo "Checking for regression in '$test_name'" |
| 54 | + for stat_name in "fullRunStats" "pullStats" "lazyTaskStats" "localTaskStats"; do |
| 55 | + local past_p90=$(echo "$past_json" | jq -r --arg test "$test_name" '.benchmarkTests[] | select(.testName == $test) | .'"$stat_name"'.pct90') |
| 56 | + local current_p90=$(echo "$current_json" | jq -r --arg test "$test_name" '.benchmarkTests[] | select(.testName == $test) | .'"$stat_name"'.pct90') |
| 57 | + |
| 58 | + # Call the compare_stat_p90 function |
| 59 | + compare_stat_p90 "$past_p90" "$current_p90" "$stat_name" || regression_detected=1 |
| 60 | + done |
| 61 | + done |
| 62 | + |
| 63 | + # Check if any regression has been detected and return the appropriate exit code |
| 64 | + return $regression_detected |
| 65 | +} |
| 66 | + |
| 67 | +# ... (remaining code) |
| 68 | + |
| 69 | +# Call compare_p90_values and store the exit code in a variable |
| 70 | +compare_p90_values "$past_data" "$current_data" |
| 71 | +exit_code=$? |
| 72 | + |
| 73 | +# Check the return status and display appropriate message |
| 74 | +if [ $exit_code -eq 0 ]; then |
| 75 | + echo "Comparison successful. No regressions detected, all P90 values are within the acceptable range." |
| 76 | +else |
| 77 | + echo "Comparison failed. Regression detected." |
| 78 | +fi |
| 79 | + |
| 80 | +# Set the final exit code to indicate if any regression occurred |
| 81 | +exit $exit_code |
0 commit comments