forked from mtusi2026/mtusi2026lab7
Перенос решения ЛР 6 без изменений (src, migrations, student-tests, bench, infra, scripts, compose, Dockerfile, docs)
This commit is contained in:
@@ -0,0 +1,90 @@
|
||||
# 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[2m])
|
||||
or rate(otelcol_exporter_send_failed_log_records[2m])
|
||||
or rate(otelcol_exporter_send_failed_metric_points[2m])
|
||||
) > 0
|
||||
for: 30s
|
||||
labels:
|
||||
severity: ticket
|
||||
annotations:
|
||||
summary: "Collector exporter {{ $labels.exporter }} fails to send"
|
||||
runbook: docs/RUNBOOK.md#telemetryexportfailing
|
||||
@@ -0,0 +1,38 @@
|
||||
# Recording rules: SLIs of docs/SLO.md (lab windows). All ratios are computed from COUNTERS and
|
||||
# histogram BUCKETS summed over every replica first, then divided - never an average of
|
||||
# per-replica ratios or percentiles.
|
||||
#
|
||||
# Business requests = every API request except /health/* (load-balancer/Docker probes).
|
||||
# "Bad" for availability = HTTP 5xx only: 4xx (wrong password, 404 of an outsider, 409) is a
|
||||
# correct answer to a wrong request, not a failure of the service.
|
||||
groups:
|
||||
- name: messenger-sli
|
||||
interval: 15s
|
||||
rules:
|
||||
- record: messenger:http_requests:rate1m
|
||||
expr: sum(rate(http_server_request_duration_seconds_count{job="messenger-api", http_route!~"/health/.*"}[1m]))
|
||||
- record: messenger:http_errors5xx:rate1m
|
||||
expr: sum(rate(http_server_request_duration_seconds_count{job="messenger-api", http_route!~"/health/.*", http_response_status_class="5xx"}[1m])) or vector(0)
|
||||
- record: messenger:http_error_ratio:rate1m
|
||||
expr: messenger:http_errors5xx:rate1m / messenger:http_requests:rate1m
|
||||
- record: messenger:http_error_ratio:rate5m
|
||||
expr: |
|
||||
(sum(rate(http_server_request_duration_seconds_count{job="messenger-api", http_route!~"/health/.*", http_response_status_class="5xx"}[5m])) or vector(0))
|
||||
/ sum(rate(http_server_request_duration_seconds_count{job="messenger-api", http_route!~"/health/.*"}[5m]))
|
||||
- record: messenger:http_error_ratio:rate1h
|
||||
expr: |
|
||||
(sum(rate(http_server_request_duration_seconds_count{job="messenger-api", http_route!~"/health/.*", http_response_status_class="5xx"}[1h])) or vector(0))
|
||||
/ sum(rate(http_server_request_duration_seconds_count{job="messenger-api", http_route!~"/health/.*"}[1h]))
|
||||
# Latency SLI: share of business requests answered within 250 ms (bucket le="0.25").
|
||||
- record: messenger:http_fast_ratio:rate5m
|
||||
expr: |
|
||||
sum(rate(http_server_request_duration_seconds_bucket{job="messenger-api", http_route!~"/health/.*", le="0.25"}[5m]))
|
||||
/ sum(rate(http_server_request_duration_seconds_count{job="messenger-api", http_route!~"/health/.*"}[5m]))
|
||||
# p50/p95/p99 over ALL replicas: buckets summed by le, then histogram_quantile.
|
||||
- record: messenger:http_latency:p99_2m
|
||||
expr: histogram_quantile(0.99, sum by (le) (rate(http_server_request_duration_seconds_bucket{job="messenger-api", http_route!~"/health/.*"}[2m])))
|
||||
# Time-to-ready SLI: share of uploads ready within 30 s (bucket le="30").
|
||||
- record: messenger:ready_within_30s_ratio:rate1h
|
||||
expr: |
|
||||
sum(rate(messenger_attachment_time_to_ready_seconds_bucket{le="30"}[1h]))
|
||||
/ sum(rate(messenger_attachment_time_to_ready_seconds_count[1h]))
|
||||
Reference in New Issue
Block a user