Propose failover operations as an openspec change

Level 4 of lab 3 asks for health checks, timeouts and SIGTERM handling
that agree with each other, a stated check period and worst detection
time, stopping every replica in turn under load with RPS, errors and
recovery time, a parallel race on one idempotency key, limits and
port and secret isolation, and a rolling update under load with
migrations run once.

The new lab3-failover-operations capability covers those guarantees.
The lab 1 operability delta makes a replica leave the rotation first
on SIGTERM: readiness answers 503 for a drain window longer than the
balancer detection time, and only then the listener closes. The lab 2
dependency failure delta states that the balancer drops every replica
and answers 503 itself while PostgreSQL is down. The design adds the
measurement tooling from the prepared kit: k6 under a bench profile,
probe load and detect modes, detection, failover-each, limits and
rolling update scripts with one make target each.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Artyom
2026-10-28 19:30:27 +03:00
co-authored by Claude Opus 5.5
parent 8d28d45d55
commit 1ae4b770ae
7 changed files with 271 additions and 0 deletions
@@ -0,0 +1,34 @@
## 1. Остановка и готовность (платформа)
- [ ] 1.1 `DRAINING` в `shared/entrypoints/health.py`: `/health/ready` отвечает `503 unavailable`, пока флаг поднят
- [ ] 1.2 `DrainingServer` и `MessengerWorker._serve` в `gunicorn_conf.py`: окно `DRAIN_SECONDS`, затем штатная остановка; uvicorn дообрабатывает `SHUTDOWN_TIMEOUT_SECONDS − DRAIN_SECONDS`
- [ ] 1.3 Пинг readiness: 0,4 с на соединение и 0,4 с на запрос
- [ ] 1.4 Проверка группы: тесты — ready `503` при флаге и live `200`; настоящий gunicorn по `SIGTERM` держит окно, закрывает порт и выходит с кодом 0 за срок
## 2. Стенд и таймауты
- [ ] 2.1 `compose.yaml`: явные `DRAIN_SECONDS`, `DB_ACQUIRE_TIMEOUT_SECONDS`, `DB_COMMAND_TIMEOUT_SECONDS` у `api`; сервис `k6` под профилем `bench`; `.env.example`, Dockerfile
- [ ] 2.2 Тест цепочки таймаутов по `compose.yaml`, `haproxy.cfg` и `scripts/stop-one.sh`
- [ ] 2.3 Проверка группы: `docker compose --profile bench config --quiet`, `make student-test -k "timeouts or drain"`
## 3. Нагрузка и зонд
- [ ] 3.1 `infra/k6/messages.js`, `scripts/k6.sh` (запуск от uid хоста)
- [ ] 3.2 `scripts/probe.py`: `load` (k6 + зонд + опрос LB, `action.log`, счётчики повторов LB, `--expect dip|replace`, `pass`), `detect` (действие фоном, `--max`, `--until`, `--within-action`, `--lb-status`, `--restore`), `check --rounds`
- [ ] 3.3 Проверка группы: `make lint`, `make check` (разбор `scripts/*.py` интерпретатором CI), `k6 inspect`
## 4. Сценарии уровня «4»
- [ ] 4.1 `scripts/detection.sh` и `make detection`: `SIGTERM`, `docker kill`, `docker pause`, остановка PostgreSQL с заявленными максимумами
- [ ] 4.2 `scripts/failover-each.sh` и `make failover-each`: остановка, 10 с без реплики и возврат каждой реплики под нагрузкой
- [ ] 4.3 `scripts/limits.py` и `make limits`: политика лимитов, портов, секретов, volumes, сетей
- [ ] 4.4 `scripts/rolling-update.sh` и `make rolling-update [FROM_REV=…]`: `migrate` один раз, замена с запасом +1, журнал образов
- [ ] 4.5 Тест отказа PostgreSQL через LB: ответы `503`, live внутри реплики `200`, LB исключает все реплики и сам отвечает `503`
- [ ] 4.6 CI: `make limits`, `make detection` в acceptance
- [ ] 4.7 Проверка группы: `make up`, `make limits`, `make lb-check`, `make detection`, `make failover-each`, `make rolling-update FROM_REV=8d28d45`, `make test-faults`
## 5. Отчёт
- [ ] 5.1 `evidence/`: detection, failover-each, rolling, limits, lb-check, повторные прогоны уровня «3» на новом коде
- [ ] 5.2 `REPORT.md`: таймауты и обнаружение, строки 4.1–4.4, таблица отказов уровня «4», ограничения
- [ ] 5.3 Проверка группы: `make check`, `make validate`, `make lint`, `make student-test`, `make test`, `make test-persistence ACTION_SCRIPT=scripts/restart.sh`, `make test-failover ACTION_SCRIPT=scripts/stop-one.sh` для обеих реплик