feat: implement lab 6 observability and telemetry cost research
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
# Prometheus v3.15.1: хранилище метрик стенда. Метрики приложения сюда
|
||||
# не пушатся — Prometheus сам забирает экспортёр Collector (:8889), куда
|
||||
# SDK api, worker и relay отправляют OTLP. Срок (7d) и объём (1GB) хранения
|
||||
# — флаги в compose.yaml; volume promdata.
|
||||
|
||||
global:
|
||||
scrape_interval: 15s
|
||||
scrape_timeout: 10s
|
||||
evaluation_interval: 15s
|
||||
|
||||
# SLI и alert rules (уровень 4). Оповещения наружу не уходят: Alertmanager
|
||||
# не подключён, состояние pending/firing видно в /api/v1/alerts и в Grafana
|
||||
rule_files:
|
||||
- /etc/prometheus/rules.yml
|
||||
|
||||
scrape_configs:
|
||||
# метрики приложения: job и instance уже проставил Collector из ресурса
|
||||
# (service.name, service.instance.id) — honor_labels их сохраняет
|
||||
- job_name: messenger
|
||||
honor_labels: true
|
||||
static_configs:
|
||||
- targets: ["otel-collector:8889"]
|
||||
|
||||
# здоровье самого конвейера телеметрии: очередь экспорта, отказы, память
|
||||
- job_name: otel-collector
|
||||
static_configs:
|
||||
- targets: ["otel-collector:8888"]
|
||||
- job_name: loki
|
||||
static_configs:
|
||||
- targets: ["loki:3100"]
|
||||
- job_name: tempo
|
||||
static_configs:
|
||||
- targets: ["tempo:3200"]
|
||||
- job_name: prometheus
|
||||
static_configs:
|
||||
- targets: ["127.0.0.1:9090"]
|
||||
@@ -0,0 +1,104 @@
|
||||
# promtool test rules (make alerts-test): каждое правило — сработало при
|
||||
# поломке, не сработало до неё и ушло после восстановления.
|
||||
|
||||
rule_files:
|
||||
- rules.yml
|
||||
|
||||
evaluation_interval: 15s
|
||||
|
||||
tests:
|
||||
# 5xx начинаются на 150-й секунде: треть ответов
|
||||
- interval: 15s
|
||||
input_series:
|
||||
- series: 'http_server_request_duration_seconds_count{job="messenger-api", http_route="/api/v1/users/me", http_response_status_class="2xx"}'
|
||||
values: '0+10x60'
|
||||
- series: 'http_server_request_duration_seconds_count{job="messenger-api", http_route="/api/v1/users/me", http_response_status_class="5xx"}'
|
||||
values: '0+0x10 5+5x20 105+0x29'
|
||||
alert_rule_test:
|
||||
- eval_time: 2m
|
||||
alertname: MessengerHighErrorRate
|
||||
exp_alerts: []
|
||||
- eval_time: 6m
|
||||
alertname: MessengerHighErrorRate
|
||||
exp_alerts:
|
||||
- exp_labels:
|
||||
severity: page
|
||||
exp_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
|
||||
# ошибки кончились на 450-й секунде, окно 2 мин прошло
|
||||
- eval_time: 10m
|
||||
alertname: MessengerHighErrorRate
|
||||
exp_alerts: []
|
||||
promql_expr_test:
|
||||
- expr: messenger:http_errors:ratio_rate2m
|
||||
eval_time: 6m
|
||||
exp_samples:
|
||||
- labels: 'messenger:http_errors:ratio_rate2m'
|
||||
value: 0.3333333333333333
|
||||
|
||||
# одиночная ошибка при почти нулевом трафике не будит
|
||||
- interval: 15s
|
||||
input_series:
|
||||
- series: 'http_server_request_duration_seconds_count{job="messenger-api", http_route="/api/v1/users/me", http_response_status_class="5xx"}'
|
||||
values: '0+0x10 1+0x30'
|
||||
alert_rule_test:
|
||||
- eval_time: 5m
|
||||
alertname: MessengerHighErrorRate
|
||||
exp_alerts: []
|
||||
|
||||
# worker остановлен на 5 мин: возраст растёт, затем backlog разобран
|
||||
- interval: 15s
|
||||
input_series:
|
||||
- series: 'messenger_job_queue_oldest_age_seconds{job="messenger-relay", instance="relay-1", messaging_destination_name="messenger.attachment-jobs"}'
|
||||
values: '0+15x20 0x20'
|
||||
alert_rule_test:
|
||||
- eval_time: 1m
|
||||
alertname: MessengerQueueLagGrowing
|
||||
exp_alerts: []
|
||||
- eval_time: 4m
|
||||
alertname: MessengerQueueLagGrowing
|
||||
exp_alerts:
|
||||
- exp_labels:
|
||||
severity: page
|
||||
messaging_destination_name: messenger.attachment-jobs
|
||||
exp_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
|
||||
- eval_time: 7m
|
||||
alertname: MessengerQueueLagGrowing
|
||||
exp_alerts: []
|
||||
|
||||
# Collector не отвечает на scrape
|
||||
- interval: 15s
|
||||
input_series:
|
||||
- series: 'up{job="otel-collector", instance="otel-collector:8888"}'
|
||||
values: '1x5 0x10 1x10'
|
||||
alert_rule_test:
|
||||
- eval_time: 1m
|
||||
alertname: MessengerTelemetryTargetDown
|
||||
exp_alerts: []
|
||||
- eval_time: 3m
|
||||
alertname: MessengerTelemetryTargetDown
|
||||
exp_alerts:
|
||||
- exp_labels:
|
||||
severity: ticket
|
||||
job: otel-collector
|
||||
instance: otel-collector:8888
|
||||
exp_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
|
||||
- eval_time: 6m
|
||||
alertname: MessengerTelemetryTargetDown
|
||||
exp_alerts: []
|
||||
@@ -0,0 +1,86 @@
|
||||
# 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
|
||||
Reference in New Issue
Block a user