feat: implement lab 6 observability and telemetry cost research

This commit is contained in:
2026-11-20 14:34:40 +03:00
parent 470d9d6f1e
commit 4f4e07a453
233 changed files with 79726 additions and 16 deletions
+43
View File
@@ -0,0 +1,43 @@
# Доказывает (уровни 3–4): стек наблюдаемости работает на рабочем стенде —
# Grafana с тремя источниками и dashboard (26 панелей); у контрольного
# запроса одна трасса в Tempo, запись в Loki и строка stdout с тем же
# trace_id; трасса загрузки доходит до worker (consumer span, outcome ready);
# метрики API, worker, relay, resource attributes; метки без id, URL и имён
# файлов; в телеметрии нет пароля, токена, текста сообщения, filename.
# Дата: 2026-11-15, 22:21 UTC.
# Окружение: macOS 26.7.1, Docker 29.9.2, Compose 5.6.1, Python хоста 3.11.9.
# Стенд: рабочий (make up); LB 127.0.0.1:8180, Grafana 127.0.0.1:3180.
# Код: src_sha256 81c47ffceeb40acc6f333a9265a15480b3e13e2cb53b2e2229e5fa7391bd0b7a
# Повторить: make up && make telemetry-check
$ make telemetry-check
python3 scripts/lab6.py telemetry-check --base-url "http://localhost:8180"
PASS grafana /api/health: status 200
PASS datasources provisioned: ['logs', 'metrics', 'traces']
PASS dashboard messenger-lab6 provisioned: status 200, panels 26
PASS controlled request GET /api/v1/users/me: status 200, X-Request-Id tcheck-7eaa7b98-me
PASS upload accepted: status 202
PASS attachment ready: ready
PASS message with attachment: status 201
PASS API trace found by request id: 60e5d0f213673aa90c8f6f69e4dcd077
PASS server span with route template: 2 spans: GET /api/v1/users/me, postgresql read
PASS no spans from FastAPI native telemetry: []
PASS API log record in Loki with the same trace_id: GET /api/v1/users/me -> 200 (1.2 ms)
PASS API stdout line carries the same trace_id: 2026-11-15T22:21:42.677Z INFO src.http [rid=tcheck-7eaa7b98-me] GET /api/v1/users/me -> 200 (1.2 ms) trace_id=60e5d0f2...
PASS upload trace has PostgreSQL and S3 child spans: POST /api/v1/chats/{chat_id}/attachments, S3 get_object, S3 put_object, postgresql read, postgresql transaction, process messenger.attachment-jobs
PASS worker consumer span with outcome ready: ... process messenger.attachment-jobs, publi...
PASS worker log 'attachment processed' with the job trace_id: attachment processed attachment_id=b28e18e8-... job_id=a1b6e40c-... trace_id=...
PASS HTTP duration histogram (API): count 3
PASS job duration histogram (worker, ready): count 2
PASS relay published counter: 2
PASS resource attributes (target_info): messenger-api@0.6.0/lab, messenger-relay@0.6.0/lab, messenger-worker@0.6.0/lab
PASS HTTP histogram has a single source: rate 0
PASS metric labels without ids, raw URLs and filenames: 35 series
PASS no password, token, message text, filename or Authorization in telemetry: 84 log records, 63821 bytes of traces
telemetry-check: PASS (22/22 checks)
# Итог: 22/22. Пара «трасса — запись журнала» у контрольного запроса:
# trace_id 60e5d0f2… в Tempo, в Loki и в stdout API (1 пара запрос → трасса →
# лог); у загрузки — трасса с PostgreSQL, S3 и consumer span worker и строка
# worker `attachment processed` с trace_id задания (вторая пара). Утечек
# секретов и текстов в 84 записях журнала и 63 821 байте трасс нет.
+25
View File
@@ -0,0 +1,25 @@
# Доказывает (уровень 4, телеметрия не ломает приложение): Tempo остановлен
# на 120 с под нагрузкой — API отвечает, загрузки принимаются и доходят до
# ready, память Collector ограничена очередью экспорта (20000 элементов),
# потери span считает сам Collector, после возврата Tempo экспорт
# возобновляется и очередь опустошается.
# Дата: 2026-11-15, 22:40 UTC; длительность 146 с.
# Окружение: macOS 26.7.1, Docker 29.9.2, Compose 5.6.1, Python хоста 3.11.9.
# Стенд: рабочий (make up); LB 127.0.0.1:8180.
# Код: src_sha256 81c47ffceeb40acc6f333a9265a15480b3e13e2cb53b2e2229e5fa7391bd0b7a
# Повторить: make up && make telemetry-outage [OUTAGE_SECONDS=120]
$ make telemetry-outage
python3 scripts/lab6.py telemetry-outage --base-url "http://localhost:8180" --seconds 120
before: collector 58 MiB, spans lost so far 0
PASS API answers during 120 s without Tempo: GET /users/me statuses {200: 1178}
PASS uploads accepted and processed without Tempo: 11 uploads, ready 11
PASS Collector memory bounded: peak 63 MiB of 256 MiB limit; export queue peak 2060 of 20000 items
PASS lost spans are counted by the Collector: 128 spans (send_failed + enqueue_failed, otlp_http/tempo)
PASS Tempo back: export resumes, queue drained: queue now 37 items
telemetry-outage: PASS (5/5 checks, 146 s)
# Итог: 5/5. За 120 с без Tempo: 1178 ответов 200, 11 из 11 загрузок ready,
# пик Collector 63 МиБ из 256, очередь экспорта пик 2060 из 20000, потеряно
# 128 span (учтены метрикой Collector), после возврата Tempo очередь 37.
# Потери SDK (до Collector) метрикой не считаются — KNOWN_ISSUES.md.
+52
View File
@@ -0,0 +1,52 @@
# Доказывает (уровень 4, перенос контекста через очередь): загрузка вложения
# даёт ОДНУ трассу от API через outbox, relay и RabbitMQ до worker; при
# сбое S3 первая попытка worker (outcome=retry, S3 get_object ERROR) и
# вторая (outcome=ready) лежат в той же трассе, каждый consumer span —
# ребёнок producer span своей попытки (parent, не link).
# Дата: 2026-11-15, 22:22 UTC.
# Окружение: macOS 26.7.1, Docker 29.9.2, Compose 5.6.1, Python хоста 3.11.9.
# Стенд: рабочий (make up); LB на 127.0.0.1:8180, Tempo — внутри сети compose.
# Код: src_sha256 81c47ffceeb40acc6f333a9265a15480b3e13e2cb53b2e2229e5fa7391bd0b7a
# Повторить: make up && make trace-chain
$ make trace-chain
python3 scripts/lab6.py trace-chain --base-url "http://localhost:8180"
PASS upload accepted, worker stopped: status 202
attachment_id=4c43f2f1-460f-4b68-a802-c2383ade1e00
PASS attempt 1 failed (S3 stopped), job back to queued: 1 queued s3_read
PASS attachment ready on a later attempt: ready
job: 2 ready -
PASS one trace for the upload in Tempo: trace ids found: 1
trace_id=46d5f182d2a0166f605d4babd09b853b (Grafana → Explore → Tempo → 46d5f182d2a0166f605d4babd09b853b)
messenger-api: POST /api/v1/chats/{chat_id}/attachments [server] 66.3 ms
messenger-api: postgresql read [client] 2.7 ms
messenger-api: postgresql read [client] 4.7 ms
messenger-api: postgresql transaction [client] 6.4 ms
messenger-api: S3 put_object [client] 30.0 ms
messenger-api: postgresql transaction [client] 10.5 ms
messenger-relay: publish messenger.attachment-jobs [producer] 10.4 ms attempt=1
messenger-worker: process messenger.attachment-jobs [consumer] 664.4 ms attempt=1 outcome=retry
messenger-worker: postgresql transaction [client] 20.6 ms
messenger-worker: S3 get_object [client] 623.2 ms ERROR
messenger-worker: postgresql transaction [client] 11.8 ms
messenger-relay: publish messenger.attachment-jobs [producer] 3.6 ms attempt=2
messenger-worker: process messenger.attachment-jobs [consumer] 201.2 ms attempt=2 outcome=ready
messenger-worker: postgresql transaction [client] 18.6 ms
messenger-worker: S3 get_object [client] 7.7 ms
messenger-worker: render variants [client] 156.1 ms
messenger-worker: S3 put_object [client] 4.6 ms
messenger-worker: S3 put_object [client] 1.6 ms
messenger-worker: S3 put_object [client] 1.4 ms
messenger-worker: S3 put_object [client] 1.6 ms
messenger-worker: postgresql transaction [client] 4.3 ms
PASS root: API server span of the upload: POST /api/v1/chats/{chat_id}/attachments
PASS relay producer spans are children of the upload span: 2 publish spans
PASS worker consumer spans are children of the producer of the same attempt: attempts [1, 2]
PASS attempt 1 outcome retry in the same trace: retry
PASS ready attempt reaches S3 and PostgreSQL: S3 get_object, S3 put_object, postgresql transaction, render variants
trace-chain: PASS (9/9 checks, 33 s)
# Итог: 9/9. Одна трасса (46d5f182…) содержит server span API, два producer
# span relay (попытки 1 и 2) и два consumer span worker: попытка 1 — retry с
# ошибкой S3, попытка 2 — ready. Контекст идёт через строку задания в
# PostgreSQL и заголовки AMQP, не через тело сообщения.