forked from mtusi2026/mtusi2026lab3
lab3: выполнение и доказательтсва
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
# balancing: balancing, shared sessions and data, X-Instance-Id
|
||||
# date: 2026-10-14 20:24:12, commit: 0ab3a34 + uncommitted changes
|
||||
# command: python.exe student-tests/test_balancing.py
|
||||
# exit code: 0, 1.3 s
|
||||
|
||||
20 x GET /users/me with one token -> replicas: {'9737b915ff2f': 10, '58542a53644c': 10}
|
||||
PASS: one session works on every replica, no second login (sessions are shared in Redis)
|
||||
message written by 58542a53644c; read back by ['58542a53644c', '9737b915ff2f']
|
||||
PASS: a message written via one replica is read right away via another (shared PostgreSQL)
|
||||
logout on 9737b915ff2f; old token then rejected by ['58542a53644c', '9737b915ff2f']
|
||||
PASS: logout on one replica revokes the session on all of them
|
||||
first POST on 9737b915ff2f -> 201 a8111033-9f9c-4d32-8260-ec76d289aace; same key on 58542a53644c -> 201 a8111033-9f9c-4d32-8260-ec76d289aace
|
||||
PASS: Idempotency-Key is shared: a retry through another replica returns the same message
|
||||
statuses [200, 200, 201, 400, 401, 404, 409]: every answer has X-Instance-Id of a running container ['58542a53644c', '9737b915ff2f']; api containers: ['58542a53644c', '9737b915ff2f']
|
||||
PASS: X-Instance-Id is in every response and points to a real container
|
||||
5 passed, 0 failed
|
||||
@@ -0,0 +1,6 @@
|
||||
# check: offline contract check (make check)
|
||||
# date: 2026-10-14 20:24:08, commit: 0ab3a34 + uncommitted changes
|
||||
# command: python.exe scripts/check_contract.py
|
||||
# exit code: 0, 0.1 s
|
||||
|
||||
PASS: offline skeleton structure, local refs and Python syntax; application NOT tested.
|
||||
@@ -0,0 +1,21 @@
|
||||
# db: PostgreSQL: rollback, FK, Argon2id, unique keys, migrations
|
||||
# date: 2026-10-14 20:24:29, commit: 0ab3a34 + uncommitted changes
|
||||
# command: python.exe student-tests/test_db.py
|
||||
# exit code: 0, 10.2 s
|
||||
|
||||
chat with unknown member -> 400; rows with this title: 0; chats without members: 0; chats insert counter: 117 -> 118
|
||||
PASS: chat row was inserted and then rolled back together with members
|
||||
direct INSERT of a message from a non-member -> exit code 1: ERROR: insert or update on table "messages" violates foreign key constraint "messages_chat_id_sender_id_fkey"
|
||||
PASS: the database itself rejects a message from a non-member
|
||||
stored password: $argon2id$v=19$m=12288,t=3,p=1$... (length 97)
|
||||
PASS: password is stored as Argon2id hash
|
||||
unique constraint on users: UNIQUE (username)
|
||||
PASS: username is unique in the database
|
||||
applied migrations: 001_init.sql,002_text_as_bytes.sql,003_idempotency.sql; running the migrate service once more
|
||||
after the second run: 001_init.sql,002_text_as_bytes.sql,003_idempotency.sql; log: Migrations applied: none (schema is up to date)
|
||||
PASS: migrations are applied once, a repeated run does nothing
|
||||
api replicas that checked the schema at start: 4; api log lines 'Migrations applied': 0; migrate service: Exited (0) 38 seconds ago
|
||||
PASS: only the migrate service applies migrations, replicas wait for the schema
|
||||
unique constraint for Idempotency-Key: UNIQUE (chat_id, sender_id, idempotency_key)
|
||||
PASS: one message per (chat, sender, Idempotency-Key) is enforced by the database
|
||||
7 passed, 0 failed
|
||||
@@ -0,0 +1,13 @@
|
||||
# expiry: session TTL=2 s, then normal TTL
|
||||
# date: 2026-10-14 20:27:07, commit: 0ab3a34 + uncommitted changes
|
||||
# command: python.exe student-tests/test_expiry.py
|
||||
# exit code: 0, 17.1 s
|
||||
|
||||
recreating api with SESSION_TTL_SECONDS=2
|
||||
session issued, expires in 2.00 s; Redis TTL of the key: 1700 ms
|
||||
before expiry: GET /users/me -> 200
|
||||
after expiry: GET /users/me -> 401; key exists in Redis: 0
|
||||
recreating api with SESSION_TTL_SECONDS from .env
|
||||
normal API again: new session expires in 3600 s
|
||||
PASS: session expires after SESSION_TTL_SECONDS and is rejected with 401
|
||||
1 passed, 0 failed
|
||||
@@ -0,0 +1,79 @@
|
||||
=== Data volume
|
||||
messages_total | messages_in_big_chat
|
||||
----------------+----------------------
|
||||
48658 | 15000
|
||||
|
||||
|
||||
=== History index
|
||||
indexdef
|
||||
----------------------------------------------------------------------------------------
|
||||
CREATE INDEX messages_history ON public.messages USING btree (chat_id, created_at, id)
|
||||
|
||||
|
||||
=== 1. First page: limit=50, the app asks for 51 rows to know if there is a next page
|
||||
QUERY PLAN
|
||||
------------------------------------------------------------------------------------------------
|
||||
Limit (actual time=0.007..0.011 rows=51 loops=1)
|
||||
Buffers: shared hit=4
|
||||
-> Index Scan using messages_history on messages (actual time=0.006..0.009 rows=51 loops=1)
|
||||
Index Cond: (chat_id = 'b246d1e6-d41a-4111-aad6-c0474ab30641'::uuid)
|
||||
Buffers: shared hit=4
|
||||
Planning:
|
||||
Buffers: shared hit=7
|
||||
Planning Time: 0.073 ms
|
||||
Execution Time: 0.020 ms
|
||||
|
||||
|
||||
=== 2. Page after the 10000th message by keyset cursor (this is what the app does)
|
||||
QUERY PLAN
|
||||
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
Limit (actual time=0.007..0.011 rows=51 loops=1)
|
||||
Buffers: shared hit=4
|
||||
-> Index Scan using messages_history on messages (actual time=0.006..0.009 rows=51 loops=1)
|
||||
Index Cond: ((chat_id = 'b246d1e6-d41a-4111-aad6-c0474ab30641'::uuid) AND (ROW(created_at, id) > ROW('2026-09-01 02:46:40+00'::timestamp with time zone, 'c1c5eccc-7e7c-4a03-a48e-3a8fb237e518'::uuid)))
|
||||
Buffers: shared hit=4
|
||||
Planning Time: 0.044 ms
|
||||
Execution Time: 0.030 ms
|
||||
|
||||
|
||||
=== 3. The same page with OFFSET 10000 (the app does NOT do this)
|
||||
QUERY PLAN
|
||||
--------------------------------------------------------------------------------
|
||||
Limit (actual time=3.445..3.448 rows=51 loops=1)
|
||||
Buffers: shared hit=860
|
||||
-> Sort (actual time=3.038..3.253 rows=10051 loops=1)
|
||||
Sort Key: created_at, id
|
||||
Sort Method: quicksort Memory: 2377kB
|
||||
Buffers: shared hit=860
|
||||
-> Seq Scan on messages (actual time=0.007..1.686 rows=15000 loops=1)
|
||||
Filter: (chat_id = 'b246d1e6-d41a-4111-aad6-c0474ab30641'::uuid)
|
||||
Rows Removed by Filter: 33658
|
||||
Buffers: shared hit=860
|
||||
Planning Time: 0.037 ms
|
||||
Execution Time: 3.511 ms
|
||||
|
||||
|
||||
=== 4. Query 2 without the index (index is dropped only inside this transaction)
|
||||
QUERY PLAN
|
||||
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
Limit (actual time=1.864..1.868 rows=51 loops=1)
|
||||
Buffers: shared hit=860
|
||||
-> Sort (actual time=1.864..1.865 rows=51 loops=1)
|
||||
Sort Key: created_at, id
|
||||
Sort Method: top-N heapsort Memory: 31kB
|
||||
Buffers: shared hit=860
|
||||
-> Seq Scan on messages (actual time=1.115..1.524 rows=5000 loops=1)
|
||||
Filter: ((chat_id = 'b246d1e6-d41a-4111-aad6-c0474ab30641'::uuid) AND (ROW(created_at, id) > ROW('2026-09-01 02:46:40+00'::timestamp with time zone, 'c1c5eccc-7e7c-4a03-a48e-3a8fb237e518'::uuid)))
|
||||
Rows Removed by Filter: 43658
|
||||
Buffers: shared hit=860
|
||||
Planning:
|
||||
Buffers: shared hit=4
|
||||
Planning Time: 0.051 ms
|
||||
Execution Time: 1.882 ms
|
||||
|
||||
|
||||
=== ROLLBACK: test data removed, index is back
|
||||
explain_users_left
|
||||
--------------------
|
||||
0
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
# explain: EXPLAIN of the history page (full plans: explain-history.txt)
|
||||
# date: 2026-10-14 20:24:32, commit: 0ab3a34 + uncommitted changes
|
||||
# command: python.exe student-tests/explain.py
|
||||
# exit code: 0, 0.7 s
|
||||
|
||||
=== Data volume
|
||||
=== History index
|
||||
=== 1. First page: limit=50, the app asks for 51 rows to know if there is a next page
|
||||
Buffers: shared hit=4
|
||||
-> Index Scan using messages_history on messages (actual time=0.006..0.009 rows=51 loops=1)
|
||||
Buffers: shared hit=4
|
||||
Buffers: shared hit=7
|
||||
Execution Time: 0.020 ms
|
||||
=== 2. Page after the 10000th message by keyset cursor (this is what the app does)
|
||||
Buffers: shared hit=4
|
||||
-> Index Scan using messages_history on messages (actual time=0.006..0.009 rows=51 loops=1)
|
||||
Buffers: shared hit=4
|
||||
Execution Time: 0.030 ms
|
||||
=== 3. The same page with OFFSET 10000 (the app does NOT do this)
|
||||
Buffers: shared hit=860
|
||||
Buffers: shared hit=860
|
||||
-> Seq Scan on messages (actual time=0.007..1.686 rows=15000 loops=1)
|
||||
Buffers: shared hit=860
|
||||
Execution Time: 3.511 ms
|
||||
=== 4. Query 2 without the index (index is dropped only inside this transaction)
|
||||
Buffers: shared hit=860
|
||||
Buffers: shared hit=860
|
||||
-> Seq Scan on messages (actual time=1.115..1.524 rows=5000 loops=1)
|
||||
Buffers: shared hit=860
|
||||
Buffers: shared hit=4
|
||||
Execution Time: 1.882 ms
|
||||
=== ROLLBACK: test data removed, index is back
|
||||
PASS: full plans saved to evidence\explain-history.txt
|
||||
@@ -0,0 +1,169 @@
|
||||
{
|
||||
"profile": {
|
||||
"writers": 4,
|
||||
"readers": 1,
|
||||
"client_timeout_seconds": 2,
|
||||
"warmup_seconds": 3,
|
||||
"after_seconds": 10,
|
||||
"replicas": 2,
|
||||
"client_python": "3.11.1"
|
||||
},
|
||||
"runs": [
|
||||
{
|
||||
"replica": "58542a53644c",
|
||||
"mode": "stop",
|
||||
"command_seconds": 4.12,
|
||||
"lb_excluded_after_seconds": 1.11,
|
||||
"errors": 0,
|
||||
"error_codes": {},
|
||||
"errors_stopped_after_seconds": 0.0,
|
||||
"before": {
|
||||
"seconds": 3.0,
|
||||
"write_rps": 304.7,
|
||||
"reads": 46,
|
||||
"errors": 0,
|
||||
"error_codes": {},
|
||||
"write_p50_ms": 15.0,
|
||||
"write_p95_ms": 32.0,
|
||||
"write_max_ms": 63.0
|
||||
},
|
||||
"after": {
|
||||
"seconds": 10.0,
|
||||
"write_rps": 202.2,
|
||||
"reads": 148,
|
||||
"errors": 0,
|
||||
"error_codes": {},
|
||||
"write_p50_ms": 16.0,
|
||||
"write_p95_ms": 47.0,
|
||||
"write_max_ms": 766.0
|
||||
},
|
||||
"stopped_replica_answers_after_stop": 0,
|
||||
"integrity": {
|
||||
"confirmed_writes": 2938,
|
||||
"messages_in_history": 2938,
|
||||
"duplicates": 0,
|
||||
"lost": 0
|
||||
},
|
||||
"rejoin_seconds": 3.25
|
||||
},
|
||||
{
|
||||
"replica": "58542a53644c",
|
||||
"mode": "kill",
|
||||
"command_seconds": 0.81,
|
||||
"lb_excluded_after_seconds": 0.11,
|
||||
"errors": 2,
|
||||
"error_codes": {
|
||||
"502": 2
|
||||
},
|
||||
"errors_stopped_after_seconds": 0.05,
|
||||
"before": {
|
||||
"seconds": 3.0,
|
||||
"write_rps": 328.7,
|
||||
"reads": 49,
|
||||
"errors": 0,
|
||||
"error_codes": {},
|
||||
"write_p50_ms": 15.0,
|
||||
"write_p95_ms": 32.0,
|
||||
"write_max_ms": 78.0
|
||||
},
|
||||
"after": {
|
||||
"seconds": 10.0,
|
||||
"write_rps": 228.2,
|
||||
"reads": 144,
|
||||
"errors": 2,
|
||||
"error_codes": {
|
||||
"502": 2
|
||||
},
|
||||
"write_p50_ms": 16.0,
|
||||
"write_p95_ms": 32.0,
|
||||
"write_max_ms": 1015.0
|
||||
},
|
||||
"stopped_replica_answers_after_stop": 0,
|
||||
"integrity": {
|
||||
"confirmed_writes": 3274,
|
||||
"messages_in_history": 3274,
|
||||
"duplicates": 0,
|
||||
"lost": 0
|
||||
},
|
||||
"rejoin_seconds": 1.55
|
||||
},
|
||||
{
|
||||
"replica": "9737b915ff2f",
|
||||
"mode": "stop",
|
||||
"command_seconds": 4.12,
|
||||
"lb_excluded_after_seconds": 1.5,
|
||||
"errors": 0,
|
||||
"error_codes": {},
|
||||
"errors_stopped_after_seconds": 0.0,
|
||||
"before": {
|
||||
"seconds": 3.0,
|
||||
"write_rps": 288.7,
|
||||
"reads": 49,
|
||||
"errors": 0,
|
||||
"error_codes": {},
|
||||
"write_p50_ms": 15.0,
|
||||
"write_p95_ms": 32.0,
|
||||
"write_max_ms": 63.0
|
||||
},
|
||||
"after": {
|
||||
"seconds": 10.0,
|
||||
"write_rps": 232.7,
|
||||
"reads": 148,
|
||||
"errors": 0,
|
||||
"error_codes": {},
|
||||
"write_p50_ms": 16.0,
|
||||
"write_p95_ms": 32.0,
|
||||
"write_max_ms": 94.0
|
||||
},
|
||||
"stopped_replica_answers_after_stop": 0,
|
||||
"integrity": {
|
||||
"confirmed_writes": 3194,
|
||||
"messages_in_history": 3194,
|
||||
"duplicates": 0,
|
||||
"lost": 0
|
||||
},
|
||||
"rejoin_seconds": 4.09
|
||||
},
|
||||
{
|
||||
"replica": "9737b915ff2f",
|
||||
"mode": "kill",
|
||||
"command_seconds": 0.83,
|
||||
"lb_excluded_after_seconds": 0.11,
|
||||
"errors": 2,
|
||||
"error_codes": {
|
||||
"502": 2
|
||||
},
|
||||
"errors_stopped_after_seconds": 0.05,
|
||||
"before": {
|
||||
"seconds": 3.0,
|
||||
"write_rps": 266.7,
|
||||
"reads": 47,
|
||||
"errors": 0,
|
||||
"error_codes": {},
|
||||
"write_p50_ms": 16.0,
|
||||
"write_p95_ms": 32.0,
|
||||
"write_max_ms": 78.0
|
||||
},
|
||||
"after": {
|
||||
"seconds": 10.0,
|
||||
"write_rps": 219.9,
|
||||
"reads": 143,
|
||||
"errors": 2,
|
||||
"error_codes": {
|
||||
"502": 2
|
||||
},
|
||||
"write_p50_ms": 16.0,
|
||||
"write_p95_ms": 32.0,
|
||||
"write_max_ms": 1000.0
|
||||
},
|
||||
"stopped_replica_answers_after_stop": 0,
|
||||
"integrity": {
|
||||
"confirmed_writes": 3000,
|
||||
"messages_in_history": 3000,
|
||||
"duplicates": 0,
|
||||
"lost": 0
|
||||
},
|
||||
"rejoin_seconds": 4.14
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
# failover-metrics: stop/kill every replica under load, metrics
|
||||
# date: 2026-10-14 20:26:19, commit: 0ab3a34 + uncommitted changes
|
||||
# command: python.exe student-tests/failover_metrics.py
|
||||
# exit code: 0, 69.7 s
|
||||
|
||||
api replicas: ['58542a53644c', '9737b915ff2f']; load: 4 writers without pauses + 1 reader, client timeout 2 s, retry with the same Idempotency-Key; 3 s before and 10 s after the failure
|
||||
--- stop 58542a53644c ...
|
||||
docker stop: 4.12 s; HAProxy excluded it after 1.11 s; errors: 0 {}, stopped after 0.0 s
|
||||
write RPS before 304.7 -> after 202.2; p95 after 47.0 ms, max 766.0 ms; answers from the stopped replica after stop: 0
|
||||
confirmed 2938, in history 2938, lost 0, duplicates 0; back in the balancer 3.25 s after docker start
|
||||
--- kill 58542a53644c ...
|
||||
docker kill: 0.81 s; HAProxy excluded it after 0.11 s; errors: 2 {'502': 2}, stopped after 0.05 s
|
||||
write RPS before 328.7 -> after 228.2; p95 after 32.0 ms, max 1015.0 ms; answers from the stopped replica after stop: 0
|
||||
confirmed 3274, in history 3274, lost 0, duplicates 0; back in the balancer 1.55 s after docker start
|
||||
--- stop 9737b915ff2f ...
|
||||
docker stop: 4.12 s; HAProxy excluded it after 1.5 s; errors: 0 {}, stopped after 0.0 s
|
||||
write RPS before 288.7 -> after 232.7; p95 after 32.0 ms, max 94.0 ms; answers from the stopped replica after stop: 0
|
||||
confirmed 3194, in history 3194, lost 0, duplicates 0; back in the balancer 4.09 s after docker start
|
||||
--- kill 9737b915ff2f ...
|
||||
docker kill: 0.83 s; HAProxy excluded it after 0.11 s; errors: 2 {'502': 2}, stopped after 0.05 s
|
||||
write RPS before 266.7 -> after 219.9; p95 after 32.0 ms, max 1000.0 ms; answers from the stopped replica after stop: 0
|
||||
confirmed 3000, in history 3000, lost 0, duplicates 0; back in the balancer 4.14 s after docker start
|
||||
|
||||
replica mode cmd,s lb_out,s errors errors_end,s rps_before rps_after p95_after,ms rejoin,s
|
||||
58542a53644c stop 4.12 1.11 0 0.0 304.7 202.2 47.0 3.25
|
||||
58542a53644c kill 0.81 0.11 2 0.05 328.7 228.2 32.0 1.55
|
||||
9737b915ff2f stop 4.12 1.5 0 0.0 288.7 232.7 32.0 4.09
|
||||
9737b915ff2f kill 0.83 0.11 2 0.05 266.7 219.9 32.0 4.14
|
||||
PASS: every replica was stopped (stop, kill) and restored; no lost or duplicated messages; saved evidence\failover-metrics.json
|
||||
@@ -0,0 +1,33 @@
|
||||
# failover: public failover test for every replica (make test-failover)
|
||||
# date: 2026-10-14 20:25:10, commit: 0ab3a34 + uncommitted changes
|
||||
# command: python.exe student-tests/run_failover.py
|
||||
# exit code: 0, 37.8 s
|
||||
|
||||
hook: scripts\stop-one.cmd; api replicas: ['58542a53644c', '9737b915ff2f']
|
||||
=== run 1: api containers before
|
||||
SERVICE CONTAINER ID STATUS
|
||||
api 58542a53644c Up About a minute (healthy)
|
||||
api 9737b915ff2f Up About a minute (healthy)
|
||||
Executing explicit failover hook; hook output suppressed to avoid leaking secrets.␍
|
||||
{"observed_instances_before": 2, "successful_writes": 128, "failed_attempts": 0, "first_recovery_seconds": 4.203}␍
|
||||
PASS: failover preserved confirmed data and existing session. Hook scope needs operator evidence.
|
||||
api containers after
|
||||
SERVICE CONTAINER ID STATUS
|
||||
api 58542a53644c Exited (0) 11 seconds ago
|
||||
api 9737b915ff2f Up About a minute (healthy)
|
||||
the hook stopped 58542a53644c (X-Instance-Id of that replica = container ID); other api containers kept running, postgres/redis/lb were not touched
|
||||
restored: docker start 58542a53644c -> healthy and back in HAProxy
|
||||
=== run 2: api containers before
|
||||
SERVICE CONTAINER ID STATUS
|
||||
api 58542a53644c Up 1 second (healthy)
|
||||
api 9737b915ff2f Up About a minute (healthy)
|
||||
Executing explicit failover hook; hook output suppressed to avoid leaking secrets.␍
|
||||
{"observed_instances_before": 2, "successful_writes": 132, "failed_attempts": 0, "first_recovery_seconds": 4.281}␍
|
||||
PASS: failover preserved confirmed data and existing session. Hook scope needs operator evidence.
|
||||
api containers after
|
||||
SERVICE CONTAINER ID STATUS
|
||||
api 58542a53644c Up 18 seconds (healthy)
|
||||
api 9737b915ff2f Exited (0) 11 seconds ago
|
||||
the hook stopped 9737b915ff2f (X-Instance-Id of that replica = container ID); other api containers kept running, postgres/redis/lb were not touched
|
||||
restored: docker start 9737b915ff2f -> healthy and back in HAProxy
|
||||
PASS: public failover test passed 2 times; every api replica was stopped once and restored
|
||||
@@ -0,0 +1,29 @@
|
||||
# failures: Redis and PostgreSQL outages via the balancer
|
||||
# date: 2026-10-14 20:27:54, commit: 0ab3a34 + uncommitted changes
|
||||
# command: python.exe student-tests/test_failures.py
|
||||
# exit code: 0, 47.0 s
|
||||
|
||||
stopping redis
|
||||
/health/live -> 200, /health/ready -> 503 (3297 ms)
|
||||
valid token: GET /users/me -> 503 unavailable (3281 ms), session cannot be checked
|
||||
unknown token -> 503, not 200: nobody is trusted without a check
|
||||
no token -> 401
|
||||
login -> 503: there is nowhere to store the session
|
||||
registration -> 201: it needs only PostgreSQL
|
||||
starting redis
|
||||
after start: the old token works, confirmed messages are in place
|
||||
PASS: Redis outage gives 503 and does not let anyone in without a session check
|
||||
killing redis with SIGKILL (docker compose kill redis): no graceful shutdown
|
||||
right after the crash: GET /users/me -> 503
|
||||
starting redis
|
||||
after start: the session issued before the crash still works (AOF, appendfsync always)
|
||||
PASS: sessions survive a Redis crash, not only a clean restart
|
||||
stopping postgres
|
||||
/health/live -> 200, /health/ready -> 503 (1015 ms)
|
||||
valid token: users/me, chats, history, new message -> 503 unavailable, no details
|
||||
no token -> 401, unknown token -> 401: anonymous users are not let in
|
||||
login -> 503, registration -> 503
|
||||
starting postgres
|
||||
after start: the old token works, confirmed messages are in place
|
||||
PASS: PostgreSQL outage gives limited 503 errors and keeps anonymous users out
|
||||
3 passed, 0 failed
|
||||
@@ -0,0 +1,22 @@
|
||||
# idempotency: Idempotency-Key, parallel same key via replicas
|
||||
# date: 2026-10-14 20:24:15, commit: 0ab3a34 + uncommitted changes
|
||||
# command: python.exe student-tests/test_idempotency.py
|
||||
# exit code: 0, 2.3 s
|
||||
|
||||
first -> 201; same JSON written differently -> 201; plain retry -> 201
|
||||
PASS: a retry with the same key returns the original 201 and message, no duplicate
|
||||
20 parallel POSTs with one key: statuses {201: 20}, replicas {'58542a53644c': 10, '9737b915ff2f': 10}, different bodies in answers: 1, messages in history: 1
|
||||
PASS: parallel requests with one key through different replicas create exactly one message
|
||||
20 parallel POSTs, one key, two different bodies: {('body A', 409): 10, ('body B', 201): 10}; saved: ['body B']
|
||||
PASS: the first body wins, the same body gets 201, the other body gets 409
|
||||
one key: alice in chat 1, bob in chat 1, alice in chat 2 -> 3 messages
|
||||
PASS: the key is scoped to the current user and chat; another body with a used key -> 409
|
||||
missing, empty, 129 chars, space, '/', non-ASCII, '"', '+' -> 400; 128 chars of A-Z a-z 0-9 . _ : - -> 201
|
||||
PASS: Idempotency-Key is required and checked: [A-Za-z0-9._:-]{1,128}
|
||||
key used by a 400 and by a 404 first, then valid request -> 201
|
||||
PASS: rejected requests (400, 404) do not store a result for the key
|
||||
same key and body by an outsider -> 404; by alice after logout -> 401
|
||||
PASS: a retry checks the session and chat access again, the saved answer is not leaked
|
||||
POST sent, connection closed without reading the answer; retry -> 201; messages: 1
|
||||
PASS: an unconfirmed POST can be safely retried with the same key
|
||||
8 passed, 0 failed
|
||||
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"lab": 3,
|
||||
"workload": "closed-loop POST messages; no automatic retries",
|
||||
"requested_duration_seconds": 30.0,
|
||||
"elapsed_seconds": 30.031,
|
||||
"concurrency": 4,
|
||||
"successful_requests": 9275,
|
||||
"failed_requests": 0,
|
||||
"error_ratio": 0.0,
|
||||
"successful_rps": 308.848,
|
||||
"successful_latency_ms": {
|
||||
"p50": 15.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,22 @@
|
||||
# load: public load generator, 30 s, concurrency 4
|
||||
# date: 2026-10-14 20:26:50, commit: 0ab3a34 + uncommitted changes
|
||||
# command: python.exe tests/load.py --base-url http://127.0.0.1:8080 --duration 30 --concurrency 4 --output evidence/load.json
|
||||
# exit code: 0, 30.3 s
|
||||
|
||||
{
|
||||
"lab": 3,
|
||||
"workload": "closed-loop POST messages; no automatic retries",
|
||||
"requested_duration_seconds": 30.0,
|
||||
"elapsed_seconds": 30.031,
|
||||
"concurrency": 4,
|
||||
"successful_requests": 9275,
|
||||
"failed_requests": 0,
|
||||
"error_ratio": 0.0,
|
||||
"successful_rps": 308.848,
|
||||
"successful_latency_ms": {
|
||||
"p50": 15.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,20 @@
|
||||
# persistence: public persistence test + proof of real restarts (make test-persistence)
|
||||
# date: 2026-10-14 20:28:03, commit: 0ab3a34 + uncommitted changes
|
||||
# command: python.exe student-tests/run_persistence.py
|
||||
# exit code: 0, 9.2 s
|
||||
|
||||
before: container, ID, started at
|
||||
messenger-lab3-api-3 231a6acf25e5 2026-10-14T17:27:05.347335515Z
|
||||
messenger-lab3-api-4 5ef3550d83e5 2026-10-14T17:27:05.632137055Z
|
||||
messenger-lab3-lb-1 143799027af8 2026-10-14T17:23:15.482251883Z
|
||||
messenger-lab3-postgres-1 94f24029f4b4 2026-10-14T17:27:46.840755333Z
|
||||
messenger-lab3-redis-1 b78c2ab71807 2026-10-14T17:27:26.471429301Z
|
||||
Executing explicit persistence hook; hook output suppressed to avoid leaking secrets.␍
|
||||
PASS: persistence preserved confirmed data and existing session. Hook scope needs operator evidence.
|
||||
after (hook + waiting for readiness took 8.5 s): container, ID, started at, restarted?
|
||||
messenger-lab3-api-3 231a6acf25e5 2026-10-14T17:28:00.882064128Z same container: True, restarted: True
|
||||
messenger-lab3-api-4 5ef3550d83e5 2026-10-14T17:28:00.692590504Z same container: True, restarted: True
|
||||
messenger-lab3-lb-1 143799027af8 2026-10-14T17:28:02.788694335Z same container: True, restarted: True
|
||||
messenger-lab3-postgres-1 94f24029f4b4 2026-10-14T17:27:56.091073554Z same container: True, restarted: True
|
||||
messenger-lab3-redis-1 b78c2ab71807 2026-10-14T17:27:56.26191188Z same container: True, restarted: True
|
||||
PASS: the hook restarted postgres, redis, all api replicas and lb (same containers, new start time); data and the old token survived
|
||||
@@ -0,0 +1,10 @@
|
||||
# race: lab2 races via the balancer
|
||||
# date: 2026-10-14 20:24:18, commit: 0ab3a34 + uncommitted changes
|
||||
# command: python.exe student-tests/test_race.py
|
||||
# exit code: 0, 1.1 s
|
||||
|
||||
sent 100 messages from 10 clients in 0.22 s; read 100 in 4 pages, unique ids: 100
|
||||
PASS: 100 concurrent messages from 10 clients, no losses and no duplicates
|
||||
20 parallel registrations of one username: 201 x1, 409 x19
|
||||
PASS: concurrent registration created exactly one user
|
||||
2 passed, 0 failed
|
||||
@@ -0,0 +1,14 @@
|
||||
# redis: Redis as the session store
|
||||
# date: 2026-10-14 20:24:31, commit: 0ab3a34 + uncommitted changes
|
||||
# command: python.exe student-tests/redis_info.py
|
||||
# exit code: 0, 2.4 s
|
||||
|
||||
session key: session:b215258e3e5be3f4...; value is the user id: True
|
||||
TTL of the key, seconds: 3599
|
||||
sessions in Redis: 153
|
||||
config appendonly = yes
|
||||
config appendfsync = always
|
||||
config maxmemory-policy = noeviction
|
||||
aof_enabled:1
|
||||
aof_last_write_status:ok
|
||||
without password: NOAUTH Authentication required.
|
||||
@@ -0,0 +1,51 @@
|
||||
{
|
||||
"from_version": "rolling-20261014-201405",
|
||||
"to_version": "rolling-20261014-202804",
|
||||
"replicas": 2,
|
||||
"profile": {
|
||||
"writers": 4,
|
||||
"readers": 1,
|
||||
"client_timeout_seconds": 2
|
||||
},
|
||||
"steps": [
|
||||
{
|
||||
"old": "231a6acf25e5",
|
||||
"new": "02b2a36daac5",
|
||||
"new_ready_seconds": 2.36,
|
||||
"step_seconds": 6.58
|
||||
},
|
||||
{
|
||||
"old": "5ef3550d83e5",
|
||||
"new": "cb8c881f5046",
|
||||
"new_ready_seconds": 2.74,
|
||||
"step_seconds": 6.91
|
||||
}
|
||||
],
|
||||
"update_seconds": 13.48,
|
||||
"before": {
|
||||
"seconds": 3.0,
|
||||
"write_rps": 284.7,
|
||||
"reads": 45,
|
||||
"errors": 0,
|
||||
"error_codes": {},
|
||||
"write_p50_ms": 15.0,
|
||||
"write_p95_ms": 32.0,
|
||||
"write_max_ms": 109.0
|
||||
},
|
||||
"during": {
|
||||
"seconds": 13.48,
|
||||
"write_rps": 346.3,
|
||||
"reads": 213,
|
||||
"errors": 0,
|
||||
"error_codes": {},
|
||||
"write_p50_ms": 15.0,
|
||||
"write_p95_ms": 31.0,
|
||||
"write_max_ms": 78.0
|
||||
},
|
||||
"integrity": {
|
||||
"confirmed_writes": 6527,
|
||||
"messages_in_history": 6527,
|
||||
"duplicates": 0,
|
||||
"lost": 0
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
# rolling-update: rolling update under load
|
||||
# date: 2026-10-14 20:28:31, commit: 0ab3a34 + uncommitted changes
|
||||
# command: python.exe student-tests/rolling_update.py
|
||||
# exit code: 0, 28.0 s
|
||||
|
||||
old replicas ['231a6acf25e5', '5ef3550d83e5'], version rolling-20261014-201405; building version rolling-20261014-202804
|
||||
image built in 5.0 s
|
||||
migrations: Migrations applied: none (schema is up to date)
|
||||
replaced 231a6acf25e5 -> 02b2a36daac5: new replica ready and in HAProxy after 2.4 s, step 6.58 s
|
||||
replaced 5ef3550d83e5 -> cb8c881f5046: new replica ready and in HAProxy after 2.7 s, step 6.91 s
|
||||
now: replicas ['02b2a36daac5', 'cb8c881f5046'], versions ['rolling-20261014-202804']
|
||||
under load: write RPS before 284.7, during the update 346.3; errors 0 {}; p95 31.0 ms, max 78.0 ms; update took 13.5 s
|
||||
confirmed 6527, in history 6527, lost 0, duplicates 0
|
||||
PASS: all 2 replicas replaced one by one under load, 0 errors, no lost or duplicated messages; saved evidence\rolling-update.json
|
||||
@@ -0,0 +1,6 @@
|
||||
# smoke: public smoke via the balancer (make test)
|
||||
# date: 2026-10-14 20:24:11, commit: 0ab3a34 + uncommitted changes
|
||||
# command: python.exe tests/smoke.py --base-url http://127.0.0.1:8080
|
||||
# exit code: 0, 0.4 s
|
||||
|
||||
PASS: lab3 public API scenario; infrastructure and grading evidence remain separate.
|
||||
@@ -0,0 +1,32 @@
|
||||
# stack: stand layout: replicas, ports, limits, networks, secrets
|
||||
# date: 2026-10-14 20:24:11, commit: 0ab3a34 + uncommitted changes
|
||||
# command: python.exe student-tests/check_stack.py
|
||||
# exit code: 0, 2.0 s
|
||||
|
||||
host: Windows 10, AMD64 Family 26 Model 68 Stepping 0, AuthenticAMD; client Python 3.11.1
|
||||
Docker 28.1.1, Docker Compose version v2.35.1-desktop.1; Docker VM: 16 CPU, 15.2 GiB RAM, Docker Desktop
|
||||
|
||||
SERVICE CONTAINER ID STATUS PORTS
|
||||
api 58542a53644c Up 56 seconds (healthy) 8080/tcp
|
||||
api 9737b915ff2f Up 56 seconds (healthy) 8080/tcp
|
||||
lb 143799027af8 Up 54 seconds (healthy) 127.0.0.1:8080->8080/tcp, 127.0.0.1:8404->8404/tcp
|
||||
migrate edb8550a4469 Exited (0) 19 seconds ago
|
||||
postgres 94f24029f4b4 Up 56 seconds (healthy)
|
||||
redis b78c2ab71807 Up 56 seconds (healthy)
|
||||
|
||||
container image cpus memory host ports networks
|
||||
messenger-lab3-api-3 messenger-lab3-api 1.00 512 MiB - data,edge
|
||||
messenger-lab3-api-4 messenger-lab3-api 1.00 512 MiB - data,edge
|
||||
messenger-lab3-lb-1 haproxy:3.2.25-alpine 0.50 128 MiB 127.0.0.1:8080,127.0.0.1:8404 edge
|
||||
messenger-lab3-postgres-1 postgres:17.11-alpine 1.00 512 MiB - data
|
||||
messenger-lab3-redis-1 redis:7.4.11-alpine 0.50 128 MiB - data
|
||||
|
||||
secrets of api: ['cache_url', 'database_url']
|
||||
secrets of lb: -
|
||||
secrets of migrate: ['database_url']
|
||||
secrets of postgres: ['postgres_password']
|
||||
secrets of redis: ['redis_auth']
|
||||
|
||||
through http://127.0.0.1:8080 one session is served by 2 replicas: ['58542a53644c', '9737b915ff2f']
|
||||
/health/ready -> 200 from 58542a53644c
|
||||
PASS: 2 api replicas behind one entry point, no direct API ports, limits on every container, internal data network, secrets only where needed
|
||||
@@ -0,0 +1,25 @@
|
||||
# student-tests: lab1/lab2 API tests via the balancer
|
||||
# date: 2026-10-14 20:24:17, commit: 0ab3a34 + uncommitted changes
|
||||
# command: python.exe student-tests/test_api.py
|
||||
# exit code: 0, 2.5 s
|
||||
|
||||
PASS: duplicate username returns 409
|
||||
PASS: invalid JSON returns 400
|
||||
PASS: wrong and extra fields return 400
|
||||
PASS: foreign chat returns 404
|
||||
PASS: empty and too long messages return 400, 4000 chars is ok
|
||||
PASS: pagination works across multiple pages, foreign cursor returns 400
|
||||
PASS: chat list pagination
|
||||
PASS: unicode text is stored as is
|
||||
PASS: strings with U+0000 are stored and returned as is
|
||||
PASS: user response has no password or hash
|
||||
PASS: password length 12..128, blank password is rejected
|
||||
PASS: Basic login returns opaque Bearer token with expiry
|
||||
PASS: wrong password and unknown user both return the same 401
|
||||
PASS: malformed Basic header returns 401
|
||||
PASS: password with colon and unicode works
|
||||
PASS: business endpoints need Bearer; Basic and X-User-Id give 401
|
||||
PASS: X-User-Id does not change the current user
|
||||
PASS: 401 comes before 400 and 404
|
||||
PASS: logout revokes only the current session
|
||||
19 passed, 0 failed
|
||||
@@ -0,0 +1,55 @@
|
||||
# Сводка проверок
|
||||
|
||||
| Шаг | Что проверяет | Результат | Время, с | Файл |
|
||||
| --- | --- | --- | --- | --- |
|
||||
| check | offline contract check (make check) | PASS | 0 | evidence/check.txt |
|
||||
| stack | stand layout: replicas, ports, limits, networks, secrets | PASS | 2 | evidence/stack.txt |
|
||||
| smoke | public smoke via the balancer (make test) | PASS | 0 | evidence/smoke.txt |
|
||||
| balancing | balancing, shared sessions and data, X-Instance-Id | PASS | 1 | evidence/balancing.txt |
|
||||
| idempotency | Idempotency-Key, parallel same key via replicas | PASS | 2 | evidence/idempotency.txt |
|
||||
| student-tests | lab1/lab2 API tests via the balancer | PASS | 2 | evidence/student-tests.txt |
|
||||
| race | lab2 races via the balancer | PASS | 1 | evidence/race.txt |
|
||||
| db | PostgreSQL: rollback, FK, Argon2id, unique keys, migrations | PASS | 10 | evidence/db.txt |
|
||||
| redis | Redis as the session store | PASS | 2 | evidence/redis.txt |
|
||||
| explain | EXPLAIN of the history page (full plans: explain-history.txt) | PASS | 1 | evidence/explain.txt |
|
||||
| failover | public failover test for every replica (make test-failover) | PASS | 38 | evidence/failover.txt |
|
||||
| failover-metrics | stop/kill every replica under load, metrics | PASS | 70 | evidence/failover-metrics.txt |
|
||||
| load | public load generator, 30 s, concurrency 4 | PASS | 30 | evidence/load.txt |
|
||||
| expiry | session TTL=2 s, then normal TTL | PASS | 17 | evidence/expiry.txt |
|
||||
| failures | Redis and PostgreSQL outages via the balancer | PASS | 47 | evidence/failures.txt |
|
||||
| persistence | public persistence test + proof of real restarts (make test-persistence) | PASS | 9 | evidence/persistence.txt |
|
||||
| rolling-update | rolling update under load | PASS | 28 | evidence/rolling-update.txt |
|
||||
|
||||
# Замеры
|
||||
|
||||
Машина: Windows 10, AMD64 Family 26 Model 68 Stepping 0, AuthenticAMD; Docker VM: 16 CPU, 15.2 GiB RAM; клиент Python 3.11.1; дата прогона 2026-10-14, commit 0ab3a34 + uncommitted changes. Лимиты контейнеров: api 1 CPU / 512 MiB каждая, postgres 1 CPU / 512 MiB, redis и lb по 0,5 CPU / 128 MiB.
|
||||
|
||||
Публичный тест отказа (`make test-failover`, 15 с записи во время остановки реплики):
|
||||
|
||||
| Прогон | Остановлена реплика | Реплик до отказа | Успешных записей | Неудачных попыток (повторены с тем же ключом) | Первая запись после hook, с |
|
||||
| --- | --- | --- | --- | --- | --- |
|
||||
| 1 | 58542a53644c | 2 | 128 | 0 | 4.203 |
|
||||
| 2 | 9737b915ff2f | 2 | 132 | 0 | 4.281 |
|
||||
|
||||
Остановка каждой реплики под нагрузкой (`student-tests/failover_metrics.py`: 4 потока записи без пауз + 1 поток чтения, timeout клиента 2 с, 3 с до и 10 с после отказа):
|
||||
|
||||
| Реплика | Как остановлена | Команда, с | HAProxy вывел из балансировки через, с | Ошибок (коды) | Ошибки прекратились через, с | Записей/с до | Записей/с после | p95 после, мс | Вернулась в балансировку после docker start, с |
|
||||
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
|
||||
| 58542a53644c | docker stop (SIGTERM) | 4.12 | 1.11 | 0 (-) | 0.0 | 304.7 | 202.2 | 47.0 | 3.25 |
|
||||
| 58542a53644c | docker kill (SIGKILL) | 0.81 | 0.11 | 2 (502: 2) | 0.05 | 328.7 | 228.2 | 32.0 | 1.55 |
|
||||
| 9737b915ff2f | docker stop (SIGTERM) | 4.12 | 1.5 | 0 (-) | 0.0 | 288.7 | 232.7 | 32.0 | 4.09 |
|
||||
| 9737b915ff2f | docker kill (SIGKILL) | 0.83 | 0.11 | 2 (502: 2) | 0.05 | 266.7 | 219.9 | 32.0 | 4.14 |
|
||||
|
||||
Во всех прогонах: потерянных подтверждённых сообщений 0, дублей 0, остановленная реплика после остановки не ответила ни разу.
|
||||
|
||||
Rolling update (`student-tests/rolling_update.py`): версия rolling-20261014-201405 -> rolling-20261014-202804, 2 реплики заменены по одной за 13.48 с под той же нагрузкой. Записей/с до: 284.7, во время замены: 346.3; ошибок: 0 (-); p95 31.0 мс, максимум 78.0 мс; подтверждено 6527 сообщений, потерь и дублей нет.
|
||||
|
||||
Публичный генератор нагрузки (`tests/load.py`, closed loop, concurrency 4, 30 с, 2 реплики): 308.848 успешных POST/с, ошибок 0 (доля 0.0), задержка успешных p50 15.0 мс, p95 32.0 мс, p99 46.0 мс.
|
||||
|
||||
| Воздействие | Что ожидаем | Что наблюдали | Время восстановления / потеря данных |
|
||||
| --- | --- | --- | --- |
|
||||
| `docker stop` реплики (SIGTERM) под нагрузкой | ошибок нет: реплика сначала уходит из балансировки (readiness 503), потом закрывает приём | ошибок: 0, 0 (по репликам); HAProxy вывел реплику через 1.11, 1.5 с | ошибки прекратились через 0.0 с; потерь 0, дублей 0; реплика вернулась через 4.09 с после `docker start` |
|
||||
| `docker kill` реплики (SIGKILL, авария) под нагрузкой | единицы 502 на запросы, начатые на убитой реплике; клиент повторяет их с тем же ключом | ошибок: 2, 2 (по репликам); HAProxy вывел реплику через 0.11, 0.11 с | ошибки прекратились через 0.05 с; потерь 0, дублей 0; реплика вернулась через 4.14 с после `docker start` |
|
||||
| публичный `make test-failover` для каждой реплики | запись продолжается не позже 10 с, подтверждённые сообщения на месте, дублей нет | PASS 2 раз(а), неудачных попыток: 0, 0 | первая запись после hook через 4.203, 4.281 с (hook ждёт остановки ~4 с); потерь нет |
|
||||
| rolling update под нагрузкой | ошибок нет, реплик всё время не меньше 2 | ошибок: 0, замена заняла 13.48 с | потерь 0, дублей 0 |
|
||||
| перезапуск всего стенда (`restart` hook: postgres, redis, api, lb) | данные и прежний токен живы | PASS, те же контейнеры с новым временем старта | 8.5 с до готовности; потерь нет |
|
||||
Reference in New Issue
Block a user