Files
mtusi2026lab7/observability/prometheus/rules/messenger.yml
T
kokorindenis a884c07867
Skeleton contracts / contracts (pull_request) Canceled after 0s
solution
2026-11-27 16:42:18 +03:00

81 lines
3.6 KiB
YAML

groups:
- name: messenger-slo
interval: 15s
rules:
- record: sli:messenger_http_error_ratio:5m
expr: |
sum(rate(http_server_requests_total{http_response_status_class="5xx",http_route!~"/health.*"}[5m]))
/
clamp_min(sum(rate(http_server_requests_total{http_route!~"/health.*"}[5m])), 1e-9)
- record: sli:messenger_http_error_ratio:2m
expr: |
sum(rate(http_server_requests_total{http_response_status_class="5xx",http_route!~"/health.*"}[2m]))
/
clamp_min(sum(rate(http_server_requests_total{http_route!~"/health.*"}[2m])), 1e-9)
- record: sli:messenger_http_latency_p95:5m
expr: |
histogram_quantile(
0.95,
sum by (le) (
rate(http_server_duration_seconds_bucket{http_route!~"/health.*"}[5m])
)
)
- alert: MessengerHighErrorRate
# Окно 2m для быстрой реакции и раннего resolved в учебном стенде;
# SLO на dashboard считается по 5m/1h.
expr: sli:messenger_http_error_ratio:2m > 0.02
for: 1m
labels:
severity: critical
slo: api-availability
annotations:
summary: "API 5xx error ratio above 2% (1m)"
description: "5xx/все бизнес-запросы за 2m = {{ $value | humanizePercentage }}; исключены /health и 4xx."
runbook_url: "observability/runbooks.md#high-error-rate-messengerhigherrorrate"
- alert: MessengerQueueLagHigh
expr: max(queue_oldest_job_age_seconds{queue_name="attachment.jobs"}) > 60
for: 2m
labels:
severity: warning
slo: async-processing
annotations:
summary: "Очередь вложений: старейшая job старше 60 s"
description: "Возраст старейшей queued-задачи {{ $value | humanizeDuration }}; проверьте worker/брокер/БД."
runbook_url: "observability/runbooks.md#queue-lag-messengerqueuelaghigh"
- alert: MessengerApiLatencyHigh
expr: sli:messenger_http_latency_p95:5m > 1.0
for: 3m
labels:
severity: warning
slo: api-latency
annotations:
summary: "p95 HTTP latency API выше 1 s (5m)"
description: "p95 = {{ $value | humanizeDuration }}; сравните DB pool и DB spans в trace."
runbook_url: "observability/runbooks.md#latency-messengerapilatencyhigh"
- alert: MessengerWorkerSaturated
expr: |
max(worker_busy / clamp_min(worker_capacity, 1)) > 0.9
for: 5m
labels:
severity: warning
annotations:
summary: "Worker занят > 90% слотов"
description: "Backlog растёт из-за нехватки worker-ёмкости, а не из-за ошибок."
runbook_url: "observability/runbooks.md#worker-saturation-messengerworkersaturated"
- alert: MessengerTelemetryExportFailing
expr: |
sum(rate(otelcol_exporter_send_failed_spans_total[5m])) > 0
or
sum(rate(otelcol_exporter_send_failed_log_records_total[5m])) > 0
for: 2m
labels:
severity: warning
annotations:
summary: "Collector не может экспортировать телеметрию"
description: "Проверьте Tempo/Loki и очередь exporter-а; API продолжает работу."
runbook_url: "observability/runbooks.md#telemetry-outage-messengertelemetryexportfailing"