Собрать стенд lab3 с двумя репликами API за Traefik.

Общие PostgreSQL, Valkey и идемпотентность сообщений нужны, чтобы чтение и запись переживали остановку одной реплики.
This commit is contained in:
samsik
2026-10-23 01:14:48 +03:00
parent 0ab3a341aa
commit eb9c378b9c
28 changed files with 2335 additions and 37 deletions
+18
View File
@@ -0,0 +1,18 @@
Дата: 2026-10-23
Команда:
python3 tests/resilience.py --mode failover --action-script scripts/stop-one.sh --base-url http://127.0.0.1:8080
Executing explicit failover hook; hook output suppressed to avoid leaking secrets.
{"observed_instances_before": 2, "successful_writes": 139, "failed_attempts": 4, "first_recovery_seconds": 3.56}
PASS: failover preserved confirmed data and existing session. Hook scope needs operator evidence.
Сразу после теста:
mtusi-lab3-api-3 Exited (0) — остановлен hook и оставлен остановленным
mtusi-lab3-api-4 Up (healthy) — продолжал обслуживать LB
X-Instance-Id совпадает с hostname контейнера. stop-one.sh ищет контейнер сервиса api
с этим hostname или с коротким id и вызывает docker stop -t 8.
restart: unless-stopped после docker stop контейнер сам не поднимает.
Поочерёдный отказ каждой реплики и цифры RPS — в evidence/grade4.json.
+169
View File
@@ -0,0 +1,169 @@
{
"date": "2026-10-22T21:59:17Z",
"platform": "Linux-6.18.54.1-microsoft-standard-WSL2-x86_64-with-glibc2.35",
"cpu_count": 20,
"workload": "closed-loop POST, concurrency 4, client timeout 3s, no client retry",
"observed_instances": [
"4cd3b03e049d",
"ee551154827e"
],
"parallel_idempotency": {
"requests": 8,
"unique_message_ids": 1,
"instances": [
"4cd3b03e049d",
"ee551154827e"
]
},
"baseline": {
"seconds": 8.009,
"successful_requests": 3182,
"failed_requests": 0,
"successful_rps": 397.291,
"error_ratio": 0.0,
"success_latency_ms": {
"p50": 4.299,
"p95": 59.098,
"p99": 67.737
},
"instances": [
"4cd3b03e049d",
"ee551154827e"
]
},
"failovers": [
{
"target": "4cd3b03e049d",
"stop_hook_exit": 0,
"stop_hook_seconds": 3.703,
"window": {
"seconds": 9.706,
"successful_requests": 1664,
"failed_requests": 154,
"successful_rps": 171.446,
"error_ratio": 0.084708,
"success_latency_ms": {
"p50": 8.807,
"p95": 75.37,
"p99": 93.708
},
"instances": [
"4cd3b03e049d",
"ee551154827e"
]
},
"first_other_replica_success_seconds": 0.034,
"target_seen_after_hook_returned": false,
"instances_after_hook": [
"ee551154827e"
],
"restore_until_target_seen_seconds": 5.324,
"instances_after_restore": [
"4cd3b03e049d",
"ee551154827e"
],
"restore_command_seconds": 7.031
},
{
"target": "ee551154827e",
"stop_hook_exit": 0,
"stop_hook_seconds": 3.812,
"window": {
"seconds": 9.816,
"successful_requests": 1693,
"failed_requests": 40,
"successful_rps": 172.474,
"error_ratio": 0.023081,
"success_latency_ms": {
"p50": 10.399,
"p95": 74.827,
"p99": 96.476
},
"instances": [
"4cd3b03e049d",
"ee551154827e"
]
},
"first_other_replica_success_seconds": 0.003,
"target_seen_after_hook_returned": false,
"instances_after_hook": [
"4cd3b03e049d"
],
"restore_until_target_seen_seconds": 6.064,
"instances_after_restore": [
"4cd3b03e049d",
"ee551154827e"
],
"restore_command_seconds": 7.79
}
],
"images_before_roll": [
"sha256:d1cb2d180884"
],
"images_after_roll": [
"sha256:3ba24670218f"
],
"rolling_under_load": {
"seconds": 34.863,
"successful_requests": 12894,
"failed_requests": 80,
"successful_rps": 369.843,
"error_ratio": 0.006166,
"success_latency_ms": {
"p50": 4.665,
"p95": 59.016,
"p99": 77.441
},
"instances": [
"11f3266202c8",
"210b73040413",
"4cd3b03e049d",
"ee551154827e"
],
"exit": 0,
"stderr_tail": "PRECATED: The legacy builder is deprecated and will be removed in a future release.\n Install the buildx component to build images with BuildKit:\n https://docs.docker.com/go/buildx/\n\n Container mtusi-lab3-api-1 Running\n Container mtusi-lab3-api-2 Running\n Container mtusi-lab3-api-3 Creating\n Container mtusi-lab3-api-3 Created\n Container mtusi-lab3-api-3 Starting\n Container mtusi-lab3-api-3 Started\n Container mtusi-lab3-api-2 Running\n Container mtusi-lab3-api-3 Running\n Container mtusi-lab3-api-2 Running\n Container mtusi-lab3-api-3 Running\n Container mtusi-lab3-api-4 Creating\n Container mtusi-lab3-api-4 Created\n Container mtusi-lab3-api-4 Starting\n Container mtusi-lab3-api-4 Started\n Container mtusi-lab3-api-3 Running\n Container mtusi-lab3-api-4 Running\n"
},
"container_limits": [
{
"name": "mtusi-lab3-api-3",
"nano_cpus": 500000000,
"memory_bytes": 268435456,
"published": "{\"8080/tcp\":null}"
},
{
"name": "mtusi-lab3-api-4",
"nano_cpus": 500000000,
"memory_bytes": 268435456,
"published": "{\"8080/tcp\":null}"
},
{
"name": "mtusi-lab3-lb-1",
"nano_cpus": 250000000,
"memory_bytes": 134217728,
"published": "{\"80/tcp\":null,\"8080/tcp\":[{\"HostIp\":\"127.0.0.1\",\"HostPort\":\"8080\"}]}"
},
{
"name": "mtusi-lab3-postgres-1",
"nano_cpus": 750000000,
"memory_bytes": 536870912,
"published": "{\"5432/tcp\":null}"
},
{
"name": "mtusi-lab3-valkey-1",
"nano_cpus": 250000000,
"memory_bytes": 134217728,
"published": "{\"6379/tcp\":null}"
}
],
"lb_timeouts": {
"check_interval_seconds": 1,
"unhealthy_after_failures": 1,
"check_timeout_seconds": 1,
"max_detection_seconds": 2,
"connect_timeout_seconds": 1,
"server_timeout_seconds": 8,
"client_timeout_seconds": 8,
"drain_seconds": 3,
"stop_grace_seconds": 10
}
}
+14
View File
@@ -0,0 +1,14 @@
Дата: 2026-10-23
Команда:
python3 tests/student_level4.py --base-url http://127.0.0.1:8080
PASS: level4 spread=4cd3b03e049d,ee551154827e parallel_instances=4cd3b03e049d,ee551154827e
8 параллельных POST с одним Idempotency-Key и одним телом дали одно сообщение.
Оба запроса дошли до разных реплик. Повтор с другим телом — 409.
Одинаковый ключ у двух пользователей создал два разных сообщения.
После rolling update тот же тест:
PASS: level4 spread=11f3266202c8,210b73040413 parallel_instances=11f3266202c8,210b73040413
+18
View File
@@ -0,0 +1,18 @@
Дата: 2026-10-23
Команда:
python3 tests/resilience.py --mode persistence --action-script scripts/restart.sh --base-url http://127.0.0.1:8080
Executing explicit persistence hook; hook output suppressed to avoid leaking secrets.
PASS: persistence preserved confirmed data and existing session. Hook scope needs operator evidence.
scripts/restart.sh выполняет:
docker compose --env-file .env -f compose.yaml restart api postgres valkey
Volumes не удаляются. После теста на месте:
mtusi-lab3_pgdata
mtusi-lab3_valkeydata
docker compose ps после hook: api-1 и api-2 Up (healthy), postgres Up (healthy), valkey Up (healthy).
Контейнеры те же (CREATED не сброшен), процессы перезапущены (Up несколько секунд).
Migrate повторно данные не заливает.
+8
View File
@@ -0,0 +1,8 @@
Дата: 2026-10-23
Команда (WSL Ubuntu, Python 3.10, стенд уже поднят):
python3 tests/smoke.py --base-url http://127.0.0.1:8080
PASS: lab3 public API scenario; infrastructure and grading evidence remain separate.
Повтор после смены статического конфига Traefik (aliasHeadersStrategy) — тот же PASS.