forked from mtusi2026/mtusi2026lab6
Лаба 6: OpenTelemetry + Grafana наблюдаемость (оценка 4)
Переиспользован стек lab5. API/worker шлют OTLP (traces/metrics/logs) в otel-collector -> Prometheus/Loki/Tempo; Grafana с provisioning датасорсов, дашборда и alert rules в Git. W3C trace context переносится через поле traceparent в задании очереди (API producer span -> worker consumer span в одном trace, подтверждено прямым запросом к Tempo). Три контролируемых инцидента прогнаны и задокументированы (worker down -> queue lag + alert, DB down отличим от медленного handler по error-span, telemetry backend down не роняет API/Collector). В процессе найдены и исправлены 4 реальных бага (middleware после старта приложения, detached span context, замерзающая метрика очереди при падении её единственного источника, неатомарный XACK+XDEL) — см. REPORT.md и evidence/. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
apiVersion: 1
|
||||
|
||||
groups:
|
||||
- orgId: 1
|
||||
name: messenger-slo
|
||||
folder: Messenger
|
||||
interval: 30s
|
||||
rules:
|
||||
- uid: messenger-high-error-rate
|
||||
title: High HTTP error rate
|
||||
condition: C
|
||||
for: 2m
|
||||
data:
|
||||
- refId: A
|
||||
relativeTimeRange: {from: 300, to: 0}
|
||||
datasourceUid: Prometheus
|
||||
model:
|
||||
expr: sum(rate(http_requests_total{status_class="5xx", route!~"/health.*"}[5m])) / sum(rate(http_requests_total{route!~"/health.*"}[5m]))
|
||||
instant: true
|
||||
refId: A
|
||||
- refId: C
|
||||
datasourceUid: "__expr__"
|
||||
model:
|
||||
type: threshold
|
||||
expression: A
|
||||
conditions:
|
||||
- evaluator: {type: gt, params: [0.05]}
|
||||
refId: C
|
||||
labels:
|
||||
severity: critical
|
||||
annotations:
|
||||
summary: "5xx ratio on business requests above 5% for 2 minutes"
|
||||
description: >
|
||||
SLI: 5xx / all business requests (excluding /health*), 5m window.
|
||||
SLO: error ratio < 5%. Runbook: check `db_pool_connections` (DB
|
||||
saturation?) and recent error-level entries in {service_name="messenger-api"}
|
||||
in Loki; correlate via trace_id with Tempo to find the failing dependency.
|
||||
|
||||
- uid: messenger-growing-queue-lag
|
||||
title: Growing attachment queue lag
|
||||
condition: C
|
||||
for: 2m
|
||||
data:
|
||||
- refId: A
|
||||
relativeTimeRange: {from: 60, to: 0}
|
||||
datasourceUid: Prometheus
|
||||
model:
|
||||
expr: max(queue_backlog{metric="oldest_age_seconds"})
|
||||
instant: true
|
||||
refId: A
|
||||
- refId: C
|
||||
datasourceUid: "__expr__"
|
||||
model:
|
||||
type: threshold
|
||||
expression: A
|
||||
conditions:
|
||||
- evaluator: {type: gt, params: [120]}
|
||||
refId: C
|
||||
labels:
|
||||
severity: warning
|
||||
annotations:
|
||||
summary: "Oldest pending attachment job older than 2 minutes"
|
||||
description: >
|
||||
SLI: oldest_age_seconds from queue_backlog. SLO: < 120s under
|
||||
normal load. Runbook: check `worker_concurrency_slots` (busy==capacity
|
||||
sustained => worker saturated) and whether the worker container is
|
||||
running (`docker compose ps worker`); check messenger-worker logs
|
||||
in Loki for repeated processing_failed entries (S3/DB dependency down).
|
||||
@@ -0,0 +1,11 @@
|
||||
apiVersion: 1
|
||||
|
||||
providers:
|
||||
- name: messenger
|
||||
orgId: 1
|
||||
folder: Messenger
|
||||
type: file
|
||||
disableDeletion: false
|
||||
updateIntervalSeconds: 30
|
||||
options:
|
||||
path: /etc/grafana/dashboards
|
||||
@@ -0,0 +1,29 @@
|
||||
apiVersion: 1
|
||||
|
||||
datasources:
|
||||
- name: Prometheus
|
||||
type: prometheus
|
||||
uid: Prometheus
|
||||
access: proxy
|
||||
url: http://prometheus:9090
|
||||
isDefault: true
|
||||
jsonData:
|
||||
timeInterval: 5s
|
||||
|
||||
- name: Loki
|
||||
type: loki
|
||||
uid: Loki
|
||||
access: proxy
|
||||
url: http://loki:3100
|
||||
jsonData:
|
||||
derivedFields:
|
||||
- name: TraceID
|
||||
matcherRegex: "trace_id\":\"(\\w+)\""
|
||||
url: "$${__value.raw}"
|
||||
datasourceUid: tempo
|
||||
|
||||
- name: Tempo
|
||||
type: tempo
|
||||
access: proxy
|
||||
url: http://tempo:3200
|
||||
uid: tempo
|
||||
Reference in New Issue
Block a user