feat: carry lab 2 over and add X-Instance-Id and idempotency keys

- carry the lab 2 solution over and plan lab 3 (PLAN.md, OpenSpec
  change instance-id-idempotency)
- rename the compose project to mtusi-lab3 and the image to :lab3
- add X-Instance-Id to every response and instance_id to every log
  record ([app] instance_id, hostname by default)
- require Idempotency-Key on POST messages: keys table in Postgres,
  key and message in one transaction, replay returns the same 201,
  another body gets 409, TTL from [idempotency] ttl_seconds
- send the key from student-tests, k6 scenarios and the skill driver;
  add idempotency, X-Instance-Id, key race and fault tests

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-08 19:42:36 +03:00
co-authored by Claude Opus 5.5
parent 0ab3a341aa
commit af4bca08c9
294 changed files with 36586 additions and 15 deletions
+53
View File
@@ -0,0 +1,53 @@
# Override стенда make bench (bench/run.py): тот же docker-compose.yml под
# проектом mtusi-bench, со своими volume, сетью и лимитами. Пины, healthcheck
# хранилищ, valkey.conf и миграции — из основного файла. Подстановки — из
# bench/bench.env, а не из .env рабочего стенда; пароли и BENCH_* передаёт
# run.py (поля Profile), без них стенд не поднимается. Решения 1, 2, 5 design
# change bench-postgres; что не меняется между метками — .claude/rules/bench.md.
services:
postgres:
container_name: mtusi-bench-postgres
# упавший контейнер не поднимается сам: прогон помечается stand_down
restart: "no"
# auto_explain загружен, но выключен (log_min_duration = -1): run.py
# включает его только на этапе плана, между прогонами
command: ["postgres", "-c", "shared_preload_libraries=auto_explain"]
ports: !reset []
cpus: ${BENCH_DB_CPUS:?run make bench}
mem_limit: ${BENCH_DB_MEMORY:?run make bench}
memswap_limit: ${BENCH_DB_MEMORY:?run make bench}
valkey:
container_name: mtusi-bench-valkey
restart: "no"
ports: !reset []
cpus: ${BENCH_CACHE_CPUS:?run make bench}
mem_limit: ${BENCH_CACHE_MEMORY:?run make bench}
memswap_limit: ${BENCH_CACHE_MEMORY:?run make bench}
migrate:
image: mtusi-messenger:bench
# без config.toml рабочего стенда: настройки — окружение и дефолты
volumes: !reset []
api:
container_name: mtusi-bench-api
image: mtusi-messenger:bench
restart: "no"
ports: !reset []
volumes: !reset []
# проверка раз в несколько секунд — лишний CPU внутри лимита API
healthcheck:
disable: true
environment:
# размер 500k с наполнением идёт ~25 мин; на медленном хосте срок
# 3600 с по умолчанию мог бы истечь посреди прогона и дать 401
AUTH__SESSION_TTL_SECONDS: ${BENCH_SESSION_TTL_SECONDS:?run make bench}
cpus: ${BENCH_APP_CPUS:?run make bench}
mem_limit: ${BENCH_APP_MEMORY:?run make bench}
memswap_limit: ${BENCH_APP_MEMORY:?run make bench}
networks:
default:
# k6 подключается к сети стенда по имени (docker run --network)
name: mtusi-bench