feat: add OpenTelemetry SDK, collector and telemetry stores
Collector (contrib), Prometheus, Loki, Tempo and Grafana with provisioning from git; SDK in API and worker with level 3 metrics, traces and logs carrying trace_id/span_id; telemetry off by default outside the stand; broker healthcheck runs as the broker user so a fresh stand starts once. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,148 @@
|
||||
# `driver.py --port 8080 telemetry-check` (change `otel-telemetry`, задача 11.1)
|
||||
|
||||
- Основа: commit `9b35c25` (propose), **рабочее дерево не закоммичено** (apply change
|
||||
`otel-telemetry`); образ `mtusi-messenger:lab6` собран `make run_docker` из этого дерева.
|
||||
Основная сессия решает, переснимать ли после коммита.
|
||||
- Дата: 2026-11-11, старт 06:10:37Z, ~2 мин; рабочий стенд `mtusi-lab6` (две реплики API,
|
||||
worker, Collector, Prometheus, Loki, Tempo, Grafana), команда из корня репозитория:
|
||||
`python3 .claude/skills/run-mtusi-messenger/driver.py --port 8080 telemetry-check`.
|
||||
- Всё — через HTTP API Grafana на `127.0.0.1:3000` с паролем из `.env` (источники-прокси uid
|
||||
`prometheus`, `loki`, `tempo`); пароль, токены и тела в вывод не попадают. Пароль, `username`,
|
||||
токен, текст, ключ и имя файла пробы — случайные синтетические, в выводе только их метки
|
||||
U, P, T, M, K, F.
|
||||
- Сценарии: `observability` — «Стенд с телеметрией», «Хранилища недоступны приложению»,
|
||||
«История после рестарта хранилищ», «Provisioning после старта», «Источник правды — git», «Вход
|
||||
в Grafana», «Ресурс сигналов», «Чужой traceparent», «Запросы в метрике», «Health не
|
||||
учитывается», «Необычный метод и неизвестный путь» (см. ниже), «Готовое вложение в метриках»,
|
||||
«Неудачное вложение в метриках», «Трасса запроса», «Трасса задания», «Отказ S3 в трассе»,
|
||||
«Health и фоновые циклы без трасс», «Проба приватности», «Запрос найден», «Задание найдено»;
|
||||
`service-logging` — «Записи запроса ведут к трассе», «Записи задания ведут к трассе», «Запись в
|
||||
Loki совпадает со stdout»; `service-configuration` — «Переменные OTEL_* не действуют».
|
||||
- Отклонение (design, «Уточнения apply»): метод `BREW` HTTP-парсер uvicorn (httptools) отклоняет
|
||||
400 текстом до приложения — ни span, ни ряда (`KNOWN_ISSUES.md`); ряд `_OTHER` без `http_route`
|
||||
проверен на `PROPFIND` к неизвестному пути с UUID, у обоих — ни метода, ни UUID в метках.
|
||||
- Свой запрос: `X-Request-Id` `acfab668a2fe4b4b865f03382d20a571`, `X-Instance-Id`
|
||||
`dd98da9edd95`, trace-id `73907d1c87e5087abd1b998e3a06c89d`; проба приватности просмотрела
|
||||
44 записи Loki (столько же, сколько записей stdout `api` и `worker` и разового контейнера за
|
||||
окно), 29 трасс Tempo и 860 рядов Prometheus.
|
||||
|
||||
```
|
||||
grafana without credentials expected 401 got 401
|
||||
grafana wrong password expected 401 got 401
|
||||
grafana password from .env expected 200 got 200
|
||||
grafana published only on 127.0.0.1 expected yes got yes
|
||||
datasource prometheus expected 200 prometheus got 200 prometheus
|
||||
datasource prometheus health expected OK got OK
|
||||
datasource loki expected 200 loki got 200 loki
|
||||
datasource loki health expected OK got OK
|
||||
datasource tempo expected 200 tempo got 200 tempo
|
||||
datasource tempo health expected OK got OK
|
||||
dashboard from git expected 200 got 200
|
||||
dashboard provisioned expected True got True
|
||||
dashboard folder expected Messenger got Messenger
|
||||
save of the provisioned dashboard rejected expected yes got yes
|
||||
dashboard equals git after the attempt expected yes got yes
|
||||
prometheus target otel-collector up expected 1 got 1
|
||||
prometheus target otel-collector-exporter up expected 1 got 1
|
||||
prometheus target loki up expected 1 got 1
|
||||
prometheus target tempo up expected 1 got 1
|
||||
prometheus target prometheus up expected 1 got 1
|
||||
register probe user expected 201 got 201
|
||||
login by Basic expected 201 got 201
|
||||
create chat expected 201 got 201
|
||||
send message expected 201 got 201
|
||||
401 without token expected 401 got 401
|
||||
404 of an unknown chat expected 404 got 404
|
||||
BREW rejected by the HTTP parser before the app expected 400 got 400
|
||||
PROPFIND of an unknown path with a UUID expected 404 got 404
|
||||
request with traceparent expected 200 got 200
|
||||
upload sample.png expected 202 got 202
|
||||
attachment becomes ready expected ready got ready
|
||||
undecodable JPEG generated expected yes got yes
|
||||
upload undecodable JPEG expected 202 got 202
|
||||
undecodable JPEG becomes failed expected failed got failed
|
||||
stdout records of the request expected yes got yes
|
||||
one trace_id and span_id in them expected 1 got 1
|
||||
trace_id format expected yes got yes
|
||||
Loki record of the request expected 1 got 1
|
||||
Loki service_name expected messenger-api got messenger-api
|
||||
Loki service_instance_id = X-Instance-Id expected dd98da9edd95 got dd98da9edd95
|
||||
Loki instance_id = X-Instance-Id expected dd98da9edd95 got dd98da9edd95
|
||||
Loki trace_id = stdout expected 73907d1c87e5087abd1b998e3a06c89d got 73907d1c87e5087abd1b998e3a06c89d
|
||||
Loki event, method, path, status, duration = stdout expected yes got yes
|
||||
Tempo server span expected POST /api/v1/chats/{chat_id}/messages SPAN_KIND_SERVER got POST /api/v1/chats/{chat_id}/messages SPAN_KIND_SERVER
|
||||
server span status code expected 201 got 201
|
||||
server span request id = X-Request-Id expected acfab668a2fe4b4b865f03382d20a571 got acfab668a2fe4b4b865f03382d20a571
|
||||
resource service.name expected messenger-api got messenger-api
|
||||
resource service.instance.id expected dd98da9edd95 got dd98da9edd95
|
||||
resource service.version = contract expected 1.6.0 got 1.6.0
|
||||
resource deployment.environment.name expected lab got lab
|
||||
PostgreSQL query spans under it expected yes got yes
|
||||
COMMIT span under it expected yes got yes
|
||||
traceparent request has its own trace expected yes got yes
|
||||
spans of the foreign trace-id in Tempo expected 0 got 0
|
||||
its server span has no parent expected yes got yes
|
||||
Loki worker record of the attachment expected 1 got 1
|
||||
worker stdout records carry the job trace_id expected yes got yes
|
||||
Tempo consumer span expected SPAN_KIND_CONSUMER ready got SPAN_KIND_CONSUMER ready
|
||||
worker resource service.name expected messenger-worker got messenger-worker
|
||||
job spans: PostgreSQL expected yes got yes
|
||||
job spans: S3.GetObject (staging) expected yes got yes
|
||||
job spans: S3.PutObject (original and 3 variants) expected yes got yes
|
||||
job spans: render process expected yes got yes
|
||||
upload with S3 paused expected 503 got 503
|
||||
its server span status expected STATUS_CODE_ERROR got STATUS_CODE_ERROR
|
||||
S3 span with error expected yes got yes
|
||||
S3 span duration within 4.0-7.5 s expected yes got yes
|
||||
error.type of the S3 span set expected yes got yes
|
||||
health traces in Tempo expected 0 got 0
|
||||
trace roots other than requests and deliveries expected 0 got 0
|
||||
api -> prometheus expected not reachable got not reachable
|
||||
api -> loki expected not reachable got not reachable
|
||||
api -> tempo expected not reachable got not reachable
|
||||
api -> grafana expected not reachable got not reachable
|
||||
api -> otel-collector:4318 expected connected got connected
|
||||
worker -> prometheus expected not reachable got not reachable
|
||||
worker -> loki expected not reachable got not reachable
|
||||
worker -> tempo expected not reachable got not reachable
|
||||
worker -> grafana expected not reachable got not reachable
|
||||
worker -> otel-collector:4318 expected connected got connected
|
||||
probe container with OTEL_* started expected 0 got 0
|
||||
probe container healthy expected yes got yes
|
||||
probe request inside expected 401 got 401
|
||||
warning level expected warning got warning
|
||||
warning names the variables expected ['OTEL_EXPORTER_OTLP_ENDPOINT', 'OTEL_SDK_DISABLED'] got ['OTEL_EXPORTER_OTLP_ENDPOINT', 'OTEL_SDK_DISABLED']
|
||||
no variable values in stdout expected yes got yes
|
||||
probe records reach Loki from [telemetry] expected yes got yes
|
||||
probe service_name expected messenger-api got messenger-api
|
||||
chat GET 200 count grew by 10 expected 10 got 10
|
||||
count grew on every replica expected 2 got 2
|
||||
jobs ready grew by 1 expected 1 got 1
|
||||
jobs failed grew by 1 expected 1 got 1
|
||||
_OTHER series without http_route expected yes got yes
|
||||
401 series of /api/v1/users/me expected yes got yes
|
||||
404 series of /api/v1/chats/{chat_id} expected yes got yes
|
||||
forbidden label names expected [] got []
|
||||
label values that are UUIDs expected 0 got 0
|
||||
label values with BREW, PROPFIND or the odd UUID expected 0 got 0
|
||||
dashboard panel queries (11) without error expected 0 got 0
|
||||
panel queries with data after traffic expected [] got []
|
||||
U in telemetry expected [] got []
|
||||
P in telemetry expected [] got []
|
||||
T in telemetry expected [] got []
|
||||
M in telemetry expected [] got []
|
||||
K in telemetry expected [] got []
|
||||
F in telemetry expected [] got []
|
||||
Bearer in telemetry expected [] got []
|
||||
Basic in telemetry expected [] got []
|
||||
foreign trace-id in telemetry expected [] got []
|
||||
pipeline back after restart expected yes got yes
|
||||
same Loki record after restart expected yes got yes
|
||||
same trace after restart expected yes got yes
|
||||
same metric value at the saved time expected 10 got 10
|
||||
PASS: own request and job are found in Loki, Tempo and Prometheus through Grafana, no secrets in telemetry
|
||||
```
|
||||
|
||||
Код выхода — 0. «Same metric value at the saved time» — значение суммы ряда GET карточки чата на
|
||||
момент снимка до рестарта, запрошенное снова после `docker compose restart otel-collector
|
||||
prometheus loki tempo` (параметр `time` запроса).
|
||||
Reference in New Issue
Block a user