diff --git a/scripts/orchestra_e2e_healthcheck.sh b/scripts/orchestra_e2e_healthcheck.sh index 7d47789..cfc8c5b 100755 --- a/scripts/orchestra_e2e_healthcheck.sh +++ b/scripts/orchestra_e2e_healthcheck.sh @@ -13,19 +13,29 @@ emit() { [ "$format" = none ] || printf "$@" } +# now_us: current time in microseconds. Strips any locale decimal separator. +now_us() { printf '%s' "${EPOCHREALTIME//[!0-9]/}"; } + +# elapsed_ms : whole milliseconds since . +elapsed_ms() { printf '%s' "$(( ($(now_us) - $1) / 1000 ))"; } + main() { + local start_us + start_us=$(now_us) local quiet= local json= local summary= local -a results=() + local timing= for arg in "$@"; do if [ "$arg" = --help ]; then - emit text 'Usage: %s [--quiet] [--json] [--summary] [--list-checks]\n\n' "${0##*/}" + emit text 'Usage: %s [--quiet] [--json] [--summary] [--timing] [--list-checks]\n\n' "${0##*/}" emit text 'Healthcheck script for Orchestra E2E tests.\n' emit text 'Exits 0 with a success message if all checks pass.\n' emit text ' --quiet Suppress the success message; still exits 0.\n' emit text ' --list-checks Print the name of each check; exits 0.\n' emit text ' --summary Print one line per check before the success message.\n' + emit text ' --timing Print elapsed milliseconds for each check.\n' emit text 'Version: %s\n' "$VERSION" exit 0 elif [ "$arg" = --list-checks ]; then @@ -39,6 +49,8 @@ main() { json=1 elif [ "$arg" = --summary ]; then summary=1 + elif [ "$arg" = --timing ]; then + timing=1 fi done @@ -48,8 +60,20 @@ main() { [ -n "$quiet" ] && format=none [ -n "$json" ] && format=json + local -a TIMINGS=() + TIMINGS+=("healthchecks=$(elapsed_ms "$start_us")") + if [ "$format" = json ]; then - emit "$format" '{"status":"ok","checks":%d}\n' "${#CHECKS[@]}" + local timings= + if [ -n "$timing" ]; then + local sep= + for t in "${TIMINGS[@]}"; do + timings+="$sep\"${t%%=*}\":${t#*=}" + sep=, + done + timings=",\"timings\":{$timings}" + fi + emit "$format" '{"status":"ok","checks":%d%s}\n' "${#CHECKS[@]}" "$timings" exit 0 fi @@ -59,6 +83,12 @@ main() { done fi + if [ -n "$timing" ]; then + for t in "${TIMINGS[@]}"; do + emit "$format" '%s: %sms\n' "${t%%=*}" "${t#*=}" + done + fi + emit "$format" '%s\n' "$SUCCESS_MESSAGE" exit 0 } diff --git a/scripts/test_healthcheck.sh b/scripts/test_healthcheck.sh index 423ff1e..1ef6b32 100755 --- a/scripts/test_healthcheck.sh +++ b/scripts/test_healthcheck.sh @@ -3,14 +3,16 @@ HC="$(dirname "$0")/orchestra_e2e_healthcheck.sh" OK='OK - all healthchecks passed' -USAGE="$(printf 'Usage: orchestra_e2e_healthcheck.sh [--quiet] [--json] [--summary] [--list-checks]\n\nHealthcheck script for Orchestra E2E tests.\nExits 0 with a success message if all checks pass.\n --quiet Suppress the success message; still exits 0.\n --list-checks Print the name of each check; exits 0.\n --summary Print one line per check before the success message.\nVersion: 1.0.0')" +USAGE="$(printf 'Usage: orchestra_e2e_healthcheck.sh [--quiet] [--json] [--summary] [--timing] [--list-checks]\n\nHealthcheck script for Orchestra E2E tests.\nExits 0 with a success message if all checks pass.\n --quiet Suppress the success message; still exits 0.\n --list-checks Print the name of each check; exits 0.\n --summary Print one line per check before the success message.\n --timing Print elapsed milliseconds for each check.\nVersion: 1.0.0')" fails=0 check() { # check