Created
March 20, 2026 04:21
-
-
Save luccabb/d0c7b0d2ea4c4fe0925af4eb6001cee0 to your computer and use it in GitHub Desktop.
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
| #!/bin/bash | |
| # Test script to verify check-storage disk-usage produces identical output | |
| # before and after the HealthCheckRuntime migration. | |
| # | |
| # Produces a single file at /tmp/hc_migration_<label>.txt that you can | |
| # diff in any tool. | |
| # | |
| # Usage: | |
| # git checkout main && pip install -e . | |
| # ./scripts/test_check_migration.sh before | |
| # | |
| # git checkout feature/health-check-runtime && pip install -e . | |
| # ./scripts/test_check_migration.sh after | |
| # | |
| # diff /tmp/hc_migration_before.txt /tmp/hc_migration_after.txt | |
| set -euo pipefail | |
| LABEL="${1:?Usage: $0 <before|after>}" | |
| OUTFILE="/tmp/hc_migration_${LABEL}.txt" | |
| CLUSTER="my_cluster" | |
| : > "$OUTFILE" | |
| run_scenario() { | |
| local name="$1" | |
| shift | |
| local log_dir | |
| log_dir=$(mktemp -d) | |
| local tmp_stdout | |
| tmp_stdout=$(mktemp) | |
| local tmp_stderr | |
| tmp_stderr=$(mktemp) | |
| set +e | |
| health_checks "$@" --log-folder="$log_dir" > "$tmp_stdout" 2> "$tmp_stderr" | |
| local ec=$? | |
| set -e | |
| # Extract Nagios output line (non-JSON lines) | |
| local output | |
| output=$(grep -v '^\[' "$tmp_stdout" || true) | |
| # Extract and stabilize telemetry JSON (strip volatile fields) | |
| local telemetry | |
| telemetry=$(grep '^\[' "$tmp_stdout" | python3 -c " | |
| import json, sys | |
| for line in sys.stdin: | |
| records = json.loads(line) | |
| for r in records: | |
| for k in ('timestamp', 'duration_ms', 'start_time', 'end_time', 'duration_secs'): | |
| r.pop(k, None) | |
| print(json.dumps(records, indent=2, sort_keys=True)) | |
| " 2>/dev/null || true) | |
| # Stabilize log file (strip timestamps) | |
| local logfile | |
| logfile=$(find "$log_dir" -name '*.log' -exec cat {} \; 2>/dev/null \ | |
| | sed 's/\[[^]]*\]/[TS]/g' || true) | |
| local stderr | |
| stderr=$(cat "$tmp_stderr") | |
| # Write everything to the single output file | |
| { | |
| echo "========================================" | |
| echo "SCENARIO: $name" | |
| echo "========================================" | |
| echo "EXIT_CODE: $ec" | |
| echo "--- OUTPUT ---" | |
| echo "$output" | |
| echo "--- TELEMETRY ---" | |
| echo "$telemetry" | |
| echo "--- STDERR ---" | |
| echo "$stderr" | |
| echo "" | |
| } >> "$OUTFILE" | |
| rm -f "$tmp_stdout" "$tmp_stderr" | |
| rm -rf "$log_dir" | |
| echo " [$ec] $name: $output" | |
| } | |
| echo "=== Running scenarios ===" | |
| echo "=== Writing to: $OUTFILE ===" | |
| echo "" | |
| # --- OK path --- | |
| run_scenario "01_ok" \ | |
| check-storage disk-usage "$CLUSTER" prolog \ | |
| --sink=stdout -v / \ | |
| --usage-warning-threshold=99 --usage-critical-threshold=99 | |
| # --- WARN path --- | |
| run_scenario "02_warn" \ | |
| check-storage disk-usage "$CLUSTER" prolog \ | |
| --sink=stdout -v / \ | |
| --usage-warning-threshold=1 --usage-critical-threshold=99 | |
| # --- CRITICAL path --- | |
| run_scenario "03_critical" \ | |
| check-storage disk-usage "$CLUSTER" prolog \ | |
| --sink=stdout -v / \ | |
| --usage-warning-threshold=1 --usage-critical-threshold=1 | |
| # --- Multiple volumes (loop aggregation) --- | |
| run_scenario "04_multi_volume" \ | |
| check-storage disk-usage "$CLUSTER" prolog \ | |
| --sink=stdout -v / -v /tmp \ | |
| --usage-warning-threshold=99 --usage-critical-threshold=99 | |
| # --- Verbose output --- | |
| run_scenario "05_verbose" \ | |
| check-storage disk-usage "$CLUSTER" prolog \ | |
| --sink=stdout -v / \ | |
| --usage-warning-threshold=99 --usage-critical-threshold=99 --verbose-out | |
| # --- Output type: nagios --- | |
| run_scenario "06_nagios" \ | |
| check-storage disk-usage "$CLUSTER" nagios \ | |
| --sink=stdout -v / \ | |
| --usage-warning-threshold=99 --usage-critical-threshold=99 | |
| # --- Output type: app --- | |
| run_scenario "07_app" \ | |
| check-storage disk-usage "$CLUSTER" app \ | |
| --sink=stdout -v / \ | |
| --usage-warning-threshold=99 --usage-critical-threshold=99 | |
| # --- Output type: epilog --- | |
| run_scenario "08_epilog" \ | |
| check-storage disk-usage "$CLUSTER" epilog \ | |
| --sink=stdout -v / \ | |
| --usage-warning-threshold=99 --usage-critical-threshold=99 | |
| # --- Inode check --- | |
| run_scenario "09_inode" \ | |
| check-storage disk-usage "$CLUSTER" prolog \ | |
| --sink=stdout -v / \ | |
| --usage-warning-threshold=99 --usage-critical-threshold=99 --inode-check | |
| # --- Bad volume (error path) --- | |
| run_scenario "10_bad_volume" \ | |
| check-storage disk-usage "$CLUSTER" prolog \ | |
| --sink=stdout -v /nonexistent_vol_12345 \ | |
| --usage-warning-threshold=99 --usage-critical-threshold=99 | |
| # --- Debug log level --- | |
| run_scenario "11_debug" \ | |
| check-storage disk-usage "$CLUSTER" prolog \ | |
| --sink=stdout -v / \ | |
| --usage-warning-threshold=99 --usage-critical-threshold=99 --log-level=DEBUG | |
| # --- Heterogeneous cluster --- | |
| run_scenario "12_heterogeneous" \ | |
| check-storage disk-usage "$CLUSTER" prolog \ | |
| --sink=stdout -v / \ | |
| --usage-warning-threshold=99 --usage-critical-threshold=99 --heterogeneous-cluster-v1 | |
| # --- Killswitch ON (should exit OK with killswitch message) --- | |
| KILLSWITCH_ON=$(mktemp --suffix=.toml) | |
| cat > "$KILLSWITCH_ON" <<'TOML' | |
| [HealthChecksFeatures] | |
| disable_disk_usage = true | |
| TOML | |
| run_scenario "13_killswitch_on" \ | |
| --features-config="$KILLSWITCH_ON" \ | |
| check-storage disk-usage "$CLUSTER" prolog \ | |
| --sink=stdout -v / \ | |
| --usage-warning-threshold=1 --usage-critical-threshold=1 | |
| # --- Killswitch OFF explicitly (should behave like normal) --- | |
| KILLSWITCH_OFF=$(mktemp --suffix=.toml) | |
| cat > "$KILLSWITCH_OFF" <<'TOML' | |
| [HealthChecksFeatures] | |
| disable_disk_usage = false | |
| TOML | |
| run_scenario "14_killswitch_off" \ | |
| --features-config="$KILLSWITCH_OFF" \ | |
| check-storage disk-usage "$CLUSTER" prolog \ | |
| --sink=stdout -v / \ | |
| --usage-warning-threshold=99 --usage-critical-threshold=99 | |
| # --- Killswitch ON + would-be-CRITICAL (proves killswitch overrides) --- | |
| run_scenario "15_killswitch_overrides_critical" \ | |
| --features-config="$KILLSWITCH_ON" \ | |
| check-storage disk-usage "$CLUSTER" nagios \ | |
| --sink=stdout -v / \ | |
| --usage-warning-threshold=1 --usage-critical-threshold=1 | |
| # --- Killswitch ON + verbose (killswitch message should appear in output) --- | |
| run_scenario "16_killswitch_verbose" \ | |
| --features-config="$KILLSWITCH_ON" \ | |
| check-storage disk-usage "$CLUSTER" nagios \ | |
| --sink=stdout -v / \ | |
| --usage-warning-threshold=1 --usage-critical-threshold=1 --verbose-out | |
| # --- Corrupt features config (killswitch should default to OFF) --- | |
| KILLSWITCH_BAD=$(mktemp --suffix=.toml) | |
| echo "not valid toml {{{{" > "$KILLSWITCH_BAD" | |
| run_scenario "17_killswitch_bad_config" \ | |
| --features-config="$KILLSWITCH_BAD" \ | |
| check-storage disk-usage "$CLUSTER" prolog \ | |
| --sink=stdout -v / \ | |
| --usage-warning-threshold=99 --usage-critical-threshold=99 | |
| # --- WARN + verbose (verify msg appears in verbose output) --- | |
| run_scenario "18_warn_verbose" \ | |
| check-storage disk-usage "$CLUSTER" prolog \ | |
| --sink=stdout -v / \ | |
| --usage-warning-threshold=1 --usage-critical-threshold=99 --verbose-out | |
| # --- CRITICAL + nagios (verify nagios format with failure) --- | |
| run_scenario "19_critical_nagios" \ | |
| check-storage disk-usage "$CLUSTER" nagios \ | |
| --sink=stdout -v / \ | |
| --usage-warning-threshold=1 --usage-critical-threshold=1 | |
| rm -f "$KILLSWITCH_ON" "$KILLSWITCH_OFF" "$KILLSWITCH_BAD" | |
| echo "" | |
| echo "Done. Output written to: $OUTFILE" | |
| echo "To compare: diff /tmp/hc_migration_before.txt /tmp/hc_migration_after.txt" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment