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

91 lines
4.4 KiB
YAML

# Alert rules (evaluated by Prometheus every 15 s; state pending -> firing -> resolved is visible
# in Prometheus /api/v1/alerts, the ALERTS series and the Grafana dashboard "Alerts" panel).
# No delivery outside (no Alertmanager): the task asks for the local firing/resolved state only.
# Runbook of every alert: docs/RUNBOOK.md#<alert name>.
groups:
- name: messenger-alerts
rules:
- alert: MessengerApiHighErrorRate
# 5xx share of business requests over 1 min, summed over all API replicas. The traffic
# guard (> 0.2 req/s) keeps a single failed request on an idle stand from paging.
expr: messenger:http_error_ratio:rate1m > 0.05 and messenger:http_requests:rate1m > 0.2
for: 1m
labels:
severity: page
slo: api-availability
annotations:
summary: "API: {{ $value | humanizePercentage }} of business requests answer 5xx"
description: >-
More than 5 % of non-health API requests failed with 5xx for over a minute (SLO: 99 %
non-5xx over 1 h). Typical causes: PostgreSQL/Valkey/S3 unavailable or too slow (503),
pool exhausted, crash (500).
runbook: docs/RUNBOOK.md#messengerapihigherrorrate
- alert: MessengerQueueLagGrowing
# Oldest unfinished job older than 60 s while jobs are waiting: nobody processes the queue
# (worker stopped/stuck, broker unreachable) or processing is far slower than arrivals.
# Measured in PostgreSQL by the relay: retries and unpublished jobs count too.
expr: max(messenger_queue_oldest_age_seconds) > 60 and max(messenger_queue_depth{state="queued"}) > 0
for: 1m
labels:
severity: page
slo: time-to-ready
annotations:
summary: "Queue: the oldest job waits {{ $value | humanizeDuration }}"
description: >-
Accepted uploads are not becoming ready. Check messenger_worker_busy / capacity, the
worker container, messenger_outbox_oldest_age_seconds (broker) and job outcomes.
runbook: docs/RUNBOOK.md#messengerqueuelaggrowing
- alert: MessengerApiLatencyHigh
# p99 of business requests over 2 min, from the buckets of all replicas.
expr: messenger:http_latency:p99_2m > 1
for: 2m
labels:
severity: ticket
slo: api-latency
annotations:
summary: "API p99 = {{ $value | humanizeDuration }} (> 1 s)"
description: >-
Slow API. Compare db.client.operation.duration and the DB pool (pending requests) with
the HTTP duration: slow database vs slow handler code (docs/RUNBOOK.md).
runbook: docs/RUNBOOK.md#messengerapilatencyhigh
- alert: MessengerDbPoolSaturated
# Requests waiting for a database connection in any process, for 1 min.
expr: max by (job) (db_client_connection_pending_requests) > 0
for: 1m
labels:
severity: ticket
annotations:
summary: "{{ $labels.job }}: requests wait for a PostgreSQL connection"
description: The pool is exhausted - queries hold connections too long (slow DB, locks) or the pool is too small.
runbook: docs/RUNBOOK.md#messengerdbpoolsaturated
- alert: MessengerQueueMetricsAbsent
# The relay reports the backlog from PostgreSQL every 5 s; no value for 2 min means the
# relay is down or cannot read the database - the queue is then NOT observed at all.
expr: absent(messenger_queue_oldest_age_seconds)
for: 2m
labels:
severity: ticket
annotations:
summary: "No queue metrics (relay down or database unreachable)"
runbook: docs/RUNBOOK.md#messengerqueuemetricsabsent
- alert: TelemetryExportFailing
# The Collector cannot deliver to a backend (Tempo/Loki/Prometheus down): data is buffered
# in its bounded queue and then dropped. The application itself is not affected.
expr: |
sum by (exporter) (
rate(otelcol_exporter_send_failed_spans_total[2m])
or rate(otelcol_exporter_send_failed_log_records_total[2m])
or rate(otelcol_exporter_send_failed_metric_points_total[2m])
) > 0
for: 30s
labels:
severity: ticket
annotations:
summary: "Collector exporter {{ $labels.exporter }} fails to send"
runbook: docs/RUNBOOK.md#telemetryexportfailing