Files
mtusi2026lab6/grafana/provisioning/alerting/alerts.yaml
T

101 lines
4.7 KiB
YAML
Raw 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.
# LAB 6 (уровень 4): alert rules с окном, порогом, for, описанием и runbook.
# Delivery наружу не требуется — достаточно локального состояния firing/resolved.
apiVersion: 1
groups:
- orgId: 1
name: messenger
folder: Messenger
interval: 30s
rules:
- uid: messenger-high-error-rate
title: "Messenger: API 5xx error rate > 1%"
condition: C
for: 2m
noDataState: NoData # реальные проблемы источника видны; idle-окно больше не даёт NoData
execErrState: Alerting
labels:
severity: warning
component: api
annotations:
summary: "Доля 5xx ответов API превысила 1% в окне 2 минуты."
description: |
SLI: 5xx / все HTTP-запросы. Окно 2m, порог 0.01.
Выражение всегда возвращает число: при отсутствии 5xx или трафика — 0.
runbook: |
1. Dashboard 'messenger-overview', панель 'HTTP 5xx error ratio'.
2. 'HTTP latency p50/p95/p99': резкий рост p99 указывает на зависимый сервис.
3. Tempo: service.name=messenger-api, status.code=ERROR; в дочерних spans
ищите db/s3 операции с ошибками.
4. Loki: {service_name="messenger-api"} |= "error", переход по trace_id.
5. Отличите отказы: недоступная БД — /health/ready=503 и db-spans ERROR;
медленный handler — /health/ready=200, высокий p99 без ERROR.
data:
- refId: A
relativeTimeRange: { from: 120, to: 0 }
datasourceUid: prometheus
model:
refId: A
instant: true
# FIX (ревью): пустой числитель больше не даёт пустое выражение.
expr: '(sum(rate(http_server_request_duration_seconds_count{service_name="messenger-api",http_response_status_code=~"5.."}[2m])) / sum(rate(http_server_request_duration_seconds_count{service_name="messenger-api"}[2m]))) or vector(0)'
- refId: B
datasourceUid: __expr__
model:
refId: B
type: reduce
expression: A
reducer: last
- refId: C
datasourceUid: __expr__
model:
refId: C
type: threshold
expression: B
conditions:
- evaluator: { type: gt, params: [0.01] }
- uid: messenger-queue-lag
title: "Messenger: queue oldest job age > 30s"
condition: C
for: 2m
noDataState: NoData
execErrState: Alerting
labels:
severity: warning
component: worker
annotations:
summary: "Возраст старейшего задания в очереди превысил 30 секунд в окне 2 минуты."
description: |
SLI: возраст backlog'а. Broker — messenger_queue_oldest_age_seconds (lag+pending),
DB — messenger_jobs_oldest_queued_age_seconds (jobs.status='queued').
runbook: |
1. Dashboard: 'Queue oldest age' и 'Worker saturation'.
2. docker compose ps worker: Exited — поднять и смотреть логи;
Up — worker не справляется, смотреть Job duration p99.
3. 'Jobs processed rate by outcome': retry_scheduled/retry_exhausted
указывают на внешнюю проблему (S3, БД).
4. Tempo: service.name=messenger-worker, name=attachment.process.
5. После устранения очередь должна разгрестись, alert — resolved.
data:
- refId: A
relativeTimeRange: { from: 120, to: 0 }
datasourceUid: prometheus
model:
refId: A
instant: true
expr: 'max(messenger_queue_oldest_age_seconds{service_name="messenger-api"}) or vector(0)'
- refId: B
datasourceUid: __expr__
model:
refId: B
type: reduce
expression: A
reducer: last
- refId: C
datasourceUid: __expr__
model:
refId: C
type: threshold
expression: B
conditions:
- evaluator: { type: gt, params: [30] }