# SLI, SLO и alert rules стенда vladimirceva-lab6 (уровень 4). # # Цели SLO считаются за 7 суток; ровно столько Prometheus держит данные. # API: ≥ 99,5 % бизнес-запросов без 5xx. Числитель — ответы 5xx # реплик API, знаменатель — все их ответы; health в метрику не # попадает вовсе, 4xx (неверный пароль, 404) — не отказ сервиса. # загрузка: ≥ 95 % вложений становятся ready не позже 30 с после 202 # (histogram messenger_attachment_time_to_ready_seconds, # корзина le="30.0"). # Оповещения быстрые, на явную поломку, а не burn rate: окно 2–5 мин и # `for` 1 мин. Alertmanager не подключён: состояние pending → firing → # (нет в списке) resolved видно в Prometheus /api/v1/alerts и в Grafana. # Тесты правил: make alerts-test (promtool, infra/otel/prometheus/rules.test.yml). groups: - name: messenger-sli interval: 15s rules: - record: messenger:http_requests:rate2m expr: sum(rate(http_server_request_duration_seconds_count{job="messenger-api"}[2m])) - record: messenger:http_errors:ratio_rate2m expr: | (sum(rate(http_server_request_duration_seconds_count{job="messenger-api", http_response_status_class="5xx"}[2m])) or vector(0)) / sum(rate(http_server_request_duration_seconds_count{job="messenger-api"}[2m])) # SLI доступности за окно SLO; 1 − значение = израсходованная доля - record: messenger:http_availability:ratio_7d expr: | 1 - ( (sum(increase(http_server_request_duration_seconds_count{job="messenger-api", http_response_status_class="5xx"}[7d])) or vector(0)) / sum(increase(http_server_request_duration_seconds_count{job="messenger-api"}[7d])) ) # SLI времени до ready: доля готовых за 30 с (экспортёр Collector пишет # границы с дробной частью: le="30.0") - record: messenger:attachment_ready_30s:ratio_7d expr: | sum(increase(messenger_attachment_time_to_ready_seconds_bucket{le="30.0"}[7d])) / sum(increase(messenger_attachment_time_to_ready_seconds_count[7d])) - name: messenger-alerts interval: 15s rules: - alert: MessengerHighErrorRate # 5 % = 10 × бюджет SLO; нижний порог трафика (≈ 6 запросов за 2 мин), # чтобы одиночный 503 в тишине не будил expr: | messenger:http_errors:ratio_rate2m > 0.05 and messenger:http_requests:rate2m > 0.05 for: 1m labels: severity: page annotations: summary: API answers 5xx to more than 5% of business requests description: >- Ratio of 5xx to all API responses (health excluded) over 2m stayed above 0.05 for 1m. Check PostgreSQL first: database unavailable lines and the postgresql spans of failing requests. runbook_url: infra/otel/runbooks/high-error-rate.md - alert: MessengerQueueLagGrowing # возраст старейшего незавершённого задания (outbox, брокер, аренда) # из PostgreSQL; без worker растёт на 1 с в секунду expr: max by (messaging_destination_name) (messenger_job_queue_oldest_age_seconds) > 60 for: 1m labels: severity: page annotations: summary: Oldest unfinished attachment job is older than 60s description: >- Oldest queued or processing job has waited more than 60s for 1m: jobs are accepted (202) but not finished. Usual causes: worker stopped, broker unavailable, relay stuck, retries with backoff. runbook_url: infra/otel/runbooks/queue-lag.md - alert: MessengerTelemetryTargetDown # без Collector пропадают метрики приложения, и два правила выше # молча перестают срабатывать expr: up{job=~"messenger|otel-collector"} == 0 for: 1m labels: severity: ticket annotations: summary: Prometheus cannot scrape the telemetry Collector description: >- Scrape target of the Collector (application metrics or its own metrics) is down for 1m; application alerts are blind meanwhile. runbook_url: infra/otel/runbooks/telemetry-down.md