feat: implement lab 6 observability and telemetry cost research
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
# Доказывает: проверки отказов с числами (`pytest -m fault -rP`) на отдельном
|
||||
# стенде vladimirceva-lab6-failures с кодом уровней 3–4 (телеметрия включена):
|
||||
# окна отказа PostgreSQL, Valkey, S3 (503 / 200 / 429 / 400 с временем),
|
||||
# уборка и сверка, pipeline — потеря брокера, relay, worker в трёх точках
|
||||
# краха, исчерпание попыток и replay, staging удалён после ready.
|
||||
# Дата: 2026-11-15, 22:24 UTC; длительность 500 с (pytest — 461,73 с).
|
||||
# Окружение: macOS 26.7.1, Docker 29.9.2, Compose 5.6.1, Python хоста 3.11.9
|
||||
# (pytest в uv-окружении, Python 3.13.15).
|
||||
# Стенд: отдельный (make failure-checks), удаляется самим прогоном.
|
||||
# Код: src_sha256 81c47ffceeb40acc6f333a9265a15480b3e13e2cb53b2e2229e5fa7391bd0b7a
|
||||
# Повторить: make failure-checks FAULT_ARGS=-rP
|
||||
# `...` — пропущены строки сборки и подъёма стенда и хвосты длинных строк
|
||||
# (словарь сверки, поля заданий).
|
||||
|
||||
$ make failure-checks FAULT_ARGS=-rP
|
||||
[failures] project=vladimirceva-lab6-failures
|
||||
...
|
||||
[failures] pytest -m fault
|
||||
collected 212 items / 178 deselected / 34 selected
|
||||
|
||||
student-tests/test_failures.py ........................ [ 70%]
|
||||
student-tests/test_pipeline.py .......... [100%]
|
||||
|
||||
test_database_stopped_and_back:
|
||||
postgres stopped: POST message -> 503 in 0.009s
|
||||
test_frozen_database_and_exhausted_pool:
|
||||
postgres paused: first request -> 503 in 4.01s, second (pool of 1 busy) -> 503 in 1.01s
|
||||
test_readiness_without_database:
|
||||
postgres stopped: /health/ready -> 503 in 0.014s
|
||||
test_valkey_stopped_is_bypassed:
|
||||
valkey stopped: GET chat -> 200 in 0.207s, POST message -> 201 in 0.006s
|
||||
test_valkey_paused_costs_one_timeout:
|
||||
valkey paused: baseline 0.002s, first read 0.206s, second read 0.003s
|
||||
test_upload_with_s3_stopped:
|
||||
s3 stopped: upload -> 503 in 0.048s
|
||||
test_upload_and_download_with_s3_paused:
|
||||
s3 paused: upload -> 503 in 5.02s, download -> 503 in 5.02s
|
||||
test_ready_failure_compensates_and_cleaner_removes_row:
|
||||
queue failed: staging compensated at once, row removed after 24.7s
|
||||
test_kill_between_put_and_ready:
|
||||
killed between PUT and queueing: client got ['RemoteProtocolError']
|
||||
cleaner removed row and object 19.7s after the kill check
|
||||
test_upload_slots_busy_is_429:
|
||||
slots busy: third upload -> 429 in 0.018s (Too many uploads in progress, retry later)
|
||||
test_upload_body_timeout_is_400:
|
||||
slow body: -> 400 in 3.01s (Upload body was not received in time)
|
||||
test_reconcile_finds_and_fixes_both_sides:
|
||||
dry-run: {... 'orphan_object', 'size_mismatch', 'missing_object' ...}
|
||||
after fixes: apply=false strategy=batch deep=false rate=2000 listed_objects=28 checked_rows=7 fresh_objects=0 fresh_rows=0 lost_known=1 found_orphan_object=0 ...
|
||||
test_reconcile_apply_under_uploads:
|
||||
reconcile --apply passes: [0, 0, 0]; uploads: 1902; errors: []
|
||||
test_worker_down_defense_flow:
|
||||
after restarts: {'state': 'ready', 'attempt': 1, 'attempt_base': 0, 'published': True, 'leased': False, 'last_error': '-'}
|
||||
test_broker_restart_keeps_published_job:
|
||||
after broker restart: message visible in queue after 0.6s
|
||||
test_relay_down_keeps_intent_in_outbox:
|
||||
relay back: ready after 4.1s, {'state': 'ready', 'attempt': 1, 'attempt_base': 0, 'published': True, 'leased': False, 'last_error': '-'}
|
||||
test_relay_crash_after_confirm:
|
||||
faulty relay exit=137, job={'state': 'queued', 'attempt': 0, 'attempt_base': 0, 'published': False, 'leased': False, 'last_error': '-'}
|
||||
test_worker_crash_after_objects_before_commit:
|
||||
faulty worker exit=137, objects=['staging', 'original', 'thumbnail', 'crop', 'optimized'], job={'state': 'processing', 'attempt': 1, ...}
|
||||
after lease: ready in 12.9s, {'state': 'ready', 'attempt': 2, 'attempt_base': 0, 'published': True, 'leased': False, 'last_error': '-'}
|
||||
test_worker_crash_after_commit_before_ack:
|
||||
redelivery after commit: {'state': 'ready', 'attempt': 1, 'attempt_base': 0, 'published': True, 'leased': False, 'last_error': '-'}, queue=1 0
|
||||
test_transient_errors_exhaust_then_replay:
|
||||
exhausted: retry_exhausted {'state': 'failed', 'attempt': 3, 'attempt_base': 0, 'published': True, 'leased': False, 'last_error': 's3_read'}
|
||||
test_staging_is_removed_after_ready:
|
||||
staging removed 0.9s after ready; left: ['original', 'thumbnail', 'crop', 'optimized']
|
||||
========== 34 passed, 178 deselected, 1 warning in 461.73s (0:07:41) ===========
|
||||
[failures] cleanup
|
||||
[failures] results: {'fault': 0}
|
||||
|
||||
# Итог: 34 passed, results {'fault': 0}. PostgreSQL недоступен — 503 за 0,01 с,
|
||||
# заморожен — 503 за 4,01 с; S3 остановлен — 503 за 0,05 с; S3 заморожен — 503
|
||||
# за 5,02 с; Valkey остановлен — чтение 200 в обход кэша; очередь: после краха
|
||||
# worker до коммита — ready со 2-й попытки через 12,9 с (аренда), после коммита
|
||||
# до ack — повторная доставка без дубля, исчерпание — failed/retry_exhausted
|
||||
# (3 попытки); сверка под нагрузкой — 3 прохода `--apply`, коды 0, 1902 загрузки,
|
||||
# ошибок нет.
|
||||
@@ -0,0 +1,30 @@
|
||||
# Доказывает: финальная проверка после заполнения REPORT.md и адаптации запуска.
|
||||
# Дата UTC: 2026-11-16; завершено 11:46:31 UTC.
|
||||
# Окружение: macOS 26.6.2 arm64, Docker 28.0.4, Compose 5.6.1,
|
||||
# Python хоста 3.11.12, pytest в Python 3.13.7.
|
||||
# Код: src_sha256 81c47ffceeb40acc6f333a9265a15480b3e13e2cb53b2e2229e5fa7391bd0b7a
|
||||
# Стенд: отдельный make test-isolated, удалён самим runner.
|
||||
# Повторить после sh tools/docker-compat/setup.sh:
|
||||
# export PATH="$PWD/tools/docker-compat:$PATH"
|
||||
# make lint; make check; make test-isolated; make stop
|
||||
# Ниже реальные строки вывода; сборка, прогресс и удаление контейнеров опущены.
|
||||
# pytest: одно StarletteDeprecationWarning об httpx, тесты не пропущены из-за него.
|
||||
|
||||
uv run ruff format --check .
|
||||
uv run ruff check .
|
||||
All checks passed!
|
||||
python3 scripts/check_contract.py
|
||||
PASS: offline skeleton structure, local refs and Python syntax; application NOT tested.
|
||||
[isolated] make test
|
||||
PASS: lab6 public API scenario; infrastructure and grading evidence remain separate.
|
||||
================ 178 passed, 34 deselected, 1 warning in 38.23s ================
|
||||
[isolated] make test-failover (scripts/stop-one.sh)
|
||||
PASS: failover preserved confirmed data and existing session. Hook scope needs operator evidence.
|
||||
PASS
|
||||
[isolated] make test-persistence (scripts/restart.sh)
|
||||
PASS: persistence preserved confirmed data and existing session. Hook scope needs operator evidence.
|
||||
[isolated] results: {'test': 0, 'student-test': 0, 'test-failover': 0, 'attachment-failover': 0, 'test-persistence': 0}
|
||||
|
||||
# Итог: lint/check PASS; 178 passed; все smoke/resilience hooks завершились 0.
|
||||
# После make stop список docker ps пуст; vlad-bench контейнеров не осталось.
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
# Доказывает: проверки без стенда на машине замеров перед треком 1.
|
||||
# Дата UTC: 2026-11-16; выполнено Codex.
|
||||
# Окружение: macOS 26.6.2, Docker 28.0.4, Compose v2.34.0-desktop.1,
|
||||
# Python хоста 3.11.12, Python uv-окружения 3.13.7.
|
||||
# Стенд: без запуска приложения; Docker VM 10 CPU, 8218034176 байт RAM.
|
||||
# Код: src_sha256 81c47ffceeb40acc6f333a9265a15480b3e13e2cb53b2e2229e5fa7391bd0b7a
|
||||
# Повторить: команды ниже из корня репозитория после make install.
|
||||
# Проверка unit-test использует отдельный UV_CACHE_DIR из-за sandbox.
|
||||
# Ниже сокращён только вывод pytest и установки зависимостей, явно отмечено.
|
||||
|
||||
$ make install
|
||||
uv sync
|
||||
Using CPython 3.13.7 interpreter at: /opt/homebrew/opt/python@3.13/bin/python3.13
|
||||
Creating virtual environment at: .venv
|
||||
Resolved 78 packages in 2ms
|
||||
Prepared 10 packages in 1.24s
|
||||
Installed 76 packages in 109ms
|
||||
# ... список установленных пакетов опущен; версии закреплены в uv.lock.
|
||||
|
||||
$ make lint
|
||||
uv run ruff format --check .
|
||||
132 files already formatted
|
||||
uv run ruff check .
|
||||
All checks passed!
|
||||
|
||||
$ make check
|
||||
python3 scripts/check_contract.py
|
||||
PASS: offline skeleton structure, local refs and Python syntax; application NOT tested.
|
||||
|
||||
$ UV_CACHE_DIR=/private/tmp/lab6-uv-cache make unit-test
|
||||
uv run pytest -m unit student-tests/unit
|
||||
# ... заголовок, строки прогресса и путь предупреждения опущены.
|
||||
collected 38 items
|
||||
StarletteDeprecationWarning: Using `httpx` with `starlette.testclient` is deprecated; install `httpx2` instead.
|
||||
38 passed, 1 warning in 2.62s
|
||||
|
||||
$ .venv/bin/python bench/telemetry.py --selftest
|
||||
telemetry selftest: ok
|
||||
$ .venv/bin/python bench/queue.py --selftest
|
||||
queue selftest: ok
|
||||
$ .venv/bin/python bench/analysis.py --selftest
|
||||
analysis selftest: ok
|
||||
$ .venv/bin/python bench/uploads.py --selftest
|
||||
uploads selftest: ok
|
||||
$ .venv/bin/python bench/reconcile.py --selftest
|
||||
reconcile selftest: ok
|
||||
|
||||
$ UV_CACHE_DIR=/private/tmp/lab6-uv-cache make requirements-check
|
||||
uv export --frozen --no-dev --no-emit-project --no-header --format requirements.txt | diff -u requirements.txt - && echo "requirements.txt matches uv.lock"
|
||||
requirements.txt matches uv.lock
|
||||
|
||||
$ UV_CACHE_DIR=/private/tmp/lab6-uv-cache make validate PYTHON=.venv/bin/python
|
||||
.venv/bin/python scripts/validate_openapi.py
|
||||
PASS: full OpenAPI 3.1 and JSON Schema validation; application NOT tested.
|
||||
|
||||
# Линтер, структура, OpenAPI, lock, 38 unit-тестов и 5 selftest прошли.
|
||||
# Эти проверки не доказывают работу контейнеров или результаты нагрузки.
|
||||
@@ -0,0 +1,60 @@
|
||||
# Доказывает: проверки рабочего и изолированных стендов на машине замеров.
|
||||
# Дата UTC: 2026-11-16; выполнено Codex.
|
||||
# Окружение: macOS 26.6.2; Docker 28.0.4; Compose 5.6.1;
|
||||
# Python хоста 3.11.12, pytest в uv-окружении Python 3.13.7.
|
||||
# Docker VM: 10 CPU, 8218034176 байт RAM; рабочий LB http://localhost:8080.
|
||||
# Код: src_sha256 81c47ffceeb40acc6f333a9265a15480b3e13e2cb53b2e2229e5fa7391bd0b7a
|
||||
# Повторить после make install и make env:
|
||||
# sh tools/docker-compat/setup.sh
|
||||
# export PATH="$PWD/tools/docker-compat:$PATH"
|
||||
# make up; make test; make telemetry-check; make test-isolated;
|
||||
# make failure-checks; make stop
|
||||
# Первые попытки запуска выявили совместимость Docker CLI/старого Compose;
|
||||
# обход описан в REPORT.md, код приложения и сигналы не менялись.
|
||||
# Ниже — реальные строки успешного прогона из журнала, в исходном порядке.
|
||||
# ... опущены сборка, подъём/остановка контейнеров, прогресс pytest и предупреждение
|
||||
# StarletteDeprecationWarning об httpx (по одному у каждого набора).
|
||||
|
||||
PASS: lab6 public API scenario; infrastructure and grading evidence remain separate.
|
||||
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-36fc9ebc-me
|
||||
PASS upload accepted: status 202
|
||||
PASS attachment ready: ready
|
||||
PASS message with attachment: status 201
|
||||
PASS API trace found by request id: 8cfe98b66d66ec826b933d24257c231b
|
||||
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 (0.8 ms)
|
||||
PASS API stdout line carries the same trace_id: 2026-11-16T10:06:26.259Z INFO src.http [rid=tcheck-36fc9ebc-me] GET /api/v1/users/me -> 200 (0.8 ms) trace_id=8cfe98b66d66ec826b933d24257
|
||||
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, publish messenger.attachment-jobs, render variants
|
||||
PASS worker consumer span with outcome ready: POST /api/v1/chats/{chat_id}/attachments, S3 get_object, S3 put_object, postgresql read, postgresql transaction, process messenger.attachment-jobs, publish messenger.attachment-jobs, render variants
|
||||
PASS worker log 'attachment processed' with the job trace_id: attachment processed attachment_id=505ea93e-007b-4bc5-8dd6-ef869ccbbe40 job_id=398d2d94-4b5a-4a8d-8d
|
||||
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: 85 log records, 54618 bytes of traces
|
||||
telemetry-check: PASS (22/22 checks)
|
||||
[isolated] ready: lb=http://127.0.0.1:59685 replicas=2
|
||||
[isolated] make test
|
||||
PASS: lab6 public API scenario; infrastructure and grading evidence remain separate.
|
||||
================ 178 passed, 34 deselected, 1 warning in 40.98s ================
|
||||
[isolated] make test-failover (scripts/stop-one.sh)
|
||||
PASS: failover preserved confirmed data and existing session. Hook scope needs operator evidence.
|
||||
PASS
|
||||
[isolated] make test-persistence (scripts/restart.sh)
|
||||
PASS: persistence preserved confirmed data and existing session. Hook scope needs operator evidence.
|
||||
[isolated] results: {'test': 0, 'student-test': 0, 'test-failover': 0, 'attachment-failover': 0, 'test-persistence': 0}
|
||||
[failures] ready: api=http://127.0.0.1:60220 tight=http://127.0.0.1:60225 uploads=http://127.0.0.1:60230 backlog=http://127.0.0.1:60235 vladimirceva-lab6-failures-cleaner vladimirceva-lab6-failures-relay vladimirceva-lab6-failures-worker
|
||||
[failures] pytest -m fault
|
||||
========== 34 passed, 178 deselected, 1 warning in 441.78s (0:07:21) ===========
|
||||
[failures] results: {'fault': 0}
|
||||
|
||||
# Итог: smoke PASS; telemetry-check 22/22; isolated 178 passed и results все 0;
|
||||
# failure-checks 34 passed и fault=0. Тестовые стенды убраны самим runner,
|
||||
# рабочий стенд остановлен перед bench-telemetry-quick.
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
# Доказывает: на отдельном чистом стенде (проект vladimirceva-lab6-isolated,
|
||||
# случайный порт LB, образ собран заново) проходят smoke, свои тесты через
|
||||
# LB (178 passed, в том числе 30 тестов телеметрии и 8 тестов цепочки
|
||||
# trace context), отказ реплики, вложение после остановки принявшей
|
||||
# реплики и сохранность данных после рестарта хранилищ и брокера.
|
||||
# Дата: 2026-11-15, 22:21 UTC; длительность 137 с (рабочий стенд в это время
|
||||
# был поднят и использовался другими проверками).
|
||||
# Окружение: macOS 26.7.1, Docker 29.9.2, Compose 5.6.1, Python хоста 3.11.9
|
||||
# (pytest в uv-окружении, Python 3.13.15).
|
||||
# Стенд: отдельный (make test-isolated), удаляется самим прогоном.
|
||||
# Код: src_sha256 81c47ffceeb40acc6f333a9265a15480b3e13e2cb53b2e2229e5fa7391bd0b7a
|
||||
# Повторить: make test-isolated
|
||||
# `...` — пропущены строки сборки образа и подъёма контейнеров.
|
||||
|
||||
$ make test-isolated
|
||||
python3 student-tests/stand.py isolated
|
||||
[isolated] project=vladimirceva-lab6-isolated
|
||||
[isolated] build image
|
||||
...
|
||||
[isolated] start postgres, valkey, s3 and rabbitmq
|
||||
...
|
||||
[isolated] s3 bootstrap
|
||||
[isolated] migrations
|
||||
...
|
||||
[isolated] ready: lb=http://127.0.0.1:50017 replicas=2
|
||||
[isolated] make test
|
||||
PASS: lab6 public API scenario; infrastructure and grading evidence remain separate.
|
||||
[isolated] pytest
|
||||
============================= test session starts ==============================
|
||||
platform darwin -- Python 3.13.15, pytest-9.1.1, pluggy-1.6.0
|
||||
configfile: pyproject.toml
|
||||
testpaths: student-tests
|
||||
plugins: anyio-4.15.1
|
||||
collected 212 items / 34 deselected / 178 selected
|
||||
|
||||
student-tests/test_attachments.py ...................................... [ 21%]
|
||||
........ [ 25%]
|
||||
student-tests/test_auth.py ...................... [ 38%]
|
||||
student-tests/test_balancing.py ... [ 39%]
|
||||
student-tests/test_cache.py .... [ 42%]
|
||||
student-tests/test_idempotency.py ................... [ 52%]
|
||||
student-tests/test_processing.py .......... [ 58%]
|
||||
student-tests/test_race.py .... [ 60%]
|
||||
student-tests/test_request_id.py ............. [ 67%]
|
||||
student-tests/test_rubric.py ................... [ 78%]
|
||||
student-tests/unit/test_telemetry.py .............................. [ 95%]
|
||||
student-tests/unit/test_trace_chain.py ........ [100%]
|
||||
|
||||
=============================== warnings summary ===============================
|
||||
student-tests/unit/test_telemetry.py:23
|
||||
StarletteDeprecationWarning: Using `httpx` with `starlette.testclient` is deprecated
|
||||
================ 178 passed, 34 deselected, 1 warning in 44.60s ================
|
||||
[isolated] make test-failover (scripts/stop-one.sh)
|
||||
Executing explicit failover hook; hook output suppressed to avoid leaking secrets.
|
||||
{"observed_instances_before": 2, "successful_writes": 128, "failed_attempts": 0, "first_recovery_seconds": 1.297}
|
||||
PASS: failover preserved confirmed data and existing session. Hook scope needs operator evidence.
|
||||
[isolated] restore replicas
|
||||
...
|
||||
[isolated] attachment failover (scripts/lab6.py, stop the uploader)
|
||||
...
|
||||
PASS
|
||||
[isolated] make test-persistence (scripts/restart.sh)
|
||||
Executing explicit persistence hook; hook output suppressed to avoid leaking secrets.
|
||||
PASS: persistence preserved confirmed data and existing session. Hook scope needs operator evidence.
|
||||
[isolated] cleanup
|
||||
[isolated] results: {'test': 0, 'student-test': 0, 'test-failover': 0, 'attachment-failover': 0, 'test-persistence': 0}
|
||||
|
||||
# Итог: results — все 0; 178 passed (34 deselected — проверки отказов,
|
||||
# их гоняет make failure-checks); при отказе реплики 128 успешных записей,
|
||||
# 0 неудачных, первое восстановление 1,3 с.
|
||||
@@ -0,0 +1,13 @@
|
||||
# Доказывает: публичный smoke лабы 6 (регистрация, вход, чат, загрузка 202,
|
||||
# ready, оригинал, thumbnail 256×160) проходит через LB на рабочем стенде.
|
||||
# Дата: 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.
|
||||
# Код: src_sha256 81c47ffceeb40acc6f333a9265a15480b3e13e2cb53b2e2229e5fa7391bd0b7a
|
||||
# Повторить: make up && make test
|
||||
|
||||
$ make test
|
||||
python3 tests/smoke.py --base-url "http://localhost:8180"
|
||||
PASS: lab6 public API scenario; infrastructure and grading evidence remain separate.
|
||||
|
||||
# Итог: PASS (2 с).
|
||||
Reference in New Issue
Block a user