Skip to content

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

Merged
SlavaKuntsov merged 8 commits into
mainfrom
feat/phase-14-observability
Aug 31, 2026
Merged

feat(phase-14): observability — trace propagation, Prometheus/Grafana, metrics and Loki#40
SlavaKuntsov merged 8 commits into
mainfrom
feat/phase-14-observability

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
  • 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
  • curl -u admin:admin http://localhost:3001/api/search?query=flowix → found Flowix — Overview

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)

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.
Update up echo with prometheus/grafana/loki ports and add
metrics/loki-logs/grafana/prometheus targets for phase 14.
@SlavaKuntsov
SlavaKuntsov merged commit 9ded94c into main Aug 31, 2026
4 checks passed
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