forked from mtusi2026/mtusi2026lab3
617 lines
32 KiB
Plaintext
617 lines
32 KiB
Plaintext
# Сводка сбора доказательств lab3 (2026-11-13T10:49:05Z)
|
||
|
||
00 clean start -> evidence/00-clean-start.txt
|
||
01 окружение -> evidence/01-env.txt
|
||
02 smoke -> evidence/02-smoke.txt: 1 PASS-строк smoke
|
||
03 собственные -> evidence/03-student-checks.txt: 61 PASS, 0 FAIL
|
||
04 балансировка -> evidence/04-load-balancing.txt: реплик увидено: 2 | токен не печатается, повторный вход не выполнялся
|
||
05 failover -> evidence/05-failover.txt: 2 из 2 раундов PASS
|
||
06 persistence -> evidence/06-persistence.txt: PASS: persistence preserved confirmed data and existing session. Hook scope needs operator evidence.
|
||
07 БД и миграции -> evidence/07-db-migrations.txt
|
||
08 БД недоступна -> evidence/08-db-down.txt
|
||
09 конфигурация LB -> evidence/09-lb-config.txt
|
||
10 git hygiene -> evidence/10-git-hygiene.txt
|
||
|
||
=================== evidence/00-clean-start.txt
|
||
# 00 чистый старт (2026-11-13T10:47:04Z)
|
||
$ docker compose down -v
|
||
Container mtusi-lab3-lb-1 Stopping
|
||
Container mtusi-lab3-lb-1 Stopped
|
||
Container mtusi-lab3-lb-1 Removing
|
||
Container mtusi-lab3-lb-1 Removed
|
||
Container mtusi-lab3-api-2 Stopping
|
||
Container mtusi-lab3-api-1 Stopping
|
||
Container mtusi-lab3-api-2 Stopped
|
||
Container mtusi-lab3-api-2 Removing
|
||
Container mtusi-lab3-api-2 Removed
|
||
Container mtusi-lab3-api-1 Stopped
|
||
Container mtusi-lab3-api-1 Removing
|
||
Container mtusi-lab3-api-1 Removed
|
||
Container mtusi-lab3-migrate-1 Stopping
|
||
Container mtusi-lab3-migrate-1 Stopped
|
||
Container mtusi-lab3-migrate-1 Removing
|
||
Container mtusi-lab3-migrate-1 Removed
|
||
Container mtusi-lab3-postgres-1 Stopping
|
||
Container mtusi-lab3-postgres-1 Stopped
|
||
Container mtusi-lab3-postgres-1 Removing
|
||
Container mtusi-lab3-postgres-1 Removed
|
||
Volume mtusi-lab3_pgdata Removing
|
||
Network mtusi-lab3_default Removing
|
||
Volume mtusi-lab3_pgdata Removed
|
||
Network mtusi-lab3_default Removed
|
||
$ sh scripts/setup-secrets.sh
|
||
secrets: ok (значения не печатаются)
|
||
$ docker compose up -d --build
|
||
Compose can now delegate builds to bake for better performance.
|
||
To do so, set COMPOSE_BAKE=true.
|
||
#0 building with "desktop-linux" instance using docker driver
|
||
|
||
#1 [migrate internal] load build definition from Dockerfile
|
||
#1 transferring dockerfile: 535B 0.0s done
|
||
#1 DONE 0.0s
|
||
|
||
#2 [migrate internal] load metadata for docker.io/library/python:3.12.7-slim-bookworm
|
||
#2 DONE 1.0s
|
||
|
||
#3 [migrate internal] load .dockerignore
|
||
#3 transferring context: 216B done
|
||
#3 DONE 0.0s
|
||
|
||
#4 [migrate 1/6] FROM docker.io/library/python:3.12.7-slim-bookworm@sha256:60d9996b6a8a3689d36db740b49f4327be3be09a21122bd02fb8895abb38b50d
|
||
#4 resolve docker.io/library/python:3.12.7-slim-bookworm@sha256:60d9996b6a8a3689d36db740b49f4327be3be09a21122bd02fb8895abb38b50d 0.0s done
|
||
#4 DONE 0.0s
|
||
|
||
#5 [migrate internal] load build context
|
||
#5 transferring context: 336B done
|
||
#5 DONE 0.0s
|
||
|
||
#6 [migrate 3/6] COPY src/requirements.txt .
|
||
#6 CACHED
|
||
|
||
#7 [migrate 4/6] RUN pip install --no-cache-dir -r requirements.txt
|
||
#7 CACHED
|
||
|
||
#8 [migrate 5/6] COPY src/ .
|
||
#8 CACHED
|
||
|
||
#9 [migrate 2/6] WORKDIR /app
|
||
#9 CACHED
|
||
|
||
#10 [migrate 6/6] RUN useradd -r -u 10001 appuser
|
||
#10 CACHED
|
||
|
||
#11 [migrate] exporting to image
|
||
#11 exporting layers done
|
||
#11 exporting manifest sha256:a30ed5463352704213d504d088e29ad605a8e823e3844d2ec04b6859fcd09c96 done
|
||
#11 exporting config sha256:1a3e2292821c81f7394c56e7b40841662d04a48e11543284941bd934583dbb3e done
|
||
#11 exporting attestation manifest sha256:481b70854ef4cec748aa88dc11a7fa7866d3c43994e0e6dd71ad9d50a4f27259 0.0s done
|
||
#11 exporting manifest list sha256:547cee3ccc7cd8de0d12866b807c22536f84eef74f502c99a51dbfbaee17d14f 0.0s done
|
||
#11 naming to docker.io/library/mtusi-lab3-api:1 done
|
||
#11 unpacking to docker.io/library/mtusi-lab3-api:1 0.0s done
|
||
#11 DONE 0.1s
|
||
|
||
#12 [migrate] resolving provenance for metadata file
|
||
#12 DONE 0.0s
|
||
|
||
#13 [api internal] load build definition from Dockerfile
|
||
#13 transferring dockerfile: 535B done
|
||
#13 DONE 0.0s
|
||
|
||
#2 [api internal] load metadata for docker.io/library/python:3.12.7-slim-bookworm
|
||
#2 DONE 1.3s
|
||
|
||
#14 [api internal] load .dockerignore
|
||
#14 transferring context: 216B done
|
||
#14 DONE 0.0s
|
||
|
||
#4 [api 1/6] FROM docker.io/library/python:3.12.7-slim-bookworm@sha256:60d9996b6a8a3689d36db740b49f4327be3be09a21122bd02fb8895abb38b50d
|
||
#4 resolve docker.io/library/python:3.12.7-slim-bookworm@sha256:60d9996b6a8a3689d36db740b49f4327be3be09a21122bd02fb8895abb38b50d 0.0s done
|
||
#4 DONE 0.1s
|
||
|
||
#15 [api internal] load build context
|
||
#15 transferring context: 336B done
|
||
#15 DONE 0.0s
|
||
|
||
#9 [api 2/6] WORKDIR /app
|
||
#9 CACHED
|
||
|
||
#16 [api 4/6] RUN pip install --no-cache-dir -r requirements.txt
|
||
#16 CACHED
|
||
|
||
#17 [api 5/6] COPY src/ .
|
||
#17 CACHED
|
||
|
||
#18 [api 3/6] COPY src/requirements.txt .
|
||
#18 CACHED
|
||
|
||
#19 [api 6/6] RUN useradd -r -u 10001 appuser
|
||
#19 CACHED
|
||
|
||
#20 [api] exporting to image
|
||
#20 exporting layers done
|
||
#20 exporting manifest sha256:b4a7346267f575a3391a0e717d3240bc2790d72e8e2fc92d3f0a650d0bf085dd done
|
||
#20 exporting config sha256:35da67b3e9504f57fdd8f40cc68931fd9ac928b152f04e24320ffc4ab3af8da7 done
|
||
#20 exporting attestation manifest sha256:d9c916aeb304c7e7e8a3ab817f56eaa9ef6da6745131b218b17667d9c810ae73 0.0s done
|
||
#20 exporting manifest list sha256:a78eddcc8ef68cf184bc636847104e5222ec5e832eeccb5ba99bd9272961fdb2
|
||
#20 exporting manifest list sha256:a78eddcc8ef68cf184bc636847104e5222ec5e832eeccb5ba99bd9272961fdb2 0.0s done
|
||
#20 naming to docker.io/library/mtusi-lab3-api:1 done
|
||
#20 unpacking to docker.io/library/mtusi-lab3-api:1 0.0s done
|
||
#20 DONE 0.1s
|
||
|
||
#21 [api] resolving provenance for metadata file
|
||
#21 DONE 0.0s
|
||
api Built
|
||
migrate Built
|
||
Network mtusi-lab3_default Creating
|
||
Network mtusi-lab3_default Created
|
||
Volume "mtusi-lab3_pgdata" Creating
|
||
Volume "mtusi-lab3_pgdata" Created
|
||
Container mtusi-lab3-postgres-1 Creating
|
||
Container mtusi-lab3-postgres-1 Created
|
||
Container mtusi-lab3-migrate-1 Creating
|
||
Container mtusi-lab3-migrate-1 Created
|
||
Container mtusi-lab3-api-2 Creating
|
||
Container mtusi-lab3-api-1 Creating
|
||
Container mtusi-lab3-api-1 Created
|
||
Container mtusi-lab3-api-2 Created
|
||
Container mtusi-lab3-lb-1 Creating
|
||
Container mtusi-lab3-lb-1 Created
|
||
Container mtusi-lab3-postgres-1 Starting
|
||
Container mtusi-lab3-postgres-1 Started
|
||
Container mtusi-lab3-postgres-1 Waiting
|
||
Container mtusi-lab3-postgres-1 Healthy
|
||
Container mtusi-lab3-migrate-1 Starting
|
||
Container mtusi-lab3-migrate-1 Started
|
||
Container mtusi-lab3-postgres-1 Waiting
|
||
Container mtusi-lab3-migrate-1 Waiting
|
||
Container mtusi-lab3-postgres-1 Healthy
|
||
Container mtusi-lab3-migrate-1 Exited
|
||
Container mtusi-lab3-api-2 Starting
|
||
Container mtusi-lab3-api-2 Started
|
||
Container mtusi-lab3-api-1 Starting
|
||
Container mtusi-lab3-api-1 Started
|
||
Container mtusi-lab3-api-2 Waiting
|
||
Container mtusi-lab3-api-1 Waiting
|
||
Container mtusi-lab3-api-2 Healthy
|
||
Container mtusi-lab3-api-1 Healthy
|
||
Container mtusi-lab3-lb-1 Starting
|
||
Container mtusi-lab3-lb-1 Started
|
||
ready через 15 с после запуска up
|
||
|
||
=================== evidence/01-env.txt
|
||
# 01 окружение (2026-11-13T10:47:24Z)
|
||
commit: 0ab3a341aa7ba32363ce43061d4ff02b1f2964af
|
||
git status:
|
||
A .gitattributes
|
||
A Dockerfile
|
||
MM REPORT.md
|
||
A compose.yaml
|
||
A infra/haproxy/haproxy.cfg
|
||
A scripts/collect-evidence.sh
|
||
A scripts/restart.cmd
|
||
A scripts/restart.sh
|
||
A scripts/setup-secrets.sh
|
||
A scripts/stop-one.cmd
|
||
A scripts/stop-one.sh
|
||
A src/app/__init__.py
|
||
A src/app/main.py
|
||
A src/app/migrate.py
|
||
A src/migrations/001_init.sql
|
||
A src/migrations/002_idempotency.sql
|
||
A src/requirements.txt
|
||
A student-tests/lab3_checks.py
|
||
?? evidence/00-clean-start.txt
|
||
?? evidence/01-env.txt
|
||
$ docker version
|
||
client=28.0.4 server=28.0.4 os=linux/amd64
|
||
$ docker compose version
|
||
Docker Compose version v2.34.0-desktop.1
|
||
python: Python 3.11.5
|
||
$ docker compose config --quiet
|
||
compose config: OK
|
||
$ docker compose images
|
||
CONTAINER REPOSITORY TAG IMAGE ID SIZE
|
||
mtusi-lab3-api-1 mtusi-lab3-api 1 a78eddcc8ef6 52.1MB
|
||
mtusi-lab3-api-2 mtusi-lab3-api 1 a78eddcc8ef6 52.1MB
|
||
mtusi-lab3-lb-1 haproxy 2.8.10-alpine 54af6e4943e4 12.2MB
|
||
mtusi-lab3-migrate-1 mtusi-lab3-api 1 a78eddcc8ef6 52.1MB
|
||
mtusi-lab3-postgres-1 postgres 16.4-alpine 5660c2cbfea5 99.2MB
|
||
$ docker compose ps -a
|
||
NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS
|
||
mtusi-lab3-api-1 mtusi-lab3-api:1 "uvicorn app.main:ap…" api 15 seconds ago Up 8 seconds (healthy) 8080/tcp
|
||
mtusi-lab3-api-2 mtusi-lab3-api:1 "uvicorn app.main:ap…" api 15 seconds ago Up 9 seconds (healthy) 8080/tcp
|
||
mtusi-lab3-lb-1 haproxy:2.8.10-alpine "docker-entrypoint.s…" lb 15 seconds ago Up 3 seconds (health: starting) 127.0.0.1:8080->8080/tcp
|
||
mtusi-lab3-migrate-1 mtusi-lab3-api:1 "python -m app.migra…" migrate 15 seconds ago Exited (0) 9 seconds ago
|
||
mtusi-lab3-postgres-1 postgres:16.4-alpine "docker-entrypoint.s…" postgres 15 seconds ago Up 14 seconds (healthy) 5432/tcp
|
||
$ docker volume ls (pgdata)
|
||
local mtusi2026lab2_pgdata
|
||
local mtusi-lab3_pgdata
|
||
$ docker stats --no-stream
|
||
NAME CPU % MEM USAGE / LIMIT
|
||
mtusi-lab3-api-1 0.42% 30.51MiB / 7.694GiB
|
||
mtusi-lab3-api-2 0.33% 34.94MiB / 7.694GiB
|
||
mtusi-lab3-lb-1 0.64% 11.6MiB / 7.694GiB
|
||
mtusi-lab3-postgres-1 1.40% 42.34MiB / 7.694GiB
|
||
$ docker info (лимиты хоста)
|
||
CPUs=16 Mem=8261029888
|
||
|
||
=================== evidence/02-smoke.txt
|
||
# 02 публичные проверки через LB (2026-11-13T10:47:30Z)
|
||
$ python scripts/check_contract.py
|
||
PASS: offline skeleton structure, local refs and Python syntax; application NOT tested.
|
||
exit code: 0
|
||
$ python tests/smoke.py --base-url http://localhost:8080
|
||
PASS: lab3 public API scenario; infrastructure and grading evidence remain separate.
|
||
exit code: 0
|
||
|
||
=================== evidence/03-student-checks.txt
|
||
# 03 собственные проверки (2026-11-13T10:47:32Z)
|
||
$ python student-tests/lab3_checks.py --base-url http://localhost:8080
|
||
PASS: повторный username -> 409
|
||
PASS: пароль короче 12 -> 400
|
||
PASS: лишнее поле -> 400
|
||
PASS: User не содержит пароль/hash/токен
|
||
PASS: гонка одинакового username: ровно один 201, остальные 409
|
||
PASS: неверный пароль и неизвестный пользователь неразличимы (401, тот же code/message/заголовок)
|
||
PASS: вход JSON-телом без Basic -> 401
|
||
PASS: Bearer на POST /auth/sessions -> 401
|
||
PASS: токен >=256 бит, token_type Bearer
|
||
PASS: Basic на бизнес-endpoint -> 401 + WWW-Authenticate: Bearer
|
||
PASS: один X-User-Id доступа не даёт
|
||
PASS: X-User-Id игнорируется: владелец определяется токеном
|
||
PASS: неизвестный токен -> 401
|
||
PASS: X-Request-Id совпадает с request_id в теле ошибки
|
||
PASS: чат с неизвестным участником -> 400
|
||
PASS: после отказа новый чат не появился (нет частичной записи)
|
||
PASS: чат создан с обоими участниками
|
||
PASS: создатель обязан быть среди member_ids -> 400
|
||
PASS: посторонний: GET /chat -> 404
|
||
PASS: посторонний: GET /messages -> 404
|
||
PASS: посторонний не может писать -> 404
|
||
PASS: неверный UUID /chats/not-a-uuid -> 400
|
||
PASS: неверный UUID /chats/not-a-uuid/messages -> 400
|
||
PASS: sender_id в запросе не принимается -> 400
|
||
PASS: пробельный текст -> 400
|
||
PASS: отправитель берётся из токена
|
||
PASS: пагинация limit=2: без повторов, все 6 сообщений
|
||
PASS: cursor от другого чата -> 400
|
||
PASS: ?limit=0 -> 400
|
||
PASS: ?limit=101 -> 400
|
||
PASS: ?limit=abc -> 400
|
||
PASS: ?limit=%2B5 -> 400
|
||
PASS: ?limit=2&limit=3 -> 400
|
||
PASS: тело >1 MiB -> 413
|
||
PASS: не JSON Content-Type -> 415
|
||
PASS: битый JSON -> 400
|
||
PASS: logout -> 204
|
||
PASS: повторный logout с отозванным токеном -> 401
|
||
PASS: отозванный токен -> 401 + WWW-Authenticate: Bearer
|
||
PASS: logout одного пользователя не затрагивает чужие сессии
|
||
PASS: все проверки режима 'main'
|
||
exit code: 0
|
||
$ python student-tests/lab3_checks.py --base-url http://localhost:8080 --mode idem --min-instances 2
|
||
PASS: через LB отвечают >= 2 реплик с одним токеном (X-Instance-Id: 2)
|
||
PASS: повтор с тем же ключом: тот же 201 и то же сообщение
|
||
PASS: повтор не создал дубль
|
||
PASS: тот же ключ с другим телом -> 409
|
||
PASS: тот же ключ и то же тело (другое форматирование JSON) -> тот же результат
|
||
PASS: тот же ключ в другом чате независим
|
||
PASS: тот же ключ у другого пользователя независим
|
||
PASS: нет Idempotency-Key -> 400
|
||
PASS: неверный ключ 'bad key!' -> 400
|
||
PASS: неверный ключ 'a/b' -> 400
|
||
PASS: неверный ключ 'aaaaaaaaaaaa' -> 400
|
||
PASS: неверный ключ '' -> 400
|
||
PASS: посторонний с тем же ключом -> 404 (доступ проверяется при повторе)
|
||
PASS: без токена -> 401
|
||
PASS: 30 параллельных запросов с одним ключом: все 201 и одно и то же сообщение
|
||
PASS: в истории ровно одно такое сообщение
|
||
INFO: параллельные повторы обслужили реплики: ['1f4c3572c169', 'b7deee7dd66b']
|
||
PASS: параллельно один ключ и два разных тела: победитель один, остальным другого тела -> 409
|
||
PASS: создано ровно одно сообщение из конкурирующих
|
||
PASS: повтор с отозванным токеном -> 401
|
||
PASS: все проверки режима 'idem'
|
||
exit code: 0
|
||
|
||
=================== evidence/04-load-balancing.txt
|
||
# 04 балансировка: одна сессия, разные реплики (2026-11-13T10:47:36Z)
|
||
$ docker compose ps api (реплики одного сервиса, без container_name)
|
||
NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS
|
||
mtusi-lab3-api-1 mtusi-lab3-api:1 "uvicorn app.main:ap…" api 25 seconds ago Up 18 seconds (healthy) 8080/tcp
|
||
mtusi-lab3-api-2 mtusi-lab3-api:1 "uvicorn app.main:ap…" api 25 seconds ago Up 19 seconds (healthy) 8080/tcp
|
||
--- ID работающих API-контейнеров (X-Instance-Id = hostname = короткий ID контейнера)
|
||
b7deee7dd66b
|
||
1f4c3572c169
|
||
--- порты API-контейнеров наружу (должно быть пусто: вход только через LB)
|
||
container b7deee7dd66b:
|
||
container 1f4c3572c169:
|
||
--- порты LB
|
||
127.0.0.1:8080
|
||
--- 40 запросов с ОДНИМ токеном к GET /users/me через LB: число ответов на каждую реплику
|
||
20 X-Instance-Id=1f4c3572c169
|
||
20 X-Instance-Id=b7deee7dd66b
|
||
реплик увидено: 2 | токен не печатается, повторный вход не выполнялся
|
||
|
||
=================== evidence/05-failover.txt
|
||
# 05 отказ API-реплики: последовательно каждая из двух (2026-11-13T10:47:38Z)
|
||
hook: scripts/stop-one.cmd
|
||
|
||
=== раунд 1 ===
|
||
--- до
|
||
b7deee7dd66b mtusi-lab3-api-2 Up 21 seconds (healthy)
|
||
1f4c3572c169 mtusi-lab3-api-1 Up 21 seconds (healthy)
|
||
$ python tests/resilience.py --mode failover --action-script scripts/stop-one.cmd
|
||
Executing explicit failover hook; hook output suppressed to avoid leaking secrets.
|
||
{"observed_instances_before": 2, "successful_writes": 114, "failed_attempts": 1, "first_recovery_seconds": 1.703}
|
||
PASS: failover preserved confirmed data and existing session. Hook scope needs operator evidence.
|
||
exit code: 0
|
||
--- после (ровно одна реплика должна быть Exited; остальные Up)
|
||
b7deee7dd66b mtusi-lab3-api-2 Up 38 seconds (healthy)
|
||
1f4c3572c169 mtusi-lab3-api-1 Exited (0) 14 seconds ago
|
||
--- LB сейчас: ответы по репликам (остановленной быть не должно)
|
||
20 x-instance-id: b7deee7dd66b
|
||
--- восстановление: docker compose start api
|
||
Container mtusi-lab3-postgres-1 Waiting
|
||
Container mtusi-lab3-postgres-1 Healthy
|
||
Container mtusi-lab3-migrate-1 Starting
|
||
Container mtusi-lab3-migrate-1 Started
|
||
Container mtusi-lab3-postgres-1 Waiting
|
||
Container mtusi-lab3-migrate-1 Waiting
|
||
Container mtusi-lab3-postgres-1 Healthy
|
||
Container mtusi-lab3-migrate-1 Exited
|
||
Container mtusi-lab3-api-1 Starting
|
||
Container mtusi-lab3-api-1 Started
|
||
обе реплики снова видны через LB через 3 с
|
||
b7deee7dd66b mtusi-lab3-api-2 Up 44 seconds (healthy)
|
||
1f4c3572c169 mtusi-lab3-api-1 Up 3 seconds (health: starting)
|
||
|
||
=== раунд 2 ===
|
||
--- до
|
||
b7deee7dd66b mtusi-lab3-api-2 Up 45 seconds (healthy)
|
||
1f4c3572c169 mtusi-lab3-api-1 Up 3 seconds (health: starting)
|
||
$ python tests/resilience.py --mode failover --action-script scripts/stop-one.cmd
|
||
Executing explicit failover hook; hook output suppressed to avoid leaking secrets.
|
||
{"observed_instances_before": 2, "successful_writes": 122, "failed_attempts": 1, "first_recovery_seconds": 1.125}
|
||
PASS: failover preserved confirmed data and existing session. Hook scope needs operator evidence.
|
||
exit code: 0
|
||
--- после (ровно одна реплика должна быть Exited; остальные Up)
|
||
b7deee7dd66b mtusi-lab3-api-2 Exited (0) 14 seconds ago
|
||
1f4c3572c169 mtusi-lab3-api-1 Up 20 seconds (healthy)
|
||
--- LB сейчас: ответы по репликам (остановленной быть не должно)
|
||
20 x-instance-id: 1f4c3572c169
|
||
--- восстановление: docker compose start api
|
||
Container mtusi-lab3-postgres-1 Waiting
|
||
Container mtusi-lab3-postgres-1 Healthy
|
||
Container mtusi-lab3-migrate-1 Starting
|
||
Container mtusi-lab3-migrate-1 Started
|
||
Container mtusi-lab3-migrate-1 Waiting
|
||
Container mtusi-lab3-postgres-1 Waiting
|
||
Container mtusi-lab3-postgres-1 Healthy
|
||
Container mtusi-lab3-migrate-1 Exited
|
||
Container mtusi-lab3-api-2 Starting
|
||
Container mtusi-lab3-api-2 Started
|
||
обе реплики снова видны через LB через 3 с
|
||
b7deee7dd66b mtusi-lab3-api-2 Up 3 seconds (health: starting)
|
||
1f4c3572c169 mtusi-lab3-api-1 Up 26 seconds (healthy)
|
||
|
||
=================== evidence/06-persistence.txt
|
||
# 06 сохранность при рестарте всего стенда (2026-11-13T10:48:25Z)
|
||
--- до
|
||
/mtusi-lab3-api-1 StartedAt=2026-11-13T10:47:58.653453624Z RestartCount=0
|
||
/mtusi-lab3-api-2 StartedAt=2026-11-13T10:48:21.861831149Z RestartCount=0
|
||
/mtusi-lab3-lb-1 StartedAt=2026-11-13T10:47:23.139431439Z RestartCount=0
|
||
/mtusi-lab3-postgres-1 StartedAt=2026-11-13T10:47:12.124665349Z RestartCount=0
|
||
NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS
|
||
mtusi-lab3-api-1 mtusi-lab3-api:1 "uvicorn app.main:ap…" api About a minute ago Up 27 seconds (healthy) 8080/tcp
|
||
mtusi-lab3-api-2 mtusi-lab3-api:1 "uvicorn app.main:ap…" api About a minute ago Up 4 seconds (health: starting) 8080/tcp
|
||
mtusi-lab3-lb-1 haproxy:2.8.10-alpine "docker-entrypoint.s…" lb About a minute ago Up About a minute (healthy) 127.0.0.1:8080->8080/tcp
|
||
mtusi-lab3-postgres-1 postgres:16.4-alpine "docker-entrypoint.s…" postgres About a minute ago Up About a minute (healthy) 5432/tcp
|
||
$ python tests/resilience.py --mode persistence --action-script scripts/restart.cmd
|
||
Executing explicit persistence hook; hook output suppressed to avoid leaking secrets.
|
||
PASS: persistence preserved confirmed data and existing session. Hook scope needs operator evidence.
|
||
exit code: 0
|
||
--- после (StartedAt должен измениться у postgres, api и lb)
|
||
/mtusi-lab3-api-1 StartedAt=2026-11-13T10:48:29.723218527Z RestartCount=0
|
||
/mtusi-lab3-api-2 StartedAt=2026-11-13T10:48:29.847689238Z RestartCount=0
|
||
/mtusi-lab3-lb-1 StartedAt=2026-11-13T10:48:30.108703104Z RestartCount=0
|
||
/mtusi-lab3-postgres-1 StartedAt=2026-11-13T10:48:28.056213785Z RestartCount=0
|
||
NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS
|
||
mtusi-lab3-api-1 mtusi-lab3-api:1 "uvicorn app.main:ap…" api About a minute ago Up 7 seconds (healthy) 8080/tcp
|
||
mtusi-lab3-api-2 mtusi-lab3-api:1 "uvicorn app.main:ap…" api About a minute ago Up 6 seconds (healthy) 8080/tcp
|
||
mtusi-lab3-lb-1 haproxy:2.8.10-alpine "docker-entrypoint.s…" lb About a minute ago Up 6 seconds (healthy) 127.0.0.1:8080->8080/tcp
|
||
mtusi-lab3-postgres-1 postgres:16.4-alpine "docker-entrypoint.s…" postgres About a minute ago Up 8 seconds (healthy) 5432/tcp
|
||
--- время восстановления одного рестарта (hook + ожидание /health/ready и 2 реплик)
|
||
Container mtusi-lab3-postgres-1 Restarting
|
||
Container mtusi-lab3-postgres-1 Started
|
||
Container mtusi-lab3-api-1 Restarting
|
||
Container mtusi-lab3-api-2 Restarting
|
||
Container mtusi-lab3-lb-1 Restarting
|
||
Container mtusi-lab3-api-2 Started
|
||
Container mtusi-lab3-lb-1 Started
|
||
Container mtusi-lab3-api-1 Started
|
||
Container mtusi-lab3-postgres-1 Running
|
||
Container mtusi-lab3-migrate-1 Created
|
||
Container mtusi-lab3-api-1 Running
|
||
Container mtusi-lab3-api-2 Running
|
||
Container mtusi-lab3-lb-1 Running
|
||
Container mtusi-lab3-postgres-1 Waiting
|
||
Container mtusi-lab3-postgres-1 Healthy
|
||
Container mtusi-lab3-migrate-1 Starting
|
||
Container mtusi-lab3-migrate-1 Started
|
||
Container mtusi-lab3-postgres-1 Waiting
|
||
Container mtusi-lab3-migrate-1 Waiting
|
||
Container mtusi-lab3-postgres-1 Healthy
|
||
Container mtusi-lab3-migrate-1 Exited
|
||
Container mtusi-lab3-api-2 Waiting
|
||
Container mtusi-lab3-api-1 Waiting
|
||
Container mtusi-lab3-api-2 Healthy
|
||
Container mtusi-lab3-api-1 Healthy
|
||
готов через 12 с
|
||
--- данные в БД после рестарта
|
||
users | chats | messages | sessions | idempotency_keys
|
||
-------+-------+----------+----------+------------------
|
||
20 | 8 | 252 | 20 | 252
|
||
(1 row)
|
||
|
||
|
||
=================== evidence/07-db-migrations.txt
|
||
# 07 схема БД и миграции (2026-11-13T10:48:49Z)
|
||
version | applied_at
|
||
---------------------+-------------------------------
|
||
001_init.sql | 2026-11-13 10:47:16.695785+00
|
||
002_idempotency.sql | 2026-11-13 10:47:16.75375+00
|
||
(2 rows)
|
||
|
||
List of relations
|
||
Schema | Name | Type | Owner
|
||
--------+-------------------+-------+-------
|
||
public | chat_members | table | msg
|
||
public | chats | table | msg
|
||
public | idempotency_keys | table | msg
|
||
public | messages | table | msg
|
||
public | schema_migrations | table | msg
|
||
public | sessions | table | msg
|
||
public | users | table | msg
|
||
(7 rows)
|
||
|
||
Table "public.idempotency_keys"
|
||
Column | Type | Collation | Nullable | Default
|
||
--------------+--------------------------+-----------+----------+---------
|
||
user_id | uuid | | not null |
|
||
method | text | | not null |
|
||
path | text | | not null |
|
||
key | text | | not null |
|
||
request_hash | bytea | | not null |
|
||
status_code | integer | | not null |
|
||
response | jsonb | | not null |
|
||
created_at | timestamp with time zone | | not null | now()
|
||
expires_at | timestamp with time zone | | not null |
|
||
Indexes:
|
||
"idempotency_keys_pkey" PRIMARY KEY, btree (user_id, method, path, key)
|
||
"idempotency_expires_idx" btree (expires_at)
|
||
Check constraints:
|
||
"idempotency_keys_key_check" CHECK (key ~ '^[A-Za-z0-9._:-]{1,128}$'::text)
|
||
Foreign-key constraints:
|
||
"idempotency_keys_user_id_fkey" FOREIGN KEY (user_id) REFERENCES users(id)
|
||
|
||
Table "public.sessions"
|
||
Column | Type | Collation | Nullable | Default
|
||
------------+--------------------------+-----------+----------+---------
|
||
token_hash | bytea | | not null |
|
||
user_id | uuid | | not null |
|
||
expires_at | timestamp with time zone | | not null |
|
||
revoked_at | timestamp with time zone | | |
|
||
Indexes:
|
||
"sessions_pkey" PRIMARY KEY, btree (token_hash)
|
||
"sessions_expires_idx" btree (expires_at)
|
||
Foreign-key constraints:
|
||
"sessions_user_id_fkey" FOREIGN KEY (user_id) REFERENCES users(id)
|
||
|
||
Table "public.messages"
|
||
Column | Type | Collation | Nullable | Default
|
||
------------+--------------------------+-----------+----------+-------------------
|
||
id | uuid | | not null |
|
||
chat_id | uuid | | not null |
|
||
sender_id | uuid | | not null |
|
||
text | text | | not null |
|
||
created_at | timestamp with time zone | | not null | clock_timestamp()
|
||
Indexes:
|
||
"messages_pkey" PRIMARY KEY, btree (id)
|
||
"messages_history_idx" btree (chat_id, created_at, id)
|
||
Check constraints:
|
||
"messages_text_check" CHECK (char_length(text) >= 1 AND char_length(text) <= 4000)
|
||
Foreign-key constraints:
|
||
"messages_chat_id_fkey" FOREIGN KEY (chat_id) REFERENCES chats(id) ON DELETE CASCADE
|
||
"messages_sender_id_fkey" FOREIGN KEY (sender_id) REFERENCES users(id)
|
||
|
||
--- пароли хранятся как Argon2id, в sessions только sha256 токена
|
||
hash_prefix | count
|
||
-------------+-------
|
||
$argon2id$ | 20
|
||
(1 row)
|
||
|
||
token_hash_bytes | count
|
||
------------------+-------
|
||
32 | 20
|
||
(1 row)
|
||
|
||
--- миграции выполняет отдельный one-shot сервис migrate (однократно, не репликами)
|
||
NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS
|
||
mtusi-lab3-migrate-1 mtusi-lab3-api:1 "python -m app.migra…" migrate About a minute ago Exited (0) 7 seconds ago
|
||
migrations: ok, latest = 002_idempotency.sql
|
||
migrations: ok, latest = 002_idempotency.sql
|
||
migrations: ok, latest = 002_idempotency.sql
|
||
--- API-реплики стартуют с RUN_MIGRATIONS=0
|
||
SESSION_TTL_SECONDS=3600
|
||
IDEMPOTENCY_TTL_SECONDS=86400
|
||
RUN_MIGRATIONS=0
|
||
--- повторный явный запуск миграции безопасен
|
||
migrations: ok, latest = 002_idempotency.sql
|
||
version
|
||
---------------------
|
||
001_init.sql
|
||
002_idempotency.sql
|
||
(2 rows)
|
||
|
||
|
||
=================== evidence/08-db-down.txt
|
||
# 08 недоступность PostgreSQL (2026-11-13T10:48:55Z)
|
||
$ docker compose stop postgres
|
||
Container mtusi-lab3-postgres-1 Stopping
|
||
Container mtusi-lab3-postgres-1 Stopped
|
||
GET /health/ready (через LB) -> 503 (все backend не готовы, LB отвечает 503)
|
||
GET /api/v1/users/me -> 503
|
||
$ docker compose start postgres
|
||
Container mtusi-lab3-postgres-1 Starting
|
||
Container mtusi-lab3-postgres-1 Started
|
||
ready и 2 реплики снова через 4 с
|
||
NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS
|
||
mtusi-lab3-api-1 mtusi-lab3-api:1 "uvicorn app.main:ap…" api About a minute ago Up 22 seconds (healthy) 8080/tcp
|
||
mtusi-lab3-api-2 mtusi-lab3-api:1 "uvicorn app.main:ap…" api About a minute ago Up 25 seconds (healthy) 8080/tcp
|
||
mtusi-lab3-lb-1 haproxy:2.8.10-alpine "docker-entrypoint.s…" lb About a minute ago Up 25 seconds (healthy) 127.0.0.1:8080->8080/tcp
|
||
mtusi-lab3-postgres-1 postgres:16.4-alpine "docker-entrypoint.s…" postgres About a minute ago Up 3 seconds (healthy) 5432/tcp
|
||
|
||
=================== evidence/09-lb-config.txt
|
||
# 09 настройка LB: проверки и время обнаружения отказа (2026-11-13T10:49:05Z)
|
||
option redispatch 1 # при неудачном соединении последняя попытка уходит на другой backend
|
||
retries 3 # повторяем только установку соединения: запрос ещё не отправлен, это безопасно
|
||
timeout connect 1s
|
||
timeout client 30s
|
||
timeout server 30s
|
||
timeout http-request 10s
|
||
timeout check 1s
|
||
timeout resolve 1s
|
||
timeout retry 1s
|
||
hold valid 1s
|
||
option httpchk
|
||
http-check send meth GET uri /health/ready ver HTTP/1.1 hdr Host api
|
||
http-check expect status 200
|
||
default-server check inter 1s fall 2 rise 2 resolvers docker resolve-prefer ipv4 init-addr none on-marked-down shutdown-sessions
|
||
server-template api 6 api:8080
|
||
Максимальное время обнаружения отказа по конфигурации: inter 1s x fall 2 + timeout check 1s = около 3 с (порог задания: 10 с).
|
||
--- фактическое состояние backend в HAProxy (через stats нет; смотрим логи LB за последние строки)
|
||
172.24.0.1:47318 [13/Nov/2026:10:49:03.928] public api/api2 0/0/0/1/2 200 208 - - ---- 1/1/0/0/0 0/0 "GET /health/live HTTP/1.1"
|
||
172.24.0.1:47324 [13/Nov/2026:10:49:04.000] public api/api2 0/0/0/2/2 200 208 - - ---- 1/1/0/0/0 0/0 "GET /health/live HTTP/1.1"
|
||
172.24.0.1:47326 [13/Nov/2026:10:49:04.054] public api/api2 0/0/0/1/1 200 208 - - ---- 1/1/0/0/0 0/0 "GET /health/live HTTP/1.1"
|
||
172.24.0.1:47338 [13/Nov/2026:10:49:04.102] public api/api2 0/0/0/1/1 200 208 - - ---- 1/1/0/0/0 0/0 "GET /health/live HTTP/1.1"
|
||
172.24.0.1:47346 [13/Nov/2026:10:49:04.150] public api/api2 0/0/0/1/2 200 208 - - ---- 1/1/0/0/0 0/0 "GET /health/live HTTP/1.1"
|
||
[WARNING] (9) : Server api/api1 is UP, reason: Layer7 check passed, code: 200, check duration: 3ms. 2 active and 0 backup servers online. 0 sessions requeued, 0 total in queue.
|
||
Server api/api1 is UP, reason: Layer7 check passed, code: 200, check duration: 3ms. 2 active and 0 backup servers online. 0 sessions requeued, 0 total in queue.
|
||
172.24.0.1:47356 [13/Nov/2026:10:49:04.204] public api/api2 0/0/0/1/1 200 208 - - ---- 1/1/0/0/0 0/0 "GET /health/live HTTP/1.1"
|
||
172.24.0.1:47360 [13/Nov/2026:10:49:04.251] public api/api1 0/0/0/1/1 200 208 - - ---- 1/1/0/0/0 0/0 "GET /health/live HTTP/1.1"
|
||
172.24.0.1:47368 [13/Nov/2026:10:49:04.318] public api/api2 0/0/0/2/2 200 208 - - ---- 1/1/0/0/0 0/0 "GET /health/live HTTP/1.1"
|
||
172.24.0.1:47384 [13/Nov/2026:10:49:04.391] public api/api1 0/0/0/2/3 200 208 - - ---- 1/1/0/0/0 0/0 "GET /health/live HTTP/1.1"
|
||
172.24.0.1:47400 [13/Nov/2026:10:49:04.454] public api/api2 0/0/0/1/1 200 208 - - ---- 1/1/0/0/0 0/0 "GET /health/live HTTP/1.1"
|
||
172.24.0.1:47412 [13/Nov/2026:10:49:04.527] public api/api1 0/0/0/2/2 200 208 - - ---- 1/1/0/0/0 0/0 "GET /health/live HTTP/1.1"
|
||
172.24.0.1:47420 [13/Nov/2026:10:49:04.584] public api/api2 0/0/0/2/2 200 208 - - ---- 1/1/0/0/0 0/0 "GET /health/live HTTP/1.1"
|
||
172.24.0.1:47424 [13/Nov/2026:10:49:04.656] public api/api1 0/0/0/1/1 200 208 - - ---- 1/1/0/0/0 0/0 "GET /health/live HTTP/1.1"
|
||
|
||
=================== evidence/10-git-hygiene.txt
|
||
# 10 секреты и volumes вне Git (2026-11-13T10:49:05Z)
|
||
$ git check-ignore -v secrets/pg_password secrets/database_url .env
|
||
.gitignore:5:secrets/ secrets/pg_password
|
||
.gitignore:5:secrets/ secrets/database_url
|
||
.gitignore:2:.env .env
|
||
$ отслеживаемые файлы, похожие на секреты:
|
||
нет
|