forked from mtusi2026/mtusi2026lab3
Реализовать стенд лабораторной 3: две API-реплики и балансировка
FastAPI + PostgreSQL как единый источник истины: пользователи, Basic/Bearer-сессии, чаты, сообщения. Сессии и идемпотентные ключи хранятся в БД, поэтому реплики взаимозаменяемы. Общая идемпотентность POST сообщения по Idempotency-Key, включая конкурентный повтор через разные реплики. compose.yaml: postgres, one-shot migrate, api1, api2 и nginx как единственная публичная точка входа. Добавлены scripts/stop-one.sh и scripts/restart.sh, student-tests, evidence и заполненный REPORT.md.
This commit is contained in:
@@ -0,0 +1 @@
|
||||
PASS: offline skeleton structure, local refs and Python syntax; application NOT tested.
|
||||
@@ -0,0 +1,2 @@
|
||||
{"concurrent_requests": 40, "instances": ["api-1", "api-2"], "stored_copies": 1}
|
||||
PASS: one Idempotency-Key, concurrent replicas, exactly one message
|
||||
@@ -0,0 +1,25 @@
|
||||
users
|
||||
-------
|
||||
40
|
||||
(1 row)
|
||||
|
||||
chats
|
||||
-------
|
||||
13
|
||||
(1 row)
|
||||
|
||||
messages
|
||||
----------
|
||||
4171
|
||||
(1 row)
|
||||
|
||||
sessions
|
||||
----------
|
||||
37
|
||||
(1 row)
|
||||
|
||||
idempotency_keys
|
||||
------------------
|
||||
4171
|
||||
(1 row)
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS
|
||||
mtusi-lab3-api1-1 mtusi-lab3-api:1.0.0 "uvicorn app.main:ap…" api1 5 minutes ago Exited (0) 30 seconds ago
|
||||
mtusi-lab3-api2-1 mtusi-lab3-api:1.0.0 "uvicorn app.main:ap…" api2 5 minutes ago Up 2 minutes (healthy) 8080/tcp
|
||||
mtusi-lab3-lb-1 nginx:1.26.2-alpine "/docker-entrypoint.…" lb 5 minutes ago Up 2 minutes (healthy) 0.0.0.0:8080->8080/tcp, [::]:8080->8080/tcp
|
||||
mtusi-lab3-migrate-1 mtusi-lab3-api:1.0.0 "python -m app.migra…" migrate 5 minutes ago Exited (0) 5 minutes ago
|
||||
mtusi-lab3-postgres-1 postgres:16.4-alpine "docker-entrypoint.s…" postgres 5 minutes ago Up 2 minutes (healthy) 5432/tcp
|
||||
@@ -0,0 +1,3 @@
|
||||
Executing explicit failover hook; hook output suppressed to avoid leaking secrets.
|
||||
{"observed_instances_before": 2, "successful_writes": 87, "failed_attempts": 0, "first_recovery_seconds": 0.648}
|
||||
PASS: failover preserved confirmed data and existing session. Hook scope needs operator evidence.
|
||||
@@ -0,0 +1,6 @@
|
||||
NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS
|
||||
mtusi-lab3-api1-1 mtusi-lab3-api:1.0.0 "uvicorn app.main:ap…" api1 8 minutes ago Exited (0) 33 seconds ago
|
||||
mtusi-lab3-api2-1 mtusi-lab3-api:1.0.0 "uvicorn app.main:ap…" api2 8 minutes ago Up 4 minutes (healthy) 8080/tcp
|
||||
mtusi-lab3-lb-1 nginx:1.26.2-alpine "/docker-entrypoint.…" lb 8 minutes ago Up 52 seconds (healthy) 0.0.0.0:8080->8080/tcp, [::]:8080->8080/tcp
|
||||
mtusi-lab3-migrate-1 mtusi-lab3-api:1.0.0 "python -m app.migra…" migrate 8 minutes ago Exited (0) 53 seconds ago
|
||||
mtusi-lab3-postgres-1 postgres:16.4-alpine "docker-entrypoint.s…" postgres 8 minutes ago Up 4 minutes (healthy) 5432/tcp
|
||||
@@ -0,0 +1,3 @@
|
||||
Executing explicit failover hook; hook output suppressed to avoid leaking secrets.
|
||||
{"observed_instances_before": 2, "successful_writes": 89, "failed_attempts": 0, "first_recovery_seconds": 0.649}
|
||||
PASS: failover preserved confirmed data and existing session. Hook scope needs operator evidence.
|
||||
@@ -0,0 +1,6 @@
|
||||
NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS
|
||||
mtusi-lab3-api1-1 mtusi-lab3-api:1.0.0 "uvicorn app.main:ap…" api1 9 minutes ago Exited (0) 15 seconds ago
|
||||
mtusi-lab3-api2-1 mtusi-lab3-api:1.0.0 "uvicorn app.main:ap…" api2 9 minutes ago Up 5 minutes (healthy) 8080/tcp
|
||||
mtusi-lab3-lb-1 nginx:1.26.2-alpine "/docker-entrypoint.…" lb 9 minutes ago Up 2 minutes (healthy) 0.0.0.0:8080->8080/tcp, [::]:8080->8080/tcp
|
||||
mtusi-lab3-migrate-1 mtusi-lab3-api:1.0.0 "python -m app.migra…" migrate 9 minutes ago Exited (0) 54 seconds ago
|
||||
mtusi-lab3-postgres-1 postgres:16.4-alpine "docker-entrypoint.s…" postgres 9 minutes ago Up 5 minutes (healthy) 5432/tcp
|
||||
@@ -0,0 +1,3 @@
|
||||
Executing explicit failover hook; hook output suppressed to avoid leaking secrets.
|
||||
{"observed_instances_before": 2, "successful_writes": 85, "failed_attempts": 0, "first_recovery_seconds": 1.434}
|
||||
PASS: failover preserved confirmed data and existing session. Hook scope needs operator evidence.
|
||||
@@ -0,0 +1,6 @@
|
||||
NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS
|
||||
mtusi-lab3-api1-1 mtusi-lab3-api:1.0.0 "uvicorn app.main:ap…" api1 11 minutes ago Up About a minute (healthy) 8080/tcp
|
||||
mtusi-lab3-api2-1 mtusi-lab3-api:1.0.0 "uvicorn app.main:ap…" api2 11 minutes ago Exited (0) 15 seconds ago
|
||||
mtusi-lab3-lb-1 nginx:1.26.2-alpine "/docker-entrypoint.…" lb 11 minutes ago Up 4 minutes (healthy) 0.0.0.0:8080->8080/tcp, [::]:8080->8080/tcp
|
||||
mtusi-lab3-migrate-1 mtusi-lab3-api:1.0.0 "python -m app.migra…" migrate 11 minutes ago Exited (0) About a minute ago
|
||||
mtusi-lab3-postgres-1 postgres:16.4-alpine "docker-entrypoint.s…" postgres 11 minutes ago Up 7 minutes (healthy) 5432/tcp
|
||||
@@ -0,0 +1,3 @@
|
||||
Executing explicit failover hook; hook output suppressed to avoid leaking secrets.
|
||||
{"observed_instances_before": 2, "successful_writes": 88, "failed_attempts": 0, "first_recovery_seconds": 0.65}
|
||||
PASS: failover preserved confirmed data and existing session. Hook scope needs operator evidence.
|
||||
@@ -0,0 +1,6 @@
|
||||
NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS
|
||||
mtusi-lab3-api1-1 mtusi-lab3-api:1.0.0 "uvicorn app.main:ap…" api1 18 minutes ago Up 5 minutes (healthy) 8080/tcp
|
||||
mtusi-lab3-api2-1 mtusi-lab3-api:1.0.0 "uvicorn app.main:ap…" api2 18 minutes ago Exited (0) 15 seconds ago
|
||||
mtusi-lab3-lb-1 nginx:1.26.2-alpine "/docker-entrypoint.…" lb 36 minutes ago Up 5 minutes (healthy) 0.0.0.0:8080->8080/tcp, [::]:8080->8080/tcp
|
||||
mtusi-lab3-migrate-1 mtusi-lab3-api:1.0.0 "python -m app.migra…" migrate 18 minutes ago Exited (0) 5 minutes ago
|
||||
mtusi-lab3-postgres-1 postgres:16.4-alpine "docker-entrypoint.s…" postgres 36 minutes ago Up 17 minutes (healthy) 5432/tcp
|
||||
@@ -0,0 +1,3 @@
|
||||
Executing explicit failover hook; hook output suppressed to avoid leaking secrets.
|
||||
{"observed_instances_before": 2, "successful_writes": 90, "failed_attempts": 0, "first_recovery_seconds": 0.546}
|
||||
PASS: failover preserved confirmed data and existing session. Hook scope needs operator evidence.
|
||||
@@ -0,0 +1,6 @@
|
||||
NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS
|
||||
mtusi-lab3-api1-1 mtusi-lab3-api:1.0.0 "uvicorn app.main:ap…" api1 9 minutes ago Exited (0) 15 seconds ago
|
||||
mtusi-lab3-api2-1 mtusi-lab3-api:1.0.0 "uvicorn app.main:ap…" api2 9 minutes ago Up 7 minutes (healthy) 8080/tcp
|
||||
mtusi-lab3-lb-1 nginx:1.26.2-alpine "/docker-entrypoint.…" lb 27 minutes ago Up 56 seconds (healthy) 0.0.0.0:8080->8080/tcp, [::]:8080->8080/tcp
|
||||
mtusi-lab3-migrate-1 mtusi-lab3-api:1.0.0 "python -m app.migra…" migrate 9 minutes ago Exited (0) 9 minutes ago
|
||||
mtusi-lab3-postgres-1 postgres:16.4-alpine "docker-entrypoint.s…" postgres 27 minutes ago Up 7 minutes (healthy) 5432/tcp
|
||||
@@ -0,0 +1,3 @@
|
||||
Executing explicit failover hook; hook output suppressed to avoid leaking secrets.
|
||||
{"observed_instances_before": 2, "successful_writes": 85, "failed_attempts": 0, "first_recovery_seconds": 0.558}
|
||||
PASS: failover preserved confirmed data and existing session. Hook scope needs operator evidence.
|
||||
@@ -0,0 +1,5 @@
|
||||
NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS
|
||||
mtusi-lab3-api1-1 mtusi-lab3-api:1.0.0 "uvicorn app.main:ap…" api1 19 minutes ago Up 6 minutes (healthy) 8080/tcp
|
||||
mtusi-lab3-api2-1 mtusi-lab3-api:1.0.0 "uvicorn app.main:ap…" api2 19 minutes ago Up 11 seconds (healthy) 8080/tcp
|
||||
mtusi-lab3-lb-1 nginx:1.26.2-alpine "/docker-entrypoint.…" lb 37 minutes ago Up 10 seconds (healthy) 0.0.0.0:8080->8080/tcp, [::]:8080->8080/tcp
|
||||
mtusi-lab3-postgres-1 postgres:16.4-alpine "docker-entrypoint.s…" postgres 37 minutes ago Up 18 minutes (healthy) 5432/tcp
|
||||
@@ -0,0 +1,11 @@
|
||||
READINESS: {"status":"ok"}
|
||||
X-Instance-Id=api-2
|
||||
X-Instance-Id=api-1
|
||||
X-Instance-Id=api-2
|
||||
X-Instance-Id=api-1
|
||||
X-Instance-Id=api-2
|
||||
X-Instance-Id=api-1
|
||||
X-Instance-Id=api-2
|
||||
X-Instance-Id=api-1
|
||||
X-Instance-Id=api-2
|
||||
X-Instance-Id=api-1
|
||||
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"lab": 3,
|
||||
"workload": "closed-loop POST messages; no automatic retries",
|
||||
"requested_duration_seconds": 15.0,
|
||||
"elapsed_seconds": 15.032,
|
||||
"concurrency": 4,
|
||||
"successful_requests": 3722,
|
||||
"failed_requests": 0,
|
||||
"error_ratio": 0.0,
|
||||
"successful_rps": 247.605,
|
||||
"successful_latency_ms": {
|
||||
"p50": 16.0,
|
||||
"p95": 32.0,
|
||||
"p99": 46.0
|
||||
},
|
||||
"note": "Latency percentiles cover successes only. Timeouts/errors are counted separately; closed-loop has coordinated omission and client overhead."
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"lab": 3,
|
||||
"workload": "closed-loop POST messages; no automatic retries",
|
||||
"requested_duration_seconds": 15.0,
|
||||
"elapsed_seconds": 15.032,
|
||||
"concurrency": 4,
|
||||
"successful_requests": 3722,
|
||||
"failed_requests": 0,
|
||||
"error_ratio": 0.0,
|
||||
"successful_rps": 247.605,
|
||||
"successful_latency_ms": {
|
||||
"p50": 16.0,
|
||||
"p95": 32.0,
|
||||
"p99": 46.0
|
||||
},
|
||||
"note": "Latency percentiles cover successes only. Timeouts/errors are counted separately; closed-loop has coordinated omission and client overhead."
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
Executing explicit persistence hook; hook output suppressed to avoid leaking secrets.
|
||||
PASS: persistence preserved confirmed data and existing session. Hook scope needs operator evidence.
|
||||
@@ -0,0 +1,2 @@
|
||||
Executing explicit persistence hook; hook output suppressed to avoid leaking secrets.
|
||||
PASS: persistence preserved confirmed data and existing session. Hook scope needs operator evidence.
|
||||
@@ -0,0 +1,12 @@
|
||||
BEFORE
|
||||
-------
|
||||
/mtusi-lab3-postgres-1 2026-11-07T12:18:04.238732906Z
|
||||
/mtusi-lab3-api1-1 2026-11-07T12:24:49.374406167Z
|
||||
/mtusi-lab3-api2-1 2026-11-07T12:26:23.168391355Z
|
||||
/mtusi-lab3-lb-1 2026-11-07T12:21:51.698457822Z
|
||||
AFTER
|
||||
-----
|
||||
/mtusi-lab3-postgres-1 2026-11-07T12:26:32.284192891Z
|
||||
/mtusi-lab3-api1-1 2026-11-07T12:26:32.573504264Z
|
||||
/mtusi-lab3-api2-1 2026-11-07T12:26:32.646884829Z
|
||||
/mtusi-lab3-lb-1 2026-11-07T12:26:32.434680808Z
|
||||
@@ -0,0 +1,2 @@
|
||||
{"requests": 12, "instances": ["api-2", "api-1", "api-2", "api-1", "api-2", "api-1", "api-2", "api-1", "api-2", "api-1", "api-2", "api-1"]}
|
||||
PASS: one bearer session served by both replicas without re-login
|
||||
@@ -0,0 +1 @@
|
||||
PASS: lab3 public API scenario; infrastructure and grading evidence remain separate.
|
||||
@@ -0,0 +1 @@
|
||||
PASS: lab3 public API scenario; infrastructure and grading evidence remain separate.
|
||||
@@ -0,0 +1 @@
|
||||
PASS: lab3 public API scenario; infrastructure and grading evidence remain separate.
|
||||
@@ -0,0 +1,6 @@
|
||||
NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS
|
||||
mtusi-lab3-api1-1 mtusi-lab3-api:1.0.0 "uvicorn app.main:ap…" api1 28 minutes ago Up 36 seconds (healthy) 8080/tcp
|
||||
mtusi-lab3-api2-1 mtusi-lab3-api:1.0.0 "uvicorn app.main:ap…" api2 28 minutes ago Exited (0) 15 seconds ago
|
||||
mtusi-lab3-lb-1 nginx:1.26.2-alpine "/docker-entrypoint.…" lb 46 minutes ago Up 37 seconds (healthy) 0.0.0.0:8080->8080/tcp, [::]:8080->8080/tcp
|
||||
mtusi-lab3-migrate-1 mtusi-lab3-api:1.0.0 "python -m app.migra…" migrate 28 minutes ago Exited (0) 9 minutes ago
|
||||
mtusi-lab3-postgres-1 postgres:16.4-alpine "docker-entrypoint.s…" postgres 46 minutes ago Up 37 seconds (healthy) 5432/tcp
|
||||
@@ -0,0 +1,3 @@
|
||||
Executing explicit failover hook; hook output suppressed to avoid leaking secrets.
|
||||
{"observed_instances_before": 2, "successful_writes": 85, "failed_attempts": 0, "first_recovery_seconds": 0.539}
|
||||
PASS: failover preserved confirmed data and existing session. Hook scope needs operator evidence.
|
||||
@@ -0,0 +1,2 @@
|
||||
{"concurrent_requests": 40, "instances": ["api-1", "api-2"], "stored_copies": 1}
|
||||
PASS: one Idempotency-Key, concurrent replicas, exactly one message
|
||||
@@ -0,0 +1,2 @@
|
||||
Executing explicit persistence hook; hook output suppressed to avoid leaking secrets.
|
||||
PASS: persistence preserved confirmed data and existing session. Hook scope needs operator evidence.
|
||||
@@ -0,0 +1,2 @@
|
||||
{"requests": 12, "instances": ["api-2", "api-1", "api-2", "api-1", "api-2", "api-1", "api-2", "api-1", "api-2", "api-1", "api-2", "api-1"]}
|
||||
PASS: one bearer session served by both replicas without re-login
|
||||
@@ -0,0 +1 @@
|
||||
PASS: lab3 public API scenario; infrastructure and grading evidence remain separate.
|
||||
Reference in New Issue
Block a user