This commit is contained in:
2026-11-01 20:38:50 +03:00
parent 470d9d6f1e
commit 3212558ead
120 changed files with 16276 additions and 36 deletions
+2
View File
@@ -0,0 +1,2 @@
python scripts/check_contract.py
PASS: offline skeleton structure, local refs and Python syntax; application NOT tested.
+55
View File
@@ -0,0 +1,55 @@
python student-tests/check_dashboard.py
1. Grafana 12.2.1: datasources prometheus, loki, tempo — provisioned (readOnly); prometheus, loki health OK; tempo answers a search through Grafana
dashboard 'Messenger lab6: API, worker, очередь, SLO' provisioned from messenger.json, 29 panels (same as the JSON in Git)
2. every panel query against its store:
panel unit series query
SLO-1 доступность API, 1 ч (цель ≥ 99%) percentunit 1 messenger:edge_availability:ratio1h
SLO-2 p95 задержки API, 5 мин (цель < 0.5 с) s 1 messenger:http_latency_p95:5m
SLO-3 вложения ready < 30 с, 1 ч (цель ≥ 95%) percentunit 1 messenger:time_to_ready_under_30s:ratio1h
Alerts: pending / firing none 0 max by (alertname, alertstate) (ALERTS)
RPS по маршрутам reqps 4 sum by (http_route) (rate(http_server_request_duration_seconds_count{job="messenger-api"}[1m]))
Ошибки: вход HAProxy и приложение (доля) percentunit 1 messenger:edge_error_ratio:rate2m
Ошибки: вход HAProxy и приложение (доля) percentunit 0 sum(rate(http_server_request_duration_seconds_count{job="messenger-api",http_response_status_code=~"5.."}[2m])) / sum(rate(http_server_request_duratio
Ошибки: вход HAProxy и приложение (доля) percentunit 0 sum(rate(http_server_request_duration_seconds_count{job="messenger-api",http_response_status_code=~"4.."}[2m])) / sum(rate(http_server_request_duratio
Задержка API p50 / p95 / p99 s 1 histogram_quantile(0.50, sum by (le) (rate(http_server_request_duration_seconds_bucket{job="messenger-api"}[5m])))
Задержка API p50 / p95 / p99 s 1 histogram_quantile(0.95, sum by (le) (rate(http_server_request_duration_seconds_bucket{job="messenger-api"}[5m])))
Задержка API p50 / p95 / p99 s 1 histogram_quantile(0.99, sum by (le) (rate(http_server_request_duration_seconds_bucket{job="messenger-api"}[5m])))
p95 по маршрутам s 4 histogram_quantile(0.95, sum by (le, http_route) (rate(http_server_request_duration_seconds_bucket{job="messenger-api"}[5m])))
Ответы клиентам по классам (HAProxy) и готовые short 6 sum by (code) (rate(haproxy_frontend_http_responses_total{proxy="api_in"}[1m]))
Ответы клиентам по классам (HAProxy) и готовые short 1 haproxy_backend_active_servers{proxy="api"}
Запросы в обработке short 1 sum by (instance) (http_server_active_requests{job="messenger-api"})
Глубина очереди (backlog) short 3 max by (state) (messenger_queue_depth{job="messenger-api"})
Глубина очереди (backlog) short 1 max(messenger_outbox_pending{job="messenger-api"})
Возраст старейшего задания (lag) s 1 max(messenger_queue_oldest_age_seconds{job="messenger-api"})
Возраст старейшего задания (lag) s 1 max(messenger_outbox_oldest_age_seconds{job="messenger-api"})
Задания по исходу ops 1 sum by (outcome) (rate(messenger_jobs_processed_total[1m]))
Обработка задания p50 / p95 / p99 (worker) s 0 histogram_quantile(0.50, sum by (le) (rate(messenger_job_duration_seconds_bucket{outcome="ready"}[5m])))
Обработка задания p50 / p95 / p99 (worker) s 0 histogram_quantile(0.95, sum by (le) (rate(messenger_job_duration_seconds_bucket{outcome="ready"}[5m])))
Обработка задания p50 / p95 / p99 (worker) s 0 histogram_quantile(0.99, sum by (le) (rate(messenger_job_duration_seconds_bucket{outcome="ready"}[5m])))
Время до ready p50 / p95 / p99 s 0 histogram_quantile(0.50, sum by (le) (rate(messenger_attachment_time_to_ready_seconds_bucket[5m])))
Время до ready p50 / p95 / p99 s 0 histogram_quantile(0.95, sum by (le) (rate(messenger_attachment_time_to_ready_seconds_bucket[5m])))
Время до ready p50 / p95 / p99 s 0 histogram_quantile(0.99, sum by (le) (rate(messenger_attachment_time_to_ready_seconds_bucket[5m])))
Насыщение worker percentunit 1 sum(messenger_worker_busy) / sum(messenger_worker_capacity)
Пул соединений с БД short 4 sum by (db_client_connection_pool_name, db_client_connection_state) (db_client_connection_count)
Пул соединений с БД short 2 sum by (db_client_connection_pool_name) (db_client_connection_pending_requests)
Пул соединений с БД short 2 sum by (db_client_connection_pool_name) (db_client_connection_max)
CPU процессов (ядер) short 3 sum by (job, instance) (rate(process_cpu_time_seconds_total{job=~"messenger-.*"}[1m]))
CPU процессов (ядер) short 1 rate(otelcol_process_cpu_seconds_total[1m])
Память процессов (RSS) bytes 3 process_memory_usage_bytes{job=~"messenger-.*"}
Память процессов (RSS) bytes 1 otelcol_process_memory_rss_bytes
Память процессов (RSS) bytes 1 otelcol_process_runtime_heap_alloc_bytes
Принято / отправлено / потеряно (в секунду) short 1 sum(rate(otelcol_receiver_accepted_spans_total[1m]))
Принято / отправлено / потеряно (в секунду) short 1 sum(rate(otelcol_exporter_sent_spans_total[1m]))
Принято / отправлено / потеряно (в секунду) short 1 sum(rate(otelcol_exporter_send_failed_spans_total[1m]))
Принято / отправлено / потеряно (в секунду) short 1 sum(rate(otelcol_receiver_accepted_log_records_total[1m]))
Принято / отправлено / потеряно (в секунду) short 1 sum(rate(otelcol_exporter_sent_log_records_total[1m]))
Принято / отправлено / потеряно (в секунду) short 1 sum(rate(otelcol_exporter_send_failed_log_records_total[1m]))
Принято / отправлено / потеряно (в секунду) short 1 sum(rate(otelcol_exporter_sent_metric_points_total[1m]))
Принято / отправлено / потеряно (в секунду) short 1 sum(rate(otelcol_exporter_send_failed_metric_points_total[1m]))
Очереди exporter (пачки) short 3 sum by (exporter) (otelcol_exporter_queue_size)
Очереди exporter (пачки) short 1 max(otelcol_exporter_queue_capacity)
Логи API и worker (предупреждения и ошибки) - 20 {service_name=~"messenger-api|messenger-worker"} | severity_text=~"WARN.*|ERROR|CRITICAL"
Трассы загрузок (последние) - 5 { kind = server && span.messenger.attachment.id != "" }
all queries succeeded; empty (allowed: failure-only panels): 9
3. alert rules loaded and healthy: HighErrorRate (inactive, for 60 s), QueueLagHigh (inactive, for 60 s), TelemetryExportFailing (inactive, for 60 s)
PASS: provisioning from Git, every panel query returns data from Prometheus/Loki/Tempo, alert rules loaded
+63
View File
@@ -0,0 +1,63 @@
docker compose --profile tools run --rm db-test
Container mtusi-lab6-postgres-1 Running
Container mtusi-lab6-postgres-1 Waiting
Container mtusi-lab6-postgres-1 Healthy
Container mtusi-lab6-db-test-run-168f826f7822 Creating
Container mtusi-lab6-db-test-run-168f826f7822 Created
test_1_replay_after_snapshot_keeps_staging (test_cleanup.CleanupRaceTest.test_1_replay_after_snapshot_keeps_staging) ... ok
test_2_cleanup_first_then_replay_waits_and_refuses (test_cleanup.CleanupRaceTest.test_2_cleanup_first_then_replay_waits_and_refuses) ...
snapshot -> replay (queued) -> cleanup: kept [('staging/64162cff-1151-4ba4-9246-def8ec904a03', 'current_work')], nothing deleted
cleanup marked the staging deleted, holds the lock -> replay waited 1 s+ -> refused (source_missing); job stays failed; journal: staging_expired, replay_refused
ok
test_3_replay_first_then_cleanup_waits_and_keeps (test_cleanup.CleanupRaceTest.test_3_replay_first_then_cleanup_waits_and_keeps) ...
replay holds the lock -> cleanup waited -> kept [('staging/714f466f-b839-470d-8364-a66a4006e923', 'current_work')]
ok
test_4_upload_in_progress_is_skipped (test_cleanup.CleanupRaceTest.test_4_upload_in_progress_is_skipped) ...
upload between PUT and COMMIT -> cleanup skipped it (busy); after COMMIT -> current work, kept
ok
test_5_objects_of_processing_job_are_kept (test_cleanup.CleanupRaceTest.test_5_objects_of_processing_job_are_kept) ... ok
test_6_regular_cleanup_still_works (test_cleanup.CleanupRaceTest.test_6_regular_cleanup_still_works) ...
processing job (worker writes the original and variants before COMMIT) -> all 3 objects kept
ok
orphan, staging after ready, objects of a failed attachment after retention -> deleted; published original and variants, a failed attachment within retention -> kept; dry-run deletes nothing
test_backoff_bounds (test_jobs.JobsIntegrationTest.test_backoff_bounds) ... ok
test_claim_once_and_concurrent_claims (test_jobs.JobsIntegrationTest.test_claim_once_and_concurrent_claims) ...
10 concurrent claims of one job: 1 claimed, 9 in_progress
ok
test_expired_lease_and_dead_predecessor (test_jobs.JobsIntegrationTest.test_expired_lease_and_dead_predecessor) ... ok
test_fencing_and_duplicates (test_jobs.JobsIntegrationTest.test_fencing_and_duplicates) ... ok
test_outbox_rows_are_taken_by_one_relay (test_jobs.JobsIntegrationTest.test_outbox_rows_are_taken_by_one_relay) ... ok
test_permanent_error_fails_at_once (test_jobs.JobsIntegrationTest.test_permanent_error_fails_at_once) ... ok
test_replay_rules (test_jobs.JobsIntegrationTest.test_replay_rules) ... ok
test_retry_backoff_then_exhausted (test_jobs.JobsIntegrationTest.test_retry_backoff_then_exhausted) ... ok
test_upload_creates_job_and_outbox_in_one_transaction (test_jobs.JobsIntegrationTest.test_upload_creates_job_and_outbox_in_one_transaction) ... ok
test_concurrent_registration_has_one_winner (test_store.StoreIntegrationTest.test_concurrent_registration_has_one_winner) ... ok
test_concurrent_same_idempotency_key_creates_one_row (test_store.StoreIntegrationTest.test_concurrent_same_idempotency_key_creates_one_row) ...
20 параллельных create_user: 1 создан, 19 получили Conflict (409)
20 одновременных add_message с одним ключом: 1 строка, 1 новое + 19 повторов с тем же сообщением
ok
test_create_chat_rolls_back_when_failing_midway (test_store.StoreIntegrationTest.test_create_chat_rolls_back_when_failing_midway) ... ok
test_database_rejects_message_from_non_member (test_store.StoreIntegrationTest.test_database_rejects_message_from_non_member) ...
чат с несуществующим участником: транзакция откатилась, строк chats/chat_members не осталось
INSERT сообщения от не-участника напрямую в БД: ForeignKeyViolation
ok
test_migrations_rerun_is_noop (test_store.StoreIntegrationTest.test_migrations_rerun_is_noop) ...
schema_migrations: ['001_core', '002_sessions', '003_text_as_bytes', '004_message_idempotency', '005_attachments', '006_jobs']; повторный migrate() ничего не применил
ok
test_old_version_insert_without_key_still_works (test_store.StoreIntegrationTest.test_old_version_insert_without_key_still_works) ... ok
test_same_key_other_body_is_conflict (test_store.StoreIntegrationTest.test_same_key_other_body_is_conflict) ...
INSERT как в lab2 (без ключа) после миграции 004 работает: старая версия совместима со схемой
тот же ключ с другим телом: Conflict (409), в базе по-прежнему одна строка
ok
test_complete_returns_time_to_ready (test_trace_context.TraceContextTest.test_complete_returns_time_to_ready) ... ok
test_upload_span_and_retries_stay_in_one_trace (test_trace_context.TraceContextTest.test_upload_span_and_retries_stay_in_one_trace) ... ok
----------------------------------------------------------------------
Ran 24 tests in 3.396s
OK
+4
View File
@@ -0,0 +1,4 @@
python tests/resilience.py --mode failover --action-script "scripts/stop-one.cmd" --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": 121, "failed_attempts": 0, "first_recovery_seconds": 5.828}
PASS: failover preserved confirmed data and existing session. Hook scope needs operator evidence.
+28
View File
@@ -0,0 +1,28 @@
python student-tests/incident_db.py --down
C. DB unavailable: docker compose pause postgres
t= 20s edge_5xx_ratio= 0.011 app_5xx/s= 0 app_rps=12.787 p95_messages= 0.031s pool_used= 1 pool_waiting= 0 ready_replicas= 2 HighErrorRate=inactive http={'201': 258}
t=21s postgres paused
t= 21s edge_5xx_ratio= 0.011 app_5xx/s= 0 app_rps=12.787 p95_messages= 0.031s pool_used= 1 pool_waiting= 0 ready_replicas= 2 HighErrorRate=inactive http={'201': 264}
t= 36s edge_5xx_ratio= 0.002 app_5xx/s= 0 app_rps= 9.775 p95_messages= 0.043s pool_used= 10 pool_waiting= 5 ready_replicas= 0 HighErrorRate=inactive http={'201': 264}
t= 51s edge_5xx_ratio= 0 app_5xx/s= 0 app_rps= 6.614 p95_messages= 0.047s pool_used= 10 pool_waiting= 20 ready_replicas= 0 HighErrorRate=inactive http={'201': 264, 'timeout': 3, '503': 137}
t= 66s edge_5xx_ratio= 0 app_5xx/s= 0 app_rps= 1.831 p95_messages= 0.045s pool_used= 10 pool_waiting= 34 ready_replicas= 0 HighErrorRate=inactive http={'201': 264, 'timeout': 3, '503': 342}
t= 81s edge_5xx_ratio= 0.117 app_5xx/s= 0 app_rps= 0 p95_messages= nans pool_used= 10 pool_waiting= 49 ready_replicas= 0 HighErrorRate=pending http={'201': 264, 'timeout': 3, '503': 548}
t= 96s edge_5xx_ratio= 0.302 app_5xx/s= 0 app_rps= 0 p95_messages= nans pool_used= 10 pool_waiting= 64 ready_replicas= 0 HighErrorRate=pending http={'201': 264, 'timeout': 3, '503': 754}
t= 111s edge_5xx_ratio= 0.485 app_5xx/s= 0 app_rps= 0 p95_messages= nans pool_used= 10 pool_waiting= 78 ready_replicas= 0 HighErrorRate=pending http={'201': 264, 'timeout': 3, '503': 959}
t= 126s edge_5xx_ratio= 0.658 app_5xx/s= 0 app_rps= 0 p95_messages= nans pool_used= 10 pool_waiting= 93 ready_replicas= 0 HighErrorRate=pending http={'201': 264, 'timeout': 3, '503': 1165}
t= 141s edge_5xx_ratio= 0.822 app_5xx/s= 0 app_rps= 0 p95_messages= nans pool_used= 10 pool_waiting=108 ready_replicas= 0 HighErrorRate=firing http={'201': 264, 'timeout': 3, '503': 1370}
HighErrorRate FIRING at t=141s; ready replicas 0, app requests/s 0: 503 comes from HAProxy itself — no replica passes /health/ready (PostgreSQL)
logs: 111 failed /health/ready checks in 5 min, e.g. GET /health/ready -> 503 (1003.6 ms) request_id=9861289a32724b64ba89d8539e657c8e
t=142s postgres unpaused
t= 142s edge_5xx_ratio= 0.997 app_5xx/s= 0 app_rps= 0 p95_messages= nans pool_used= 10 pool_waiting=108 ready_replicas= 0 HighErrorRate=firing http={'201': 264, 'timeout': 3, '503': 1382}
t= 157s edge_5xx_ratio= 1 app_5xx/s= 0 app_rps= 2.878 p95_messages= 0.048s pool_used= 2 pool_waiting= 0 ready_replicas= 2 HighErrorRate=firing http={'201': 445, 'timeout': 3, '503': 1394}
t= 172s edge_5xx_ratio= 0.89 app_5xx/s= 0 app_rps= 5.495 p95_messages= 0.039s pool_used= 2 pool_waiting= 0 ready_replicas= 2 HighErrorRate=firing http={'201': 643, 'timeout': 3, '503': 1394}
t= 187s edge_5xx_ratio= 0.749 app_5xx/s= 0 app_rps=10.472 p95_messages= 0.031s pool_used= 1 pool_waiting= 0 ready_replicas= 2 HighErrorRate=firing http={'201': 828, 'timeout': 3, '503': 1394}
t= 202s edge_5xx_ratio= 0.614 app_5xx/s= 0 app_rps=12.849 p95_messages= 0.025s pool_used= 0 pool_waiting= 0 ready_replicas= 2 HighErrorRate=firing http={'201': 1023, 'timeout': 3, '503': 1394}
t= 217s edge_5xx_ratio= 0.469 app_5xx/s= 0 app_rps=12.811 p95_messages= 0.025s pool_used= 0 pool_waiting= 0 ready_replicas= 2 HighErrorRate=firing http={'201': 1220, 'timeout': 3, '503': 1394}
t= 232s edge_5xx_ratio= 0.324 app_5xx/s= 0 app_rps= 12.79 p95_messages= 0.025s pool_used= 0 pool_waiting= 0 ready_replicas= 2 HighErrorRate=firing http={'201': 1418, 'timeout': 3, '503': 1394}
t= 247s edge_5xx_ratio= 0.176 app_5xx/s= 0 app_rps=12.886 p95_messages= 0.037s pool_used= 0 pool_waiting= 0 ready_replicas= 2 HighErrorRate=firing http={'201': 1607, 'timeout': 3, '503': 1394}
t= 263s edge_5xx_ratio= 0.027 app_5xx/s= 0 app_rps=12.876 p95_messages= 0.035s pool_used= 0 pool_waiting= 0 ready_replicas= 2 HighErrorRate=firing http={'201': 1803, 'timeout': 3, '503': 1394}
t= 278s edge_5xx_ratio= 0 app_5xx/s= 0 app_rps=12.937 p95_messages= 0.034s pool_used= 0 pool_waiting= 0 ready_replicas= 2 HighErrorRate=inactive http={'201': 2003, 'timeout': 3, '503': 1394}
HighErrorRate RESOLVED at t=278s (136 s after unpause); http codes: {'201': 2003, 'timeout': 3, '503': 1394}
PASS: DB unavailable -> 5xx only at the entry (HAProxy), HighErrorRate firing -> resolved
+41
View File
@@ -0,0 +1,41 @@
python student-tests/incident_db.py
A. slow HTTP handler, healthy DB (fault api_slow_handler=1.5 s in every api replica)
request 5251b25d1bb54d0b92d0ddf565ecf373 -> 201; log event=http.request severity=INFO; trace b3002e4e6c367387a94d2cfe9c1c19f4
messenger-api SERVER POST /api/v1/chats/{chat_id}/messages 1509.8 ms route=/api/v1/chats/{chat_id}/messages status_code=201
messenger-api CLIENT SQL messenger 0.6 ms
messenger-api CLIENT SQL INSERT 1.3 ms
server span 1510 ms, of it in SQL 1.9 ms (slowest SQL INSERT 1.3 ms): the time is spent in the handler, not in the DB
metrics: p95 POST messages = 0.073 s, app 5xx/s = 0, pool waiting = 0
B. slow DB: a session holds LOCK TABLE messages; POST message waits until statement_timeout (5 s) -> 503
t= 20s edge_5xx_ratio= 0 app_5xx/s= 0 app_rps= 4.375 p95_messages= 0.042s pool_used= 0 pool_waiting= 0 ready_replicas= 2 HighErrorRate=inactive http={'201': 264}
t=20s lock taken
request 2bf9d5bf4786487ab0099233a896a582 -> 503; log event=http.request severity=WARN; trace 0c50ab02599e0932544e54b368230bd6
messenger-api SERVER POST /api/v1/chats/{chat_id}/messages 5012.5 ms ERROR route=/api/v1/chats/{chat_id}/messages status_code=503
messenger-api CLIENT SQL messenger 0.5 ms
messenger-api CLIENT SQL SELECT 1.6 ms
messenger-api CLIENT SQL messenger 0.5 ms
messenger-api CLIENT SQL INSERT 5001.6 ms ERROR
server span 5012 ms, of it in SQL 5004 ms; slowest SQL INSERT 5002 ms status ERROR: the DB is slow
t= 40s edge_5xx_ratio= 0 app_5xx/s= 0.095 app_rps= 5.429 p95_messages= 0.033s pool_used= 2 pool_waiting= 0 ready_replicas= 2 HighErrorRate=inactive http={'201': 267, '503': 9}
t= 55s edge_5xx_ratio= 0.009 app_5xx/s= 0.264 app_rps= 5.6 p95_messages= 0.048s pool_used= 3 pool_waiting= 0 ready_replicas= 2 HighErrorRate=inactive http={'201': 267, '503': 18}
t= 70s edge_5xx_ratio= 0.027 app_5xx/s= 0.422 app_rps= 1.661 p95_messages= 7.008s pool_used= 3 pool_waiting= 0 ready_replicas= 2 HighErrorRate=inactive http={'201': 267, '503': 27}
t= 85s edge_5xx_ratio= 0.055 app_5xx/s= 0.578 app_rps= 0.578 p95_messages= 7.375s pool_used= 3 pool_waiting= 0 ready_replicas= 2 HighErrorRate=inactive http={'201': 267, '503': 36}
t= 100s edge_5xx_ratio= 0.1 app_5xx/s= 0.599 app_rps= 0.599 p95_messages= 7.375s pool_used= 3 pool_waiting= 0 ready_replicas= 2 HighErrorRate=pending http={'201': 267, '503': 45}
t= 115s edge_5xx_ratio= 0.117 app_5xx/s= 0.599 app_rps= 0.599 p95_messages= 7.375s pool_used= 3 pool_waiting= 0 ready_replicas= 2 HighErrorRate=pending http={'201': 267, '503': 54}
t= 130s edge_5xx_ratio= 0.163 app_5xx/s= 0.6 app_rps= 0.6 p95_messages= 7.375s pool_used= 3 pool_waiting= 0 ready_replicas= 2 HighErrorRate=pending http={'201': 267, '503': 63}
t= 145s edge_5xx_ratio= 0.655 app_5xx/s= 0.6 app_rps= 0.6 p95_messages= 7.375s pool_used= 2 pool_waiting= 0 ready_replicas= 2 HighErrorRate=pending http={'201': 267, '503': 69}
t= 160s edge_5xx_ratio= 1 app_5xx/s= 0.54 app_rps= 0.54 p95_messages= 7.375s pool_used= 3 pool_waiting= 0 ready_replicas= 2 HighErrorRate=firing http={'201': 267, '503': 78}
HighErrorRate FIRING at t=160s (140 s after the lock)
t=161s lock released (pg_cancel_backend)
t= 161s edge_5xx_ratio= 1 app_5xx/s= 0.54 app_rps= 0.54 p95_messages= 7.375s pool_used= 3 pool_waiting= 0 ready_replicas= 2 HighErrorRate=firing http={'201': 270, '503': 78}
t= 176s edge_5xx_ratio= 1 app_5xx/s= 0.465 app_rps= 1.894 p95_messages= 6.991s pool_used= 0 pool_waiting= 0 ready_replicas= 2 HighErrorRate=firing http={'201': 466, '503': 78}
t= 191s edge_5xx_ratio= 0.36 app_5xx/s= 0.235 app_rps= 6.123 p95_messages= 2.043s pool_used= 4 pool_waiting= 2 ready_replicas= 2 HighErrorRate=firing http={'201': 616, '503': 78}
t= 206s edge_5xx_ratio= 0.143 app_5xx/s= 0.074 app_rps=10.397 p95_messages= 0.04s pool_used= 0 pool_waiting= 0 ready_replicas= 2 HighErrorRate=firing http={'201': 815, '503': 78}
t= 221s edge_5xx_ratio= 0.081 app_5xx/s= 0 app_rps=12.217 p95_messages= 0.025s pool_used= 0 pool_waiting= 0 ready_replicas= 2 HighErrorRate=firing http={'201': 1013, '503': 78}
t= 236s edge_5xx_ratio= 0.045 app_5xx/s= 0 app_rps=12.284 p95_messages= 0.025s pool_used= 0 pool_waiting= 0 ready_replicas= 2 HighErrorRate=firing http={'201': 1212, '503': 78}
t= 251s edge_5xx_ratio= 0.024 app_5xx/s= 0 app_rps=13.186 p95_messages= 0.024s pool_used= 1 pool_waiting= 0 ready_replicas= 2 HighErrorRate=inactive http={'201': 1410, '503': 78}
HighErrorRate RESOLVED at t=251s (90 s after the release); http codes: {'201': 1410, '503': 78}
Summary: how to tell them apart
slow handler: server span 1510 ms, SQL 2 ms, no 5xx, pool free
slow DB: server span 5012 ms, SQL 5004 ms (ERROR, statement timeout), 5xx, pool connections busy; HighErrorRate firing in 140 s, resolved 90 s after the fix
PASS: slow DB vs slow handler distinguished by trace (time in SQL spans) and metrics (5xx, pool); HighErrorRate firing -> resolved
+46
View File
@@ -0,0 +1,46 @@
python student-tests/incident_worker.py
1. baseline (worker running):
t= 15s ready= 0 oldest_age= 0s worker_deliveries/s= 0.06 worker_busy= 0 QueueLagHigh=inactive http={'201': 137, 'upload 202': 2}
2. t=18s docker compose stop worker; uploads continue
t= 19s ready= 0 oldest_age= 0s worker_deliveries/s= 0.07 worker_busy= 0 QueueLagHigh=inactive http={'201': 168, 'upload 202': 3}
t= 34s ready= 0 oldest_age= 0s worker_deliveries/s= 0.06 worker_busy= 0 QueueLagHigh=inactive http={'201': 305, 'upload 202': 6}
t= 49s ready= 4 oldest_age= 19.49s worker_deliveries/s= 0.06 worker_busy= 0 QueueLagHigh=inactive http={'201': 440, 'upload 202': 9}
t= 64s ready= 6 oldest_age= 29.49s worker_deliveries/s= 0.02 worker_busy= 0 QueueLagHigh=inactive http={'201': 574, 'upload 202': 12}
t= 79s ready= 10 oldest_age= 49.49s worker_deliveries/s= — worker_busy= 0 QueueLagHigh=inactive http={'201': 711, 'upload 202': 15}
t= 94s ready= 12 oldest_age= 59.5s worker_deliveries/s= — worker_busy= 0 QueueLagHigh=inactive http={'201': 846, 'upload 202': 18}
t= 109s ready= 16 oldest_age= 79.5s worker_deliveries/s= — worker_busy= 0 QueueLagHigh=inactive http={'201': 984, 'upload 202': 21}
t= 124s ready= 20 oldest_age= 99.51s worker_deliveries/s= — worker_busy= 0 QueueLagHigh=pending http={'201': 1121, 'upload 202': 23}
t= 124s ready= 20 oldest_age= 99.51s worker_deliveries/s= — worker_busy= 0 QueueLagHigh=pending http={'201': 1121, 'upload 202': 23}
t= 139s ready= 22 oldest_age=109.52s worker_deliveries/s= — worker_busy= 0 QueueLagHigh=pending http={'201': 1258, 'upload 202': 26}
t= 154s ready= 25 oldest_age=129.52s worker_deliveries/s= — worker_busy= 0 QueueLagHigh=pending http={'201': 1393, 'upload 202': 29}
t= 169s ready= 27 oldest_age=139.86s worker_deliveries/s= — worker_busy= 0 QueueLagHigh=pending http={'201': 1519, 'upload 202': 32}
t= 184s ready= 31 oldest_age=159.55s worker_deliveries/s= — worker_busy= 0 QueueLagHigh=firing http={'201': 1654, 'upload 202': 35}
3. QueueLagHigh pending at t=124s, FIRING at t=184s (165 s after the worker stopped)
4. t=189s docker compose start worker
t= 197s ready= 33 oldest_age=169.93s worker_deliveries/s= — worker_busy= 0 QueueLagHigh=firing http={'201': 1767, 'upload 202': 38}
t= 212s ready= 31 oldest_age=159.33s worker_deliveries/s= — worker_busy= 1 QueueLagHigh=firing http={'201': 1902, 'upload 202': 41}
t= 227s ready= 19 oldest_age= 96.24s worker_deliveries/s= 0.38 worker_busy= 1 QueueLagHigh=firing http={'201': 2036, 'upload 202': 44}
t= 242s ready= 11 oldest_age= 54.98s worker_deliveries/s= 0.63 worker_busy= 1 QueueLagHigh=firing http={'201': 2174, 'upload 202': 46}
t= 257s ready= 1 oldest_age= 3.16s worker_deliveries/s= 0.82 worker_busy= 0.5 QueueLagHigh=firing http={'201': 2308, 'upload 202': 49}
t= 272s ready= 0 oldest_age= 0s worker_deliveries/s= 0.62 worker_busy= 0 QueueLagHigh=inactive http={'201': 2442, 'upload 202': 52}
QueueLagHigh RESOLVED at t=272s (83 s after the worker started)
all 52 uploads of the run are ready (none lost); final http codes: {'201': 2442, 'upload 202': 52}
5. diagnosis from stored telemetry:
metrics: max oldest_age over 10 min = 170 s; worker deliveries/s fell to 0 while API kept answering 2xx — the queue is not drained, the API is healthy
logs: worker.started (cf67239815a8); worker.stopped (cf67239815a8); worker.started (cf67239815a8)
trace 42f0e6b4e45735295a6ddcff6dca33f of upload 97bd8671-fd20-4454-8d91-54bfd61c9db2 made during the outage: send -> process gap 123 s (message waited in the queue), processing itself 2.19 s
messenger-api SERVER POST /api/v1/chats/{chat_id}/attachments 30.0 ms route=/api/v1/chats/{chat_id}/attachments status_code=202
messenger-api CLIENT S3.PutObject 10.1 ms method=PutObject
messenger-api INTERNAL BackgroundTask nudge 0.8 ms
messenger-api PRODUCER send attachments 4.7 ms attempt=1
messenger-worker CONSUMER process attachments.process 2190.9 ms attempt=1 outcome=ready
messenger-worker INTERNAL jobs.claim 6.8 ms
messenger-worker CLIENT S3.GetObject 8.1 ms method=GetObject
messenger-worker INTERNAL image.process 2066.8 ms
messenger-worker CLIENT S3.PutObject 10.5 ms method=PutObject
messenger-worker CLIENT S3.PutObject 8.1 ms method=PutObject
messenger-worker CLIENT S3.PutObject 8.3 ms method=PutObject
messenger-worker CLIENT S3.PutObject 8.0 ms method=PutObject
messenger-worker INTERNAL jobs.complete 56.7 ms
messenger-worker CLIENT S3.DeleteObject 4.3 ms method=DeleteObject
PASS: worker stopped -> oldest job age grew -> QueueLagHigh firing in 165 s; worker started -> backlog drained, alert resolved in 83 s; no uploads lost
+3
View File
@@ -0,0 +1,3 @@
python tests/resilience.py --mode persistence --action-script "scripts/restart.cmd" --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.
+32
View File
@@ -0,0 +1,32 @@
python student-tests/check_stack.py
docker: 29.6.2
compose: 5.3.1
container_name: not set for any service (replicas of one service are possible)
api replicas running: 2 -> ['58a74eb2cca0', '8e29adaece1b'] (deploy.replicas = 2)
service container cpus memory published ports networks
valkey 12b7cd0a1630 0.50 128Mi - backend
lb 188cafe602f3 0.50 128Mi 127.0.0.1:8080->8080/tcp, 127.0.0.1:8081->8081/tcp, 127.0.0.1:8404->8404/tcp edge, telemetry
prometheus 32f969b6e0f8 1.00 512Mi 127.0.0.1:9090->9090/tcp ops, telemetry
api 58a74eb2cca0 1.00 512Mi - backend, edge, telemetry
grafana 5dcc8779d9a0 1.00 512Mi 127.0.0.1:3000->3000/tcp ops, telemetry
tempo 77fb8493dbae 1.00 512Mi - telemetry
s3 7c0244f96be0 0.50 512Mi - backend
api 8e29adaece1b 1.00 512Mi - backend, edge, telemetry
postgres 99e389223400 1.00 512Mi - backend
loki a25bf9eaddb8 1.00 512Mi - telemetry
otel-collector aaf7048fd9ed 0.50 512Mi - telemetry
worker cf67239815a8 1.00 1024Mi - backend, telemetry
broker eb2e18aeb0c3 1.00 512Mi - backend
published: only lb, grafana (3000) and prometheus (9090), only on 127.0.0.1 (api replicas, OTLP, Loki, Tempo have no ports)
balancer: every api server is under the /health/ready check, no backup servers -> api1 UP (L7OK), api2 UP (L7OK)
limits: every running container has CPU and RAM limits
networks: lb -> edge (+telemetry); api -> edge + backend + telemetry; postgres, valkey, s3, broker -> backend (internal: no way out)
broker: rabbitmq:4.2.9-alpine, volume rabbitmqdata, hostname broker, no ports, no web console; worker: separate service (1 running), no ports
s3: no published ports; master/filer web UIs only on 127.0.0.1 inside the container; IAM API off; pinned image; volume s3data
telemetry: otel-collector otel/opentelemetry-collector-contrib:0.140.1; prometheus prom/prometheus:v3.7.3; loki grafana/loki:3.5.8; tempo grafana/tempo:2.9.0; grafana grafana/grafana:12.2.1
volumes promdata, lokidata, tempodata, grafanadata; OTLP/Loki/Tempo only on internal network telemetry; worker service.name=messenger-worker
secrets: api -> broker_url, cache_url, database_url, s3_access_key_id, s3_secret_access_key; worker -> broker_url, database_url, s3_access_key_id, s3_secret_access_key; broker -> broker_credentials; migrate -> database_url; lb -> none; postgres -> postgres_password; valkey -> valkey_acl; s3 -> s3_config; s3-init -> s3_root_password, s3_root_user; grafana -> grafana_admin_password; otel-collector -> none; prometheus -> none; loki -> none; tempo -> none
images: lb haproxy:3.2.25-alpine; api mtusi-messenger:lab6; worker mtusi-messenger:lab6; postgres postgres:17.10-bookworm; valkey valkey/valkey:8.1.9; s3 chrislusf/seaweedfs:4.44; broker rabbitmq:4.2.9-alpine
PASS: one entry point (lb on 127.0.0.1), >= 2 api replicas without ports and container_name, only ready replicas get traffic, CPU/RAM limits everywhere, stores (incl. S3) only on the internal network, S3 admin credentials only in s3-init; broker and worker are separate services; collector and three telemetry stores + Grafana pinned, with volumes, OTLP only on the internal network
+92
View File
@@ -0,0 +1,92 @@
python -m unittest discover -s student-tests -p "test_*.py" -v
test_auth_checked_before_access_and_body (test_api.MessengerApiTest.test_auth_checked_before_access_and_body) ... ok
test_bad_cursor_returns_400 (test_api.MessengerApiTest.test_bad_cursor_returns_400) ... ok
test_chat_list_pagination (test_api.MessengerApiTest.test_chat_list_pagination) ... ok
test_chat_membership_rules (test_api.MessengerApiTest.test_chat_membership_rules) ... ok
test_duplicate_username_returns_409 (test_api.MessengerApiTest.test_duplicate_username_returns_409) ... ok
test_empty_blank_and_too_long_messages_return_400 (test_api.MessengerApiTest.test_empty_blank_and_too_long_messages_return_400) ... ok
test_malformed_json_returns_400 (test_api.MessengerApiTest.test_malformed_json_returns_400) ... ok
test_nul_character_is_stored (test_api.MessengerApiTest.test_nul_character_is_stored) ... ok
test_outsider_gets_404_for_foreign_chat (test_api.MessengerApiTest.test_outsider_gets_404_for_foreign_chat) ... ok
test_pagination_walks_several_pages (test_api.MessengerApiTest.test_pagination_walks_several_pages) ... ok
test_unicode_roundtrip (test_api.MessengerApiTest.test_unicode_roundtrip) ... ok
test_wrong_types_and_extra_fields_return_400 (test_api.MessengerApiTest.test_wrong_types_and_extra_fields_return_400) ... ok
test_attachment_rules_without_500 (test_attachments.AttachmentTest.test_attachment_rules_without_500) ... ok
test_broken_scan_becomes_failed_and_cannot_be_attached (test_attachments.AttachmentTest.test_broken_scan_becomes_failed_and_cannot_be_attached) ... ok
test_corrupted_images_are_415 (test_attachments.AttachmentTest.test_corrupted_images_are_415) ... ok
test_dangerous_filenames_are_400 (test_attachments.AttachmentTest.test_dangerous_filenames_are_400) ... ok
test_exact_limits (test_attachments.AttachmentTest.test_exact_limits) ... ok
test_idempotency_with_attachments (test_attachments.AttachmentTest.test_idempotency_with_attachments) ... ok
test_large_real_image_within_limits_is_accepted (test_attachments.AttachmentTest.test_large_real_image_within_limits_is_accepted) ... ok
test_message_with_attachments (test_attachments.AttachmentTest.test_message_with_attachments) ... ok
test_mime_spoofing_is_415 (test_attachments.AttachmentTest.test_mime_spoofing_is_415) ... ok
test_outsider_and_anonymous_cannot_upload (test_attachments.AttachmentTest.test_outsider_and_anonymous_cannot_upload) ... ok
test_pixel_bomb_is_413 (test_attachments.AttachmentTest.test_pixel_bomb_is_413) ... ok
test_png_and_jpeg_roundtrip_for_member (test_attachments.AttachmentTest.test_png_and_jpeg_roundtrip_for_member) ... ok
test_structurally_broken_jpeg_is_415 (test_attachments.AttachmentTest.test_structurally_broken_jpeg_is_415) ... ok
test_too_large_is_413_before_reading (test_attachments.AttachmentTest.test_too_large_is_413_before_reading) ... ok
test_too_large_stream_is_413 (test_attachments.AttachmentTest.test_too_large_stream_is_413) ... ok
test_valid_jpeg_variants_are_accepted (test_attachments.AttachmentTest.test_valid_jpeg_variants_are_accepted) ... ok
test_variants_and_bad_ids (test_attachments.AttachmentTest.test_variants_and_bad_ids) ... ok
test_variants_follow_the_contract (test_attachments.AttachmentTest.test_variants_follow_the_contract) ... ok
test_bearer_required_on_business_endpoints (test_auth.AuthTest.test_bearer_required_on_business_endpoints) ... ok
test_login_returns_opaque_token_with_expiry (test_auth.AuthTest.test_login_returns_opaque_token_with_expiry) ... ok
test_logout_revokes_only_current_session (test_auth.AuthTest.test_logout_revokes_only_current_session) ... ok
test_malformed_basic_returns_401 (test_auth.AuthTest.test_malformed_basic_returns_401) ... ok
test_password_length_rules (test_auth.AuthTest.test_password_length_rules) ... ok
test_password_with_colon_and_unicode (test_auth.AuthTest.test_password_with_colon_and_unicode) ... ok
test_relogin_after_logout (test_auth.AuthTest.test_relogin_after_logout) ... ok
test_user_never_contains_password (test_auth.AuthTest.test_user_never_contains_password) ... ok
test_wrong_password_and_unknown_user_look_the_same (test_auth.AuthTest.test_wrong_password_and_unknown_user_look_the_same) ... ok
test_x_user_id_does_not_change_identity (test_auth.AuthTest.test_x_user_id_does_not_change_identity) ... ok
test_instance_id_on_errors_and_health (test_balancing.BalancingTest.test_instance_id_on_errors_and_health) ... ok
test_logout_applies_on_every_replica (test_balancing.BalancingTest.test_logout_applies_on_every_replica) ... ok
test_one_session_is_served_by_every_replica (test_balancing.BalancingTest.test_one_session_is_served_by_every_replica) ... ok
test_session_cache_is_shared_between_replicas (test_balancing.BalancingTest.test_session_cache_is_shared_between_replicas) ... ok
test_write_on_one_replica_read_on_another (test_balancing.BalancingTest.test_write_on_one_replica_read_on_another) ... ok
test_failed_request_does_not_burn_key (test_idempotency.IdempotencyTest.test_failed_request_does_not_burn_key) ... ok
test_json_formatting_does_not_matter (test_idempotency.IdempotencyTest.test_json_formatting_does_not_matter) ... ok
test_key_is_required_and_validated (test_idempotency.IdempotencyTest.test_key_is_required_and_validated) ... ok
test_key_scope_is_user_and_chat (test_idempotency.IdempotencyTest.test_key_scope_is_user_and_chat) ... ok
test_parallel_different_bodies_same_key (test_idempotency.IdempotencyTest.test_parallel_different_bodies_same_key) ... ok
test_parallel_same_key_through_replicas_creates_one_message (test_idempotency.IdempotencyTest.test_parallel_same_key_through_replicas_creates_one_message) ... ok
test_replay_rechecks_session_and_access (test_idempotency.IdempotencyTest.test_replay_rechecks_session_and_access) ... ok
test_replay_through_another_replica_returns_same_message (test_idempotency.IdempotencyTest.test_replay_through_another_replica_returns_same_message) ... ok
test_same_key_other_body_is_409 (test_idempotency.IdempotencyTest.test_same_key_other_body_is_409) ... ok
----------------------------------------------------------------------
Ran 54 tests in 44.119s
OK
10 485 760 байт и 6400×6250 = 40 000 000 px: 202 -> ready; на 1 байт/пиксель больше: 413
fixture 320×200 -> thumbnail 256×160 JPEG, crop 128×128 JPEG, optimized 320×200 WebP; 48×32 -> {'thumbnail': (48, 32), 'crop': (128, 128), 'optimized': (48, 32)}
X-Instance-Id есть в health, 404, 401 и 400
logout через одну реплику -> 401 на ['58a74eb2cca0', '8e29adaece1b']
20 x GET /users/me с одним токеном -> реплики {'8e29adaece1b': 10, '58a74eb2cca0': 10}; это ID запущенных контейнеров api, повторный вход не нужен
10 x GET /users/me через реплики {'8e29adaece1b': 5, '58a74eb2cca0': 5}: попаданий в кэш +20, промахов +0 — кэш общий
сообщение записала реплика 8e29adaece1b, сразу прочитали ['58a74eb2cca0', '8e29adaece1b']
с тем же ключом: сначала 400 (пустой текст), потом 201 — ошибка ключ не заняла
тот же JSON с другими пробелами и переносами -> тот же 201 и то же сообщение
нет ключа, пустой, 129 символов, пробел, '/', кириллица -> 400; 128 символов и ._:- -> 201
тот же ключ у другого пользователя и в другом чате -> независимые сообщения
10 одновременных разных тел с одним ключом: 201 x1, 409 x9, в истории 1 сообщение
20 одновременных POST с одним ключом через реплики {'58a74eb2cca0': 10, '8e29adaece1b': 10}: все 201 с одним id, в истории 1 сообщение
повтор: посторонний -> 404, после logout -> 401, после нового входа -> то же сообщение
1 запрос + 4 повтора через реплики ['58a74eb2cca0', '8e29adaece1b']: 201 и то же сообщение, в истории 1
другой текст с тем же ключом -> 409 conflict, второе сообщение не создано
+44
View File
@@ -0,0 +1,44 @@
python student-tests/check_telemetry.py
1. POST message: X-Request-Id=8be49d40c84c497aba6d04adf33a859c -> Loki: event=http.request severity=INFO service=messenger-api instance=58a74eb2cca0 trace_id=6f3559ea6df4de9a35ecacef79f9661e span_id=ae53b8f0874f223b
Tempo: trace 6f3559ea6df4de9a35ecacef79f9661e, server span ae53b8f0874f223b (request_id matches), 2 SQL spans:
messenger-api SERVER POST /api/v1/chats/{chat_id}/messages 29.7 ms route=/api/v1/chats/{chat_id}/messages status_code=201
messenger-api CLIENT SQL messenger 0.5 ms
messenger-api CLIENT SQL INSERT 1.4 ms
2. upload with one injected transient failure: attachment_id=81376ed2-3d0c-41d4-8048-41365092615d -> 202 queued
one trace f8722248c26bcadcb87de24591b1faa8: SERVER -> PRODUCER -> CONSUMER(attempt 1, retry, ERROR) -> jobs.retry -> PRODUCER(attempt 2) -> CONSUMER(attempt 2, ready) -> 4 x S3 PutObject, SQL under jobs.complete
messenger-api SERVER POST /api/v1/chats/{chat_id}/attachments 36.1 ms route=/api/v1/chats/{chat_id}/attachments status_code=202
messenger-api CLIENT S3.PutObject 9.4 ms method=PutObject
messenger-api INTERNAL BackgroundTask nudge 1.0 ms
messenger-api PRODUCER send attachments 6.8 ms attempt=1
messenger-worker CONSUMER process attachments.process 32.7 ms ERROR attempt=1 outcome=retry
messenger-worker INTERNAL jobs.claim 8.5 ms
messenger-worker CLIENT S3.GetObject 7.5 ms method=GetObject
messenger-worker INTERNAL jobs.retry 10.2 ms error_code=storage_unavailable
messenger-api PRODUCER send attachments 8.5 ms attempt=2
messenger-worker CONSUMER process attachments.process 1075.2 ms attempt=2 outcome=ready
messenger-worker INTERNAL jobs.claim 13.7 ms
messenger-worker CLIENT S3.GetObject 5.4 ms method=GetObject
messenger-worker INTERNAL image.process 1000.5 ms
messenger-worker CLIENT S3.PutObject 10.0 ms method=PutObject
messenger-worker CLIENT S3.PutObject 7.3 ms method=PutObject
messenger-worker CLIENT S3.PutObject 7.3 ms method=PutObject
messenger-worker CLIENT S3.PutObject 6.8 ms method=PutObject
messenger-worker INTERNAL jobs.complete 9.7 ms
messenger-worker CLIENT S3.DeleteObject 4.4 ms method=DeleteObject
Loki by trace_id: worker events ['job.retry', 'job.ready']; api events ['attachment.accepted', 'http.request']
3. metrics of the application in Prometheus:
HTTP requests (counter, method/route/code): 6 series; {'http_request_method': 'POST', 'http_response_status_code': '201', 'http_route': '/api/v1/chats/{chat_id}/messages'}=5, {'http_request_method': 'GET', 'http_response_status_code': '200', 'http_route': '/api/v1/chats/{ch
HTTP duration histogram buckets: 1 series; {}=495
jobs processed by outcome: 2 series; {'messenger_job_type': 'attachment.process', 'outcome': 'ready'}=2, {'messenger_job_type': 'attachment.process', 'outcome': 'retry'}=1
job duration histogram: 2 series; {'outcome': 'ready'}=2, {'outcome': 'retry'}=1
time to ready histogram: 1 series; {}=2
queue depth: 3 series; {'queue': 'attachments.process', 'state': 'ready'}=0, {'queue': 'attachments.process', 'state': 'delayed'}=0, {'queue': 'attachments.process', 'state': 'processing'}=0
oldest job age: 1 series; {'queue': 'attachments.process'}=0
DB pool: 4 series; {'db_client_connection_state': 'used', 'job': 'messenger-worker'}=0, {'db_client_connection_state': 'idle', 'job': 'messenger-worker'}=2, {'db_client_connection_state': 'used', 'job': 'messenger-api'}=0
worker busy/capacity: 1 series; {}=2
process CPU: 2 series; {'job': 'messenger-worker'}=4.72, {'job': 'messenger-api'}=18.57
process RAM: 2 series; {'job': 'messenger-worker'}=1.0086e+08, {'job': 'messenger-api'}=2.75915e+08
1523 series of messenger-api/worker; label names: __name__, db_client_connection_pool_name, db_client_connection_state, deployment_environment_name, http_request_method, http_response_status_code, http_route, instance, job, le, messenger_job_type, network_protocol_version, outcome, queue, service_version, state, telemetry_sdk_language, telemetry_sdk_name, telemetry_sdk_version, type, url_scheme
no ID labels; http_route values are templates: /api/v1/attachments/{attachment_id}, /api/v1/attachments/{attachment_id}/content, /api/v1/auth/sessions, /api/v1/auth/sessions/current, /api/v1/chats, /api/v1/chats/{chat_id}, /api/v1/chats/{chat_id}/attachments, /api/v1/chats/{chat_id}/messages, /api/v1/users, /api/v1/users/me
4. message text, password and session token: 0 hits in Loki (30 min) and in span attributes; no query strings / Authorization in spans
PASS: request -> log -> trace by X-Request-Id/trace_id; upload -> publish -> consume -> retry -> S3/DB in one trace with parent-child links; app metrics without ID labels; no secrets or message bodies in telemetry
+27
View File
@@ -0,0 +1,27 @@
python student-tests/telemetry_outage.py
1. baseline (exporter queue capacity 200 batches, memory_limiter 400 MiB heap, container limit 512 MiB):
t= 15s collector heap= 42.5 rss= 165.7 MiB queues={'loki': 0, 'prometheus': 0, 'tempo': 0} send_failed_total=0 TelemetryExportFailing=inactive http={'201': 136, 'upload 202': 2}
2. t=17s docker compose stop tempo loki (traces and logs stores)
t= 32s collector heap= 27.2 rss= 169.6 MiB queues={'loki': 3, 'prometheus': 0, 'tempo': 3} send_failed_total=0 TelemetryExportFailing=inactive http={'201': 288, 'upload 202': 6}
t= 47s collector heap= 33.6 rss= 169.6 MiB queues={'loki': 11, 'prometheus': 0, 'tempo': 11} send_failed_total=0 TelemetryExportFailing=inactive http={'201': 423, 'upload 202': 9}
t= 62s collector heap= 39.2 rss= 170.1 MiB queues={'loki': 18, 'prometheus': 0, 'tempo': 18} send_failed_total=0 TelemetryExportFailing=inactive http={'201': 547, 'upload 202': 12}
t= 77s collector heap= 43.6 rss= 170.1 MiB queues={'loki': 26, 'prometheus': 0, 'tempo': 26} send_failed_total=0 TelemetryExportFailing=inactive http={'201': 679, 'upload 202': 15}
t= 92s collector heap= 28.0 rss= 170.8 MiB queues={'loki': 33, 'prometheus': 0, 'tempo': 33} send_failed_total=0 TelemetryExportFailing=pending http={'201': 811, 'upload 202': 17}
t= 107s collector heap= 32.7 rss= 170.8 MiB queues={'loki': 40, 'prometheus': 0, 'tempo': 41} send_failed_total=0 TelemetryExportFailing=pending http={'201': 946, 'upload 202': 20}
t= 122s collector heap= 37.8 rss= 170.8 MiB queues={'loki': 48, 'prometheus': 0, 'tempo': 48} send_failed_total=0 TelemetryExportFailing=pending http={'201': 1079, 'upload 202': 23}
t= 137s collector heap= 42.6 rss= 170.8 MiB queues={'loki': 55, 'prometheus': 1, 'tempo': 55} send_failed_total=0 TelemetryExportFailing=pending http={'201': 1215, 'upload 202': 26}
t= 152s collector heap= 47.0 rss= 170.8 MiB queues={'loki': 63, 'prometheus': 0, 'tempo': 63} send_failed_total=0 TelemetryExportFailing=firing http={'201': 1346, 'upload 202': 29}
t= 167s collector heap= 32.3 rss= 170.8 MiB queues={'loki': 70, 'prometheus': 0, 'tempo': 70} send_failed_total=0 TelemetryExportFailing=firing http={'201': 1478, 'upload 202': 32}
t= 182s collector heap= 39.0 rss= 171.5 MiB queues={'loki': 78, 'prometheus': 0, 'tempo': 78} send_failed_total=0 TelemetryExportFailing=firing http={'201': 1613, 'upload 202': 35}
t= 197s collector heap= 45.3 rss= 175.0 MiB queues={'loki': 85, 'prometheus': 0, 'tempo': 85} send_failed_total=0 TelemetryExportFailing=firing http={'201': 1742, 'upload 202': 38}
upload 519f5171-09af-47e7-a0ea-65245c398527 made during the outage -> ready (business path unaffected)
during the outage: every business request succeeded {'201': 1742, 'upload 202': 38}; collector RSS max 175 MiB (heap max 47 MiB < 400 MiB limit); exporter queue max 85 of 200 batches; TelemetryExportFailing firing at t=152s
3. t=200s docker compose start tempo loki
t= 215s collector heap= 50.3 rss= 175.0 MiB queues={'loki': 93, 'prometheus': 0, 'tempo': 93} send_failed_total=0 TelemetryExportFailing=firing http={'201': 1896, 'upload 202': 41}
t= 230s collector heap= 51.7 rss= 175.6 MiB queues={'loki': 1, 'prometheus': 0, 'tempo': 0} send_failed_total=0 TelemetryExportFailing=firing http={'201': 2030, 'upload 202': 44}
t= 245s collector heap= 57.1 rss= 176.3 MiB queues={'loki': 0, 'prometheus': 0, 'tempo': 0} send_failed_total=0 TelemetryExportFailing=inactive http={'201': 2152, 'upload 202': 47}
queues drained and TelemetryExportFailing resolved at t=245s
upload a9b297a8-98b1-4fcb-a8a3-61b5c74473d3 from the middle of the outage: log (X-Request-Id 35573634eee641e9b9eee43ccbf50fc0) and trace ee597afda36071ba1c880f8d3b933b48 arrived after recovery (they waited in the collector queue); telemetry items dropped by exporters during the run: 0
4. docker compose stop otel-collector for 60 s (the SDK cannot export at all)
API answered {'201': 538, 'upload 202': 12} while the collector was down (no errors); API replica RSS 147 -> 148 MiB (SDK queues are bounded: 2048 records per signal)
PASS: telemetry stores and the collector down -> business API unaffected, bounded collector memory and queues, delayed telemetry delivered after recovery, drops are counted
+6
View File
@@ -0,0 +1,6 @@
python student-tests/telemetry_persistence.py
before: trace 1a2016e74cafe0c7717f50c9fe8fb2a8 (36 spans), log of X-Request-Id 86d2785fcf2044339046c8ad3b9b630d, HTTP requests counter at t-120s = 8177
docker compose restart prometheus loki tempo grafana (same containers, volumes kept)
after: trace 1a2016e74cafe0c7717f50c9fe8fb2a8 — 36 spans; log found; counter at the same past moment = 8177
Grafana: dashboard 'Messenger lab6: API, worker, очередь, SLO' still provisioned
PASS: Prometheus, Loki and Tempo keep their history in volumes across a restart
+2
View File
@@ -0,0 +1,2 @@
python tests/smoke.py --base-url "http://127.0.0.1:8080"
PASS: lab6 public API scenario; infrastructure and grading evidence remain separate.