|
| 1 | +#!/usr/bin/env bash |
| 2 | +# Stable entrypoint for the managed nightly RPC benchmark. |
| 3 | +set -euo pipefail |
| 4 | + |
| 5 | +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 6 | +RPC_DIR="$(cd "$SCRIPT_DIR/.." && pwd)" |
| 7 | +CATALOG="$RPC_DIR/corpus/nightly.json" |
| 8 | +CI_CONFIG="$SCRIPT_DIR/ci.json" |
| 9 | +CORPUS_GEN=${CORPUS_GEN:-"$RPC_DIR/../../build/corpus-gen"} |
| 10 | +RUN_SCRIPT="$RPC_DIR/run.js" |
| 11 | + |
| 12 | +: "${NODE_URL:?NODE_URL is required}" |
| 13 | +: "${SNAPSHOT_SHA256:?SNAPSHOT_SHA256 is required}" |
| 14 | +[[ $SNAPSHOT_SHA256 =~ ^[0-9a-f]{64}$ ]] || { |
| 15 | + echo "error: SNAPSHOT_SHA256 must be a lowercase SHA-256 digest" >&2 |
| 16 | + exit 1 |
| 17 | +} |
| 18 | +CORPUS_ROOT="${CORPUS_ROOT:-/corpus/cases}/$SNAPSHOT_SHA256" |
| 19 | + |
| 20 | +source "$SCRIPT_DIR/internal/preflight.sh" |
| 21 | +source "$SCRIPT_DIR/internal/corpus.sh" |
| 22 | + |
| 23 | +case_path() { |
| 24 | + printf '%s/%s/corpus.json\n' "$CORPUS_ROOT" "$1" |
| 25 | +} |
| 26 | + |
| 27 | +benchmark() { |
| 28 | + [[ -f $CI_CONFIG ]] || { |
| 29 | + echo "error: k6 config not found: $CI_CONFIG" >&2 |
| 30 | + return 1 |
| 31 | + } |
| 32 | + local out_dir=${RESULTS_DIR:-/results} |
| 33 | + local warmup_iterations=${WARMUP_ITERATIONS:-200} |
| 34 | + mkdir -p "$out_dir" |
| 35 | + |
| 36 | + local name corpus summary case_failed |
| 37 | + local -a failed=() |
| 38 | + while IFS= read -r name; do |
| 39 | + summary="$out_dir/$name.json" |
| 40 | + |
| 41 | + echo |
| 42 | + echo "==> $name" |
| 43 | + corpus=$(case_path "$name") |
| 44 | + if [[ ! -f $corpus ]]; then |
| 45 | + echo "error: missing corpus for $name: $corpus" >&2 |
| 46 | + failed+=("$name") |
| 47 | + continue |
| 48 | + fi |
| 49 | + corpus="$(cd "$(dirname "$corpus")" && pwd)/$(basename "$corpus")" |
| 50 | + |
| 51 | + case_failed=0 |
| 52 | + if [[ $warmup_iterations != 0 ]]; then |
| 53 | + echo "warming up" |
| 54 | + ( |
| 55 | + K6_WEB_DASHBOARD=false k6 run \ |
| 56 | + --vus 1 \ |
| 57 | + --iterations "$warmup_iterations" \ |
| 58 | + --tag "case_id=$name" \ |
| 59 | + --tag phase=warmup \ |
| 60 | + --summary-mode=disabled \ |
| 61 | + -e NODE_URL="$NODE_URL" \ |
| 62 | + "$RUN_SCRIPT" <"$corpus" >/dev/null |
| 63 | + ) || { |
| 64 | + echo "error: warmup did not complete for $name" >&2 |
| 65 | + case_failed=1 |
| 66 | + } |
| 67 | + fi |
| 68 | + |
| 69 | + if ((case_failed == 0)); then |
| 70 | + k6 run \ |
| 71 | + --config "$CI_CONFIG" \ |
| 72 | + --tag "case_id=$name" \ |
| 73 | + --tag phase=measure \ |
| 74 | + --summary-export "$summary" \ |
| 75 | + -e NODE_URL="$NODE_URL" \ |
| 76 | + "$RUN_SCRIPT" <"$corpus" || case_failed=1 |
| 77 | + fi |
| 78 | + ((case_failed == 0)) || failed+=("$name") |
| 79 | + done < <(jq -r 'keys_unsorted[]' "$CATALOG") |
| 80 | + |
| 81 | + if ((${#failed[@]} > 0)); then |
| 82 | + echo "failed: ${failed[*]}" >&2 |
| 83 | + return 1 |
| 84 | + fi |
| 85 | +} |
| 86 | + |
| 87 | +nightly_run() { |
| 88 | + preflight |
| 89 | + |
| 90 | + local failed=0 |
| 91 | + generate || failed=1 |
| 92 | + benchmark || failed=1 |
| 93 | + return "$failed" |
| 94 | +} |
| 95 | + |
| 96 | +nightly_run |
0 commit comments