Files
mtusi2026lab7/infra/prometheus/rules/messenger.yml

126 lines
6.7 KiB
YAML
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# SLI / SLO / alerts мессенджера (lab6).
#
# SLI доступности API = доля НЕ-5xx среди бизнес-запросов.
# numerator — запросы с http_response_status_code 5xx;
# denominator — все запросы API (health исключены ещё в инструментировании:
# excluded_urls=/health/live,/health/ready), 4xx — не ошибка сервиса
# (неверный пароль клиента ≠ отказ БД).
# SLO: 99 % запросов без 5xx за скользящий час; p95 latency < 500 ms;
# p95 времени upload → ready < 30 s.
# p95/p99 считаются из buckets histogram, суммированных по всем репликам (sum by le),
# а не усреднением перцентилей реплик. «or vector(0)» — пока 5xx не было, серии-числителя
# нет, и без него доля ошибок была бы «пусто», а не 0.
# Runbook каждого alert — infra/prometheus/RUNBOOK.md.
groups:
- name: messenger-sli
interval: 15s
rules:
- record: messenger:http_requests:rate1m
expr: sum by (job) (rate(http_server_request_duration_seconds_count[1m]))
- record: messenger:http_errors:ratio1m
expr: |
(sum(rate(http_server_request_duration_seconds_count{http_response_status_code=~"5.."}[1m])) or vector(0))
/ sum(rate(http_server_request_duration_seconds_count[1m]))
- record: messenger:http_errors:ratio5m
expr: |
(sum(rate(http_server_request_duration_seconds_count{http_response_status_code=~"5.."}[5m])) or vector(0))
/ sum(rate(http_server_request_duration_seconds_count[5m]))
- record: messenger:http_errors:ratio1h
expr: |
(sum(rate(http_server_request_duration_seconds_count{http_response_status_code=~"5.."}[1h])) or vector(0))
/ sum(rate(http_server_request_duration_seconds_count[1h]))
- record: messenger:http_latency_seconds:p95_5m
expr: histogram_quantile(0.95, sum by (le) (rate(http_server_request_duration_seconds_bucket[5m])))
- record: messenger:time_to_ready_seconds:p95_15m
expr: histogram_quantile(0.95, sum by (le) (rate(messenger_attachment_time_to_ready_seconds_bucket[15m])))
# Обе реплики API публикуют один и тот же gauge очереди (считается из БД) — берём max.
- record: messenger:queue_oldest_age_seconds:max
expr: max by (queue) (messenger_queue_oldest_age_seconds)
- name: messenger-alerts
interval: 15s
rules:
- alert: ApiHighErrorRate
# Окно 1m, порог 5 % (в 5 раз выше бюджета SLO 1 %), держится 1m.
# Минимальный трафик 0.05 rps — чтобы 1 ошибка из 2 запросов не будила.
expr: |
messenger:http_errors:ratio1m > 0.05
and on() sum(rate(http_server_request_duration_seconds_count[1m])) > 0.05
for: 1m
labels:
severity: page
annotations:
summary: "API: {{ $value | humanizePercentage }} ответов 5xx за 1m (порог 5 %)"
description: "SLO 99 % не-5xx/час под угрозой. Ищите error-span в Tempo и WARNING http.request в Loki."
runbook: "infra/prometheus/RUNBOOK.md#apihigherrorrate"
- alert: ApiErrorBudgetBurnFast
# Burn rate 14.4 = весь месячный бюджет 1 % за ~2 дня; два окна (5m и 1h)
# — короткий всплеск сам по себе не срабатывает, длинная деградация ловится.
expr: messenger:http_errors:ratio5m > (14.4 * 0.01) and messenger:http_errors:ratio1h > (14.4 * 0.01)
for: 2m
labels:
severity: page
annotations:
summary: "API сжигает error budget в 14.4× быстрее нормы"
runbook: "infra/prometheus/RUNBOOK.md#apihigherrorrate"
- alert: ApiLatencyP95High
expr: messenger:http_latency_seconds:p95_5m > 0.5
for: 5m
labels:
severity: ticket
annotations:
summary: "API p95 = {{ $value | humanizeDuration }} (SLO < 500ms)"
runbook: "infra/prometheus/RUNBOOK.md#apilatencyp95high"
- alert: AttachmentQueueLagGrowing
# Возраст старейшей job в queued/processing. Обычная обработка — 1–3 s,
# retry с backoff — до ~30 s, поэтому порог 60 s, держится 30s.
expr: messenger:queue_oldest_age_seconds:max > 60
for: 30s
labels:
severity: page
annotations:
summary: "Очередь {{ $labels.queue }}: старейшая задача ждёт {{ $value | humanizeDuration }}"
description: "Worker не забирает задачи (остановлен/завис/нет БД). Backlog ≠ latency: смотрите и depth, и age."
runbook: "infra/prometheus/RUNBOOK.md#attachmentqueuelaggrowing"
- alert: AttachmentJobsFailing
expr: sum(increase(messenger_jobs_processed_total{outcome="failed"}[10m])) > 0
labels:
severity: ticket
annotations:
summary: "За 10m {{ $value }} задач ушли в failed/DLQ"
runbook: "infra/prometheus/RUNBOOK.md#attachmentjobsfailing"
- alert: TimeToReadySloBreach
expr: messenger:time_to_ready_seconds:p95_15m > 30
for: 5m
labels:
severity: ticket
annotations:
summary: "p95 upload → ready = {{ $value | humanizeDuration }} (SLO < 30s)"
runbook: "infra/prometheus/RUNBOOK.md#attachmentqueuelaggrowing"
- alert: TelemetryExportFailing
# Collector не может отдать данные в Tempo/Loki/Prometheus: данные теряются,
# но приложение продолжает работать (очереди ограничены).
expr: sum by (exporter) (rate({__name__=~"otelcol_exporter_send_failed_.+"}[2m])) > 0
for: 1m
labels:
severity: ticket
annotations:
summary: "Collector: exporter {{ $labels.exporter }} теряет {{ $value | humanize }} записей/с"
runbook: "infra/prometheus/RUNBOOK.md#telemetryexportfailing"
- alert: OtelCollectorDown
expr: up{job="otel-collector"} == 0
for: 1m
labels:
severity: ticket
annotations:
summary: "OTel Collector не отвечает на scrape :8888"
runbook: "infra/prometheus/RUNBOOK.md#telemetryexportfailing"