Fill the remaining report sections: clean clone run with versions and prerequisites, lab 2 carry-over, transaction boundaries, teacher agreements, skeleton variable mapping, rubric cross-check, experiment overview, limitations summary, sources and AI usage. Record the clean clone run of every documented command on default ports. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
233 lines
13 KiB
Markdown
233 lines
13 KiB
Markdown
# Итоговая проверка из чистого clone: стенд с LB на портах по умолчанию
|
||
|
||
| | |
|
||
|---|---|
|
||
| Что проверялось | раздел `REPORT.md` «Запуск из чистого clone» — буквально, шаг за шагом, как у проверяющего |
|
||
| Дата | 2026-10-11 18:41–18:47 UTC |
|
||
| Commit | `67b4303` — `git clone --branch solution/bvt2301-safronov` локального репозитория во временный каталог; рабочее дерево клона чистое, `.env`, `config.toml` и `.venv` нет. Код итогового commit отличается от него только `REPORT.md` и этим файлом |
|
||
| Стенд | проект compose `mtusi-lab3` (имя из `docker-compose.yml`, без `COMPOSE_PROJECT_NAME`), порты по умолчанию: LB `127.0.0.1:8080`, Postgres 5433, Valkey 6380. Рабочий стенд с тем же именем проекта перед проверкой удалён вместе с volume (`make wipe_data`), чтобы клон стартовал на пустой базе со своим паролем, как у проверяющего. После проверки стенд клона удалён (`docker compose down -v`), рабочий поднят заново `make run_docker` |
|
||
| Хост | Docker Desktop 29.8.2, Compose v5.5.1, macOS arm64 (Apple M3 Pro); ВМ Docker: 12 CPU, 7,7 GiB RAM; `python3` 3.11.9, uv 0.12.17 |
|
||
|
||
Пароли из сгенерированного `.env` не выводились: проверялось только,
|
||
что они есть (32 hex-символа).
|
||
|
||
## Подготовка и запуск
|
||
|
||
```text
|
||
$ git clone --branch solution/bvt2301-safronov <репозиторий> clean-clone && cd clean-clone
|
||
$ git log --oneline -1; git status --short | wc -l; ls .env config.toml
|
||
67b4303 docs: archive scaling-improvement and sync its specs
|
||
0
|
||
ls: .env: No such file or directory
|
||
ls: config.toml: No such file or directory
|
||
|
||
$ make env_setup # exit 0
|
||
env ready: .env, config.toml
|
||
$ grep -c -E '^(POSTGRES|VALKEY)_PASSWORD=.{32}$' .env
|
||
2
|
||
|
||
$ make run_docker # exit 0, 4,3 с (слои — из кэша BuildKit)
|
||
DOCKER_BUILDKIT=1 docker compose build
|
||
Image mtusi-messenger:lab3 Building
|
||
#4 [internal] load metadata for docker.io/library/python:3.12.14-slim-trixie@sha256:f77ac9e4…
|
||
Container mtusi-lab3-postgres-1 Healthy
|
||
Container mtusi-lab3-valkey-1 Healthy
|
||
Container mtusi-lab3-migrate-1 Exited
|
||
Container mtusi-lab3-api-1 Started
|
||
Container mtusi-lab3-api-2 Started
|
||
Container mtusi-lab3-haproxy-1 Started
|
||
|
||
$ docker compose ps -a --format 'table {{.Name}}\t{{.Status}}\t{{.Ports}}'
|
||
NAME STATUS PORTS
|
||
mtusi-lab3-api-1 Up 9 seconds (healthy) 8080/tcp
|
||
mtusi-lab3-api-2 Up 9 seconds (healthy) 8080/tcp
|
||
mtusi-lab3-haproxy-1 Up 9 seconds (healthy) 127.0.0.1:8080->8080/tcp
|
||
mtusi-lab3-migrate-1 Exited (0) 10 seconds ago
|
||
mtusi-lab3-postgres-1 Up 13 seconds (healthy) 127.0.0.1:5433->5432/tcp
|
||
mtusi-lab3-valkey-1 Up 13 seconds (healthy) 127.0.0.1:6380->6379/tcp
|
||
|
||
$ docker compose logs migrate --no-log-prefix | tail -5 # поле event
|
||
Running upgrade -> 16c279725564, added messenger tables
|
||
Running upgrade 16c279725564 -> 42bc3b9be38f, added sessions and password hashes
|
||
Running upgrade 42bc3b9be38f -> 7652184b7016, added idempotency keys
|
||
Running upgrade 7652184b7016 -> e656d6bbe1a4, added message instance id
|
||
Finished alembic
|
||
```
|
||
|
||
`8080/tcp` у реплик — `EXPOSE` образа: опубликованного порта у них
|
||
нет, API на хосте — только через HAProxy.
|
||
|
||
Сборка без кэша слоёв из того же клона (отдельный тег, затем удалён):
|
||
|
||
```text
|
||
$ docker build --no-cache --pull -t mtusi-clean-check:nocache . # exit 0, 10,5 с
|
||
$ docker run --rm --entrypoint sh mtusi-clean-check:nocache -c 'id -u; ls /app; …'
|
||
10001
|
||
alembic.ini
|
||
migrations
|
||
src
|
||
no-.env
|
||
no-config.toml
|
||
```
|
||
|
||
Колёса зависимостей `uv sync --locked` берёт из cache mount BuildKit,
|
||
поэтому 10 с; на машине без кэша добавится их загрузка.
|
||
|
||
## Контракт, smoke и распределение
|
||
|
||
```text
|
||
$ make check # exit 0
|
||
PASS: offline skeleton structure, local refs and Python syntax; application NOT tested.
|
||
$ uv sync # .venv клона с группой dev
|
||
$ make validate PYTHON=.venv/bin/python # exit 0
|
||
PASS: full OpenAPI 3.1 and JSON Schema validation; application NOT tested.
|
||
$ make test # exit 0
|
||
PASS: lab3 public API scenario; infrastructure and grading evidence remain separate.
|
||
$ make instances
|
||
11 GET /api/v1/users/me 200 x-instance-id: 437292ccaf78
|
||
12 GET /api/v1/users/me 200 x-instance-id: 0089ca350b2b
|
||
user lb_c34d4132: one login, 12 requests with one token
|
||
437292ccaf78: 6
|
||
0089ca350b2b: 6
|
||
instances: 2
|
||
```
|
||
|
||
## `make test-persistence`
|
||
|
||
```text
|
||
$ docker inspect … (до) имя, ID, состояние, StartedAt
|
||
/mtusi-lab3-api-1 0089ca350b2b running 2026-10-11T18:41:29Z
|
||
/mtusi-lab3-api-2 437292ccaf78 running 2026-10-11T18:41:29Z
|
||
/mtusi-lab3-haproxy-1 588c7fcc58e0 running 2026-10-11T18:41:29Z
|
||
/mtusi-lab3-postgres-1 e4b53ac23602 running 2026-10-11T18:41:26Z
|
||
/mtusi-lab3-valkey-1 fca2cb095076 running 2026-10-11T18:41:26Z
|
||
|
||
$ make test-persistence ACTION_SCRIPT=scripts/restart.sh # exit 0
|
||
Executing explicit persistence hook; hook output suppressed to avoid leaking secrets.
|
||
PASS: persistence preserved confirmed data and existing session. Hook scope needs operator evidence.
|
||
|
||
$ docker inspect … (после)
|
||
/mtusi-lab3-api-1 0089ca350b2b running 2026-10-11T18:41:58Z
|
||
/mtusi-lab3-api-2 437292ccaf78 running 2026-10-11T18:41:58Z
|
||
/mtusi-lab3-haproxy-1 588c7fcc58e0 running 2026-10-11T18:41:58Z
|
||
/mtusi-lab3-postgres-1 e4b53ac23602 running 2026-10-11T18:41:54Z
|
||
/mtusi-lab3-valkey-1 fca2cb095076 running 2026-10-11T18:41:54Z
|
||
$ docker volume inspect -f '{{.Name}} {{.CreatedAt}}' mtusi-lab3_postgres_data
|
||
mtusi-lab3_postgres_data 2026-10-11T18:41:25Z
|
||
```
|
||
|
||
Перезапущены LB, обе реплики, Postgres и Valkey: те же ID, новый
|
||
`StartedAt`. Volume тот же, что создал `make run_docker`.
|
||
|
||
## `make test-failover` для каждой реплики
|
||
|
||
`STOP_ONE_LOG` — строка hook: какой `TARGET_INSTANCE_ID` выбрал тест и
|
||
какой контейнер остановлен.
|
||
|
||
```text
|
||
$ STOP_ONE_LOG=<файл> make test-failover ACTION_SCRIPT=scripts/stop-one.sh # exit 0
|
||
{"observed_instances_before": 2, "successful_writes": 118, "failed_attempts": 0, "first_recovery_seconds": 1.0}
|
||
PASS: failover preserved confirmed data and existing session. Hook scope needs operator evidence.
|
||
2026-10-11T18:42:05Z TARGET_INSTANCE_ID=0089ca350b2b container=0089ca350b2bcbee… mode=stop
|
||
$ docker compose ps -a --format 'table {{.Name}}\t{{.ID}}\t{{.Status}}'
|
||
mtusi-lab3-api-1 0089ca350b2b Exited (0) 14 seconds ago
|
||
mtusi-lab3-api-2 437292ccaf78 Up 21 seconds (healthy)
|
||
|
||
$ make replicas # тот же контейнер api-1 снова healthy
|
||
$ make lb_stats
|
||
api-1 172.30.0.5:8080 UP L7OK …
|
||
api-2 172.30.0.4:8080 UP L7OK …
|
||
$ curl -s -o /dev/null -D - http://127.0.0.1:8080/health/live | grep -i x-instance-id
|
||
x-instance-id: 437292ccaf78 # сдвиг очереди round-robin одним запросом
|
||
|
||
$ STOP_ONE_LOG=<файл> make test-failover ACTION_SCRIPT=scripts/stop-one.sh # exit 0
|
||
{"observed_instances_before": 2, "successful_writes": 113, "failed_attempts": 0, "first_recovery_seconds": 0.991}
|
||
PASS: failover preserved confirmed data and existing session. Hook scope needs operator evidence.
|
||
2026-10-11T18:42:31Z TARGET_INSTANCE_ID=437292ccaf78 container=437292ccaf78… mode=stop
|
||
$ docker compose ps -a …
|
||
mtusi-lab3-api-1 0089ca350b2b Up 20 seconds (healthy)
|
||
mtusi-lab3-api-2 437292ccaf78 Exited (0) 14 seconds ago
|
||
|
||
$ make replicas
|
||
$ STOP_MODE=kill STOP_ONE_LOG=<файл> make test-failover ACTION_SCRIPT=scripts/stop-one.sh # exit 0
|
||
{"observed_instances_before": 2, "successful_writes": 114, "failed_attempts": 0, "first_recovery_seconds": 0.221}
|
||
PASS: failover preserved confirmed data and existing session. Hook scope needs operator evidence.
|
||
2026-10-11T18:42:56Z TARGET_INSTANCE_ID=437292ccaf78 container=437292ccaf78… mode=kill
|
||
mtusi-lab3-api-2 437292ccaf78 Exited (137) 15 seconds ago
|
||
|
||
$ make replicas; make lb_stats
|
||
api-1 172.30.0.5:8080 UP L7OK 0 205 0 0 5 0
|
||
api-2 172.30.0.4:8080 UP L7OK 0 307 0 0 2 0
|
||
BACKEND - UP - 0 507 2 0 7 2
|
||
free slots: 6
|
||
```
|
||
|
||
Остановлены по очереди обе реплики: ID остановленного контейнера
|
||
совпадает с `TARGET_INSTANCE_ID`, остальные работают; первая запись
|
||
после остановки — через 1,0 и 0,99 с (`stop`) и 0,22 с (`kill`),
|
||
неудачных попыток 0. У слотов реплик 5xx нет; два `hrsp_5xx` у
|
||
`BACKEND` — ответы самого LB. Счётчики обнулил рестарт LB в
|
||
`restart.sh`, после него тест сохранности ждёт готовности опросом, а
|
||
до проверок реплик LB отвечает 503 (так же в
|
||
`evidence/replicas/test-persistence.md`). Журнал LB до уборки клона не
|
||
сохранялся, так что это объяснение, а не сверка по журналу; клиенту
|
||
тестов отказа ни одна ошибка не досталась (`failed_attempts` 0).
|
||
|
||
## Собственные тесты
|
||
|
||
```text
|
||
$ make student_test # exit 0, 23,7 с
|
||
coverage: 137 scenarios in 11 specs, 125 tested (18 by make failure_checks), 12 excluded
|
||
one session, 20 requests: {'437292ccaf78': 10, '0089ca350b2b': 10}
|
||
key race through replicas: {'437292ccaf78': 5, '0089ca350b2b': 5}
|
||
===================== 131 passed, 17 deselected in 22.98s ======================
|
||
|
||
$ make failure_checks # exit 0, 69 с
|
||
[failure_checks] project=mtusi-lab3-failures (working stand: mtusi-lab3)
|
||
test_expired_token PASSED test_readiness_without_database PASSED
|
||
test_use_does_not_extend_session PASSED test_readiness_without_cache PASSED
|
||
test_token_while_database_stopped PASSED test_flush_cache PASSED
|
||
test_members_failure_rolls_back_chat PASSED test_valkey_stopped PASSED
|
||
test_database_stopped_and_back PASSED test_valkey_paused PASSED
|
||
test_pool_exhausted PASSED test_valkey_back PASSED
|
||
test_connection_limit_reached PASSED test_message_failure_keeps_key_free PASSED
|
||
test_pool_keeps_connections PASSED test_database_outage_keeps_key_free PASSED
|
||
test_key_free_after_ttl PASSED
|
||
================ 17 passed, 131 deselected in 60.82s (0:01:00) =================
|
||
Volume mtusi-lab3-failures_postgres_data Removed
|
||
Network mtusi-lab3-failures_default Removed
|
||
|
||
$ make test_isolated # exit 0, 65 с
|
||
PASS: lab3 public API scenario; infrastructure and grading evidence remain separate.
|
||
SKIPPED [1] student-tests/test_idempotency.py:282: one API process (EXPECT_REPLICAS=1): replica checks need the stand with the load balancer
|
||
… (ещё 3 теста реплик с той же причиной)
|
||
================ 127 passed, 4 skipped, 17 deselected in 58.11s ================
|
||
[test_isolated] cleanup
|
||
[test_isolated] results: {'test': 0, 'student_test': 0}
|
||
```
|
||
|
||
## Уборка и рабочий стенд
|
||
|
||
```text
|
||
$ docker compose down -v # в каталоге клона, проект mtusi-lab3
|
||
Volume mtusi-lab3_postgres_data Removed
|
||
Network mtusi-lab3_default Removed
|
||
$ docker ps -a --filter name=failures -q | wc -l
|
||
0
|
||
$ make run_docker # в каталоге рабочего репозитория, exit 0
|
||
$ docker compose ps --format '{{.Name}} {{.Status}}'
|
||
mtusi-lab3-api-1 Up 6 seconds (healthy)
|
||
mtusi-lab3-api-2 Up 6 seconds (healthy)
|
||
mtusi-lab3-haproxy-1 Up 6 seconds (healthy)
|
||
mtusi-lab3-postgres-1 Up 9 seconds (healthy)
|
||
mtusi-lab3-valkey-1 Up 9 seconds (healthy)
|
||
$ make lb_stats
|
||
api-1 172.30.0.5:8080 UP L7OK …
|
||
api-2 172.30.0.4:8080 UP L7OK …
|
||
free slots: 6
|
||
```
|
||
|
||
Итог: все шаги инструкции из настоящего clone прошли с кодом 0 без
|
||
правки файлов клона; дефектов не найдено. Стенд лабы 2
|
||
(`mtusi-lab2_postgres_data`) не затронут.
|