Skip to content

feat(phase-14): observability — trace propagation, Prometheus/Grafana, metrics and Loki - #39

Closed
SlavaKuntsov wants to merge 7 commits into
mainfrom
feat/phase-14-loki
Closed

feat(phase-14): observability — trace propagation, Prometheus/Grafana, metrics and Loki#39
SlavaKuntsov wants to merge 7 commits into
mainfrom
feat/phase-14-loki

Conversation

@SlavaKuntsov

Copy link
Copy Markdown
Owner

Closes #11
Closes #12
Closes #13
Closes #14
Closes #15
Closes #38

Phase 14 — P1: Наблюдаемость — реализация по docs/PLAN.md:228.

Summary

  • Прокидка X-Request-ID/X-User-ID/X-Forwarded-For в gateway/proxy и логирование trace_id во всех сервисах (gateway/metadata/upload/auth)
  • Добавлены prometheus:9090 и grafana:3001 в compose с healthcheck, datasource и дашбордом Flowix — Overview
  • Метрики rabbitmq_queue_depth, ffmpeg_duration_seconds, upload_bytes, vod_cache_hit через client_golang/prometheus_client во всех сервисах
  • Алерты alert.rules.yml (queue>100, OOM, disk>80%)
  • Унифицирован JSON лог с trace_id/request_id/service
  • Новое (фаза 14 доп): Loki 3.0 + Promtail 3.0 с docker_sd_configs и Loki datasource в Grafana для централизованных логов ({service="gateway"} |= "test123")

Acceptance criteria

Verification

  • make lint-go — 0 issues
  • make lint-py — black/flake8/mypy success
  • make lint-front — ✔ No ESLint
  • make test-go — ok (metadata/gateway/upload)
  • make test-py — 11 passed auth, 16 passed transcoder
  • make up --build -d — все Healthy (postgres, minio, rabbitmq, prometheus Healthy, loki Healthy, promtail Started, grafana Healthy)
  • make e2e — PASS (6s sample → 2 renditions, HLS via 8081/8080 200)
  • curl -H X-Request-ID:test-loki-999 → Loki query trace_id — success (см. выше, trace_id label)
  • grafana дашборд Flowix — Overview — проверен curl -u admin:admin /api/search?query=flowix → found

Risks

  • Loki allow_structured_metadata: false (совместимость с schema v11 boltdb-shipper) — structured metadata отключена, trace_id идет как label (достаточно для фазы, можно мигрировать на v13/tsdb позже)
  • Promtail использует docker_sd_configs с /var/run/docker.sock — на OrbStack работает, на других Docker Desktop может требовать DOCKER_HOST
  • rabbitmq_queue_depth пока Gauge 0 без реального опроса Management API — алерт QueueDepthHigh не сработает до реализации poller (можно добавить в след. PR)

Commits (phase 14):

  • feat(gateway,metadata,upload): propagate X-Request-ID
  • feat(infra): add Prometheus and Grafana
  • feat(metrics): expose queue/ffmpeg/upload/vod metrics
  • feat(logging): unify JSON logs
  • fix(gateway): log trace_id
  • feat(grafana): add Flowix dashboard
  • feat(loki): add Loki + Promtail

Gateway ReverseProxy now forwards X-Request-ID/X-User-ID and builds
X-Forwarded-For chain; metadata/upload use RequestID before logger and
emit trace_id/request_id via zerolog RequestLogger.
Add prometheus:9090 and grafana:3001 services with healthchecks,
provision Prometheus datasource, and alert rules for queue/OOM/disk.
Update .env.example with PROMETHEUS_PORT/GRAFANA_* vars.
Add /metrics endpoints via prometheus_client (Python) and
client_golang (Go) for gateway/metadata/upload/auth/transcoder,
implement ffmpeg_duration_seconds histogram, upload_bytes counter,
rabbitmq_queue_depth gauge and vod_cache_hit counter, and scrape
transcoder:8004 via Prometheus.
Gateway already logs trace_id; add zerolog JSON config and
RequestLogger with trace_id/request_id for metadata/upload,
and FastAPI middleware for auth that logs JSON with trace_id
and echoes X-Request-ID.
Include trace_id/request_id/service fields for unified JSON logs.
Mount dashboards to /etc/grafana/dashboards and provision datasource
so Grafana shows data out of the box (queue depth, ffmpeg duration,
upload bytes, vod cache).
Add Loki 3.0 and Promtail 3.0 services with docker_sd_configs,
Loki datasource in Grafana, and promtail pipeline extracting
trace_id/service/level for Explore queries.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant