Выполнение ЛР5 на 5 (трек 2)

This commit is contained in:
Ilya
2026-11-11 19:09:08 +03:00
parent 276dbdad8a
commit 9de64e36b2
58 changed files with 5132 additions and 30 deletions
+15
View File
@@ -3,3 +3,18 @@
Храните небольшие обезличенные результаты: команды и stdout проверок, JSON/CSV агрегатов нагрузки, EXPLAIN, dashboard JSON, текст разбора отказа. Укажите дату, commit, аппаратные лимиты и профиль нагрузки.
Не добавляйте .env, session tokens, cookies, приватные ключи, credentials, реальные сообщения, raw dumps и signed URLs. Для скриншотов скрывайте секреты. Большие логи/бинарные traces сохраняйте отдельно по правилам преподавателя; одного скриншота без методики недостаточно.
## Файлы этой работы (lab5)
| Файл | Что доказывает | Команда |
| --- | --- | --- |
| `smoke.txt` | публичный сценарий lab5 | `make test` |
| `pipeline.txt` | варианты (256×160, crop 128, WebP), EXIF, alpha, лимиты 413/415, invalid_image без повторов | `make test-pipeline` |
| `faults.txt`, `faults.json` | 14 сценариев отказов (уровни 3–4, трек 2) с инвариантами I1–I5 | `make test-faults` (FAULT_INJECTION=1) |
| `limits.txt` | лимиты памяти (RLIMIT_AS) и времени worker | `make test-limits` |
| `persistence.txt` | рестарт API, worker, relay и всех хранилищ с volumes | `make test-persistence ACTION_SCRIPT=scripts/restart.sh` |
| `failover.txt`, `stop-one.txt` | отказ API-реплики (регресс lab3) | `make test-failover ACTION_SCRIPT=scripts/stop-one.sh` |
| `sweeper.txt` | retention/очистка неиспользуемых объектов, идемпотентность sweeper | см. заголовок файла |
| `load.json` | регресс синхронного пути сообщений | `tests/load.py` (см. REPORT.md) |
Стенд: Apple M3, 8 CPU, 16 GiB, Docker Desktop 28.0.1. В файлах нет токенов и паролей: тесты держат токены только в памяти, hook-вывод скрыт.
+24
View File
@@ -0,0 +1,24 @@
# failover: stop the API replica that served the test, twice (restore in between)
# date: 2026-11-10T13:49:42Z
## run 1: make test-failover ACTION_SCRIPT=scripts/stop-one.sh
python3 tests/resilience.py --mode failover --action-script "scripts/stop-one.sh" --base-url "http://localhost:8080"
Executing explicit failover hook; hook output suppressed to avoid leaking secrets.
{"observed_instances_before": 2, "successful_writes": 113, "failed_attempts": 0, "first_recovery_seconds": 3.483}
PASS: failover preserved confirmed data and existing session. Hook scope needs operator evidence.
NAME STATUS
messenger-lab5-api-1 Up 5 seconds (healthy)
messenger-lab5-api-2 Up 39 seconds (healthy)
## run 2: make test-failover ACTION_SCRIPT=scripts/stop-one.sh
python3 tests/resilience.py --mode failover --action-script "scripts/stop-one.sh" --base-url "http://localhost:8080"
Executing explicit failover hook; hook output suppressed to avoid leaking secrets.
{"observed_instances_before": 2, "successful_writes": 113, "failed_attempts": 0, "first_recovery_seconds": 2.809}
PASS: failover preserved confirmed data and existing session. Hook scope needs operator evidence.
NAME STATUS
messenger-lab5-api-1 Up 5 seconds (healthy)
messenger-lab5-api-2 Up About a minute (healthy)
## stop-one.sh log
2026-11-10T13:49:45Z stopped messenger-lab5-api-1 (45db2233b0c2) instance=api-cf4d97a2 state=exited
2026-11-10T13:50:09Z stopped messenger-lab5-api-1 (45db2233b0c2) instance=api-3423c899 state=exited
+133
View File
@@ -0,0 +1,133 @@
{
"scenarios": [
{
"scenario": "worker_down",
"what": "worker stopped -> upload 202 -> message -> API + broker restart -> worker start -> ready",
"seconds": 31.1,
"observed": [
"worker: messenger-lab5-worker-1 exited Exited (0) Less than a second ago",
"queue before broker restart: {\"jobs\": {\"superseded\": 1, \"failed\": 6, \"done\": 33, \"queued\": 1}, \"outbox_unpublished\": 0, \"queue_ready_messages\": 1, \"queue_consumers\": 0, \"dlq_messages\": 1}",
"queue after broker restart (volume kept): {\"jobs\": {\"superseded\": 1, \"failed\": 6, \"done\": 33, \"queued\": 1}, \"outbox_unpublished\": 0, \"queue_ready_messages\": 1, \"queue_consumers\": 0, \"dlq_messages\": 1}",
"attachment 1f804983-862e-4fcc-b3ca-ee2af8564aba ready after worker start; thumbnail 256x160"
]
},
{
"scenario": "outbox_gap",
"what": "COMMIT done, relay down (= crash between COMMIT and publish) -> relay restart publishes -> ready",
"seconds": 15.8,
"observed": [
"relay down: outbox [{'id': 60, 'attempt': '1', 'published': False, 'publish_count': 0}], attachment queued",
"after relay start: ready, events ['accepted', 'claimed', 'ready']"
]
},
{
"scenario": "relay_crash_after_confirm",
"what": "relay dies after the publisher confirm but before marking the row -> duplicate publish -> worker no-op",
"seconds": 7.6,
"observed": [
"events: ['accepted', 'fault_injected', 'claimed', 'ready', 'duplicate_noop']"
]
},
{
"scenario": "crash_after_claim",
"what": "crash before any side effect: lease expires, reaper re-enqueues attempt 2",
"seconds": 28.5,
"observed": [
"worker.after_claim: ready in 23.9s; events ['accepted', 'claimed', 'fault_injected', 'lease_held_noop', 'lease_expired', 'retry_scheduled', 'claimed', 'ready']; variant attempts [2]"
]
},
{
"scenario": "crash_after_s3",
"what": "crash after writing S3 objects, before COMMIT: retry overwrites the same keys, one set of variants",
"seconds": 29.0,
"observed": [
"worker.after_s3_before_commit: ready in 24.2s; events ['accepted', 'claimed', 'fault_injected', 'lease_held_noop', 'lease_expired', 'retry_scheduled', 'claimed', 'ready']; variant attempts [2]"
]
},
{
"scenario": "crash_after_commit",
"what": "crash after COMMIT, before ack: redelivery sees done -> ack as no-op, no second attempt",
"seconds": 6.6,
"observed": [
"worker.after_commit_before_ack: ready in 1.7s; events ['accepted', 'claimed', 'ready', 'fault_injected', 'duplicate_noop']; variant attempts [1]"
]
},
{
"scenario": "transient_backoff",
"what": "two transient failures -> retries with exponential backoff + jitter -> ready on attempt 3",
"seconds": 12.8,
"observed": [
"retry delays [1.12, 3.15] (windows [1,2] and [2,4] s)"
]
},
{
"scenario": "exhausted_then_replay",
"what": "5 transient failures -> failed retry_exhausted (registry) -> explicit replay -> ready; replay of ready refused",
"seconds": 38.3,
"observed": [
"failed after 5 attempts, registry entry present",
"replayed job 5ff64075-edfa-4472-afed-a003bdbb601d (attempt 6 next)",
"replay of ready: refused: job is done (attachment ready); replay applies only to failed jobs"
]
},
{
"scenario": "long_running_not_hung",
"what": "a 30 s step longer than the 20 s lease: heartbeat renews the lease -> no second attempt",
"seconds": 37.4,
"observed": [
"30 s processing with 20 s lease: attempt=1, no lease_expired"
]
},
{
"scenario": "duplicate",
"what": "3 raw duplicates of an already completed job: ack as no-op, nothing rewritten",
"seconds": 12.4,
"observed": [
"3 duplicates -> 3 duplicate_noop, updated_at unchanged"
]
},
{
"scenario": "reorder",
"what": "relay stopped; deliveries arrive out of order: attempt 1, then 1 again and 4, then the outbox backlog",
"seconds": 20.2,
"observed": [
"events: ['accepted', 'claimed', 'fault_injected', 'retry_scheduled', 'stale_attempt_noop', 'stale_attempt_noop', 'stale_attempt_noop', 'claimed', 'ready']"
]
},
{
"scenario": "new_version",
"what": "v1 ready -> reprocess v2 -> v2 published; replaying a v1 message afterwards changes nothing",
"seconds": 11.9,
"observed": [
"v1 optimized 1090d84ed841.. -> v2 f2878c4a9d89..; stale v1 message: duplicate_noop"
]
},
{
"scenario": "stale_version_race",
"what": "v1 attempt is slow; v2 commits first; v1 then tries to commit -> superseded, v2 result kept",
"seconds": 16.3,
"observed": [
"commit order: [('ready', 'v2: thumbnail,crop,optimized'), ('superseded', 'published v2 is newer than v1')]; v1 objects are unreferenced leftovers for the sweeper"
]
},
{
"scenario": "poison_message",
"what": "a message that violates jobs.schema.json goes to the DLQ instead of looping",
"seconds": 6.4,
"observed": [
"DLQ 1 -> 2"
]
}
],
"final_stats": {
"jobs": {
"superseded": 2,
"failed": 6,
"done": 47
},
"outbox_unpublished": 0,
"queue_ready_messages": 0,
"queue_consumers": 1,
"dlq_messages": 2
}
}
+53
View File
@@ -0,0 +1,53 @@
# fault injection suite (levels 3-4, track 5.2)
# date: 2026-11-10T13:42:20Z, FAULT_INJECTION=1, WORKER_REPLICAS=1, WORKER_CONCURRENCY=2, LEASE_SECONDS=20
# command: python3 student-tests/faults_test.py --output evidence/faults.json
--- worker_down: worker stopped -> upload 202 -> message -> API + broker restart -> worker start -> ready
worker: messenger-lab5-worker-1 exited Exited (0) Less than a second ago
queue before broker restart: {"jobs": {"superseded": 1, "failed": 6, "done": 33, "queued": 1}, "outbox_unpublished": 0, "queue_ready_messages": 1, "queue_consumers": 0, "dlq_messages": 1}
queue after broker restart (volume kept): {"jobs": {"superseded": 1, "failed": 6, "done": 33, "queued": 1}, "outbox_unpublished": 0, "queue_ready_messages": 1, "queue_consumers": 0, "dlq_messages": 1}
attachment 1f804983-862e-4fcc-b3ca-ee2af8564aba ready after worker start; thumbnail 256x160
PASS worker_down (31.1s)
--- outbox_gap: COMMIT done, relay down (= crash between COMMIT and publish) -> relay restart publishes -> ready
relay down: outbox [{'id': 60, 'attempt': '1', 'published': False, 'publish_count': 0}], attachment queued
after relay start: ready, events ['accepted', 'claimed', 'ready']
PASS outbox_gap (15.8s)
--- relay_crash_after_confirm: relay dies after the publisher confirm but before marking the row -> duplicate publish -> worker no-op
events: ['accepted', 'fault_injected', 'claimed', 'ready', 'duplicate_noop']
PASS relay_crash_after_confirm (7.6s)
--- crash_after_claim: crash before any side effect: lease expires, reaper re-enqueues attempt 2
worker.after_claim: ready in 23.9s; events ['accepted', 'claimed', 'fault_injected', 'lease_held_noop', 'lease_expired', 'retry_scheduled', 'claimed', 'ready']; variant attempts [2]
PASS crash_after_claim (28.5s)
--- crash_after_s3: crash after writing S3 objects, before COMMIT: retry overwrites the same keys, one set of variants
worker.after_s3_before_commit: ready in 24.2s; events ['accepted', 'claimed', 'fault_injected', 'lease_held_noop', 'lease_expired', 'retry_scheduled', 'claimed', 'ready']; variant attempts [2]
PASS crash_after_s3 (29.0s)
--- crash_after_commit: crash after COMMIT, before ack: redelivery sees done -> ack as no-op, no second attempt
worker.after_commit_before_ack: ready in 1.7s; events ['accepted', 'claimed', 'ready', 'fault_injected', 'duplicate_noop']; variant attempts [1]
PASS crash_after_commit (6.6s)
--- transient_backoff: two transient failures -> retries with exponential backoff + jitter -> ready on attempt 3
retry delays [1.12, 3.15] (windows [1,2] and [2,4] s)
PASS transient_backoff (12.8s)
--- exhausted_then_replay: 5 transient failures -> failed retry_exhausted (registry) -> explicit replay -> ready; replay of ready refused
failed after 5 attempts, registry entry present
replayed job 5ff64075-edfa-4472-afed-a003bdbb601d (attempt 6 next)
replay of ready: refused: job is done (attachment ready); replay applies only to failed jobs
PASS exhausted_then_replay (38.3s)
--- long_running_not_hung: a 30 s step longer than the 20 s lease: heartbeat renews the lease -> no second attempt
30 s processing with 20 s lease: attempt=1, no lease_expired
PASS long_running_not_hung (37.4s)
--- duplicate: 3 raw duplicates of an already completed job: ack as no-op, nothing rewritten
3 duplicates -> 3 duplicate_noop, updated_at unchanged
PASS duplicate (12.4s)
--- reorder: relay stopped; deliveries arrive out of order: attempt 1, then 1 again and 4, then the outbox backlog
events: ['accepted', 'claimed', 'fault_injected', 'retry_scheduled', 'stale_attempt_noop', 'stale_attempt_noop', 'stale_attempt_noop', 'claimed', 'ready']
PASS reorder (20.2s)
--- new_version: v1 ready -> reprocess v2 -> v2 published; replaying a v1 message afterwards changes nothing
v1 optimized 1090d84ed841.. -> v2 f2878c4a9d89..; stale v1 message: duplicate_noop
PASS new_version (11.9s)
--- stale_version_race: v1 attempt is slow; v2 commits first; v1 then tries to commit -> superseded, v2 result kept
commit order: [('ready', 'v2: thumbnail,crop,optimized'), ('superseded', 'published v2 is newer than v1')]; v1 objects are unreferenced leftovers for the sweeper
PASS stale_version_race (16.3s)
--- poison_message: a message that violates jobs.schema.json goes to the DLQ instead of looping
DLQ 1 -> 2
PASS poison_message (6.4s)
PASS: 14 fault scenarios; final {"jobs": {"superseded": 2, "failed": 6, "done": 47}, "outbox_unpublished": 0, "queue_ready_messages": 0, "queue_consumers": 1, "dlq_messages": 2}
+9
View File
@@ -0,0 +1,9 @@
# worker limits
# date: 2026-11-10T13:41:24Z, branch: solution/bvt2304-koshelev, host: Apple M3 8 CPU 16 GiB, Docker Desktop 28.0.1
# command: python3 student-tests/limits_test.py
big image: 105048 bytes compressed, 6000x6000
PASS default limits (768 MiB, 60 s): ready in 1.0s, {'thumbnail': (256, 256), 'crop': (128, 128), 'optimized': (1280, 1280)}
PASS RLIMIT_AS 160 MiB: failed/image_too_large after 1 attempt
PASS JOB_TIMEOUT 0.3 s: child killed each attempt, 4 retries, then failed/retry_exhausted
PASS: worker limits
+17
View File
@@ -0,0 +1,17 @@
{
"lab": 5,
"workload": "closed-loop POST messages; no automatic retries",
"requested_duration_seconds": 15.0,
"elapsed_seconds": 15.249,
"concurrency": 4,
"successful_requests": 3995,
"failed_requests": 4,
"error_ratio": 0.001,
"successful_rps": 261.986,
"successful_latency_ms": {
"p50": 3.331,
"p95": 6.927,
"p99": 60.411
},
"note": "Latency percentiles cover successes only. Timeouts/errors are counted separately; closed-loop has coordinated omission and client overhead."
}
+33
View File
@@ -0,0 +1,33 @@
# persistence: restart API, worker, relay and all stores (postgres, valkey, s3, rabbitmq) with volumes
# date: 2026-11-10T13:47:05Z
# command: make test-persistence ACTION_SCRIPT=scripts/restart.sh ; hook output below is from a separate run
python3 tests/resilience.py --mode persistence --action-script "scripts/restart.sh" --base-url "http://localhost: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.
## hook run separately to show container states before/after:
NAME STATUS
messenger-lab5-api-1 Up 5 seconds (healthy)
messenger-lab5-api-2 Up 6 seconds (healthy)
messenger-lab5-lb-1 Up 5 seconds (healthy)
messenger-lab5-ops-1 Up 38 seconds (healthy)
messenger-lab5-postgres-1 Up 41 seconds (healthy)
messenger-lab5-rabbitmq-1 Up 41 seconds (healthy)
messenger-lab5-relay-1 Up 35 seconds (healthy)
messenger-lab5-s3-1 Up 41 seconds (healthy)
messenger-lab5-sweeper-1 Up 6 seconds (healthy)
messenger-lab5-valkey-1 Up 41 seconds (healthy)
messenger-lab5-worker-1 Up 6 seconds (healthy)
NAME STATUS
messenger-lab5-api-1 Up 5 seconds (healthy)
messenger-lab5-api-2 Up 5 seconds (healthy)
messenger-lab5-lb-1 Up 5 seconds (healthy)
messenger-lab5-ops-1 Up 37 seconds (healthy)
messenger-lab5-postgres-1 Up 41 seconds (healthy)
messenger-lab5-rabbitmq-1 Up 41 seconds (healthy)
messenger-lab5-relay-1 Up 35 seconds (healthy)
messenger-lab5-s3-1 Up 41 seconds (healthy)
messenger-lab5-sweeper-1 Up 5 seconds (healthy)
messenger-lab5-valkey-1 Up 41 seconds (healthy)
messenger-lab5-worker-1 Up 5 seconds (healthy)
+12
View File
@@ -0,0 +1,12 @@
# functional pipeline suite
# date: 2026-11-10T13:41:17Z, branch: solution/bvt2304-koshelev, host: Apple M3 8 CPU 16 GiB, Docker Desktop 28.0.1
# command: python3 student-tests/pipeline_test.py
PASS sample.png 320x200 -> thumbnail 256x160, crop 128x128, webp 320x200; original byte-identical 1.9s
PASS EXIF orientation applied, EXIF stripped from variants (thumbnail 170x256) 0.2s
PASS RGBA 64x40: no upscaling of thumbnail, alpha composited on white, crop upscaled 0.8s
PASS 2000x500 -> thumbnail 256x64, optimized fit 1280x320 0.2s
PASS PNG with valid CRCs but broken IDAT -> failed/invalid_image after 1 attempt; attach 409, content 409 1.7s
PASS synchronous limits before 202: pixels/bytes 413, type 415, filename 400 0.1s
PASS outsider gets 404 for metadata/original/variant; unknown variant 400 0.2s
PASS: 7 pipeline cases
+6
View File
@@ -0,0 +1,6 @@
# public smoke
# date: 2026-11-10T13:41:13Z, branch: solution/bvt2304-koshelev, host: Apple M3 8 CPU 16 GiB, Docker Desktop 28.0.1
# command: make test
python3 tests/smoke.py --base-url "http://localhost:8080"
PASS: lab5 public API scenario; infrastructure and grading evidence remain separate.
+2
View File
@@ -0,0 +1,2 @@
2026-11-10T13:49:45Z stopped messenger-lab5-api-1 (45db2233b0c2) instance=api-cf4d97a2 state=exited
2026-11-10T13:50:09Z stopped messenger-lab5-api-1 (45db2233b0c2) instance=api-3423c899 state=exited
+26
View File
@@ -0,0 +1,26 @@
# sweeper: staging/orphan retention (grace lowered to 60 s for the demo; default 900 s)
# date: 2026-11-10T13:50:46Z, attachment with a superseded v1 attempt: b25d5064-4db0-4a29-b9fa-fad0b112a60d
## S3 keys before
[
"attachments/b25d50644db04a29b9fafad0b112a60d/original",
"attachments/b25d50644db04a29b9fafad0b112a60d/v1/crop.jpg",
"attachments/b25d50644db04a29b9fafad0b112a60d/v1/optimized.webp",
"attachments/b25d50644db04a29b9fafad0b112a60d/v1/thumbnail.jpg",
"attachments/b25d50644db04a29b9fafad0b112a60d/v2/crop.jpg",
"attachments/b25d50644db04a29b9fafad0b112a60d/v2/optimized.webp",
"attachments/b25d50644db04a29b9fafad0b112a60d/v2/thumbnail.jpg"
]
## dry run
{"dry_run": true, "grace_seconds": 60, "retention_seconds": 86400, "staging_ready_deleted": 0, "staging_failed_expired": 0, "staging_orphans": 0, "final_orphans": 6, "outbox_pruned": 0, "objects_scanned": 209, "duration_ms": 187.3}
## real run
{"dry_run": false, "grace_seconds": 60, "retention_seconds": 86400, "staging_ready_deleted": 0, "staging_failed_expired": 0, "staging_orphans": 0, "final_orphans": 6, "outbox_pruned": 0, "objects_scanned": 209, "duration_ms": 208.3}
## repeat (idempotent)
{"dry_run": false, "grace_seconds": 60, "retention_seconds": 86400, "staging_ready_deleted": 0, "staging_failed_expired": 0, "staging_orphans": 0, "final_orphans": 0, "outbox_pruned": 0, "objects_scanned": 203, "duration_ms": 125.5}
## S3 keys after
[
"attachments/b25d50644db04a29b9fafad0b112a60d/original",
"attachments/b25d50644db04a29b9fafad0b112a60d/v2/crop.jpg",
"attachments/b25d50644db04a29b9fafad0b112a60d/v2/optimized.webp",
"attachments/b25d50644db04a29b9fafad0b112a60d/v2/thumbnail.jpg"
]