forked from mtusi2026/mtusi2026lab3
The /health/ready route imported the PostgreSQL adapter and kept the drain flag in the HTTP layer, which gunicorn_conf imported to raise it. Readiness is now a port of the shared application layer; its adapter in shared/infrastructure checks the per-process drain flag and pings PostgreSQL, and PlatformProvider assembles it. The route only knows the port, and gunicorn_conf raises the flag through the infrastructure module. Another critical dependency now changes the adapter and the provider, not the HTTP layer. The drain window was logged by a uvicorn logger with a printf string; it is now the service.draining event of a StructlogLogger with the same fields as the application, and failover-evidence looks for it. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01V1d3RLHNBBMA6UqBLLJv27
32 lines
1.3 KiB
Bash
Executable File
32 lines
1.3 KiB
Bash
Executable File
#!/bin/sh
|
|
set -eu
|
|
cd "$(dirname "$0")/.."
|
|
replicas() {
|
|
docker inspect -f '{{.Config.Hostname}} {{.State.Status}} started={{.State.StartedAt}} finished={{.State.FinishedAt}}' $(docker compose ps -aq "${API_SERVICE:-api}")
|
|
}
|
|
url=${1:-http://localhost:8080}
|
|
shift=0
|
|
while [ "$shift" -lt "${2:-0}" ]; do curl -fsS -o /dev/null "$url/health/live"; shift=$((shift + 1)); done
|
|
tmp=evidence/failover.tmp
|
|
since=$(date -u +%FT%TZ)
|
|
{
|
|
echo "date: $(date -u +%FT%TZ) commit: $(git rev-parse --short HEAD)"
|
|
echo "== before: api replicas (hostname = X-Instance-Id), state, StartedAt, FinishedAt"
|
|
replicas
|
|
echo "\$ make test-failover ACTION_SCRIPT=scripts/stop-one.sh"
|
|
make --no-print-directory test-failover ACTION_SCRIPT=scripts/stop-one.sh BASE_URL="$url"
|
|
echo "== after: api replicas"
|
|
replicas
|
|
} > "$tmp" 2>&1
|
|
stopped=$(replicas | awk '$2 == "exited" {print $1}')
|
|
{
|
|
echo "== stopped replica: $stopped; shutdown: signal, drain window with readiness 503, close, exit"
|
|
docker logs --since "$since" "$stopped" 2>&1 | grep -E 'Handling signal|service.draining|"status":503|Shutting down|Waiting for conn|Finished server|service.stopped|SIGTERM' | tail -16
|
|
echo "\$ scripts/restore.sh"
|
|
scripts/restore.sh
|
|
echo "== after restore"
|
|
replicas
|
|
} >> "$tmp" 2>&1
|
|
mv "$tmp" "evidence/failover-$stopped.txt"
|
|
cat "evidence/failover-$stopped.txt"
|