ЛР6: наблюдаемость, SLO и диагностика отказов

This commit is contained in:
2026-11-16 21:07:01 +03:00
parent 470d9d6f1e
commit 8a96df4a74
217 changed files with 15534 additions and 34 deletions
+45
View File
@@ -0,0 +1,45 @@
groups:
- name: messenger
rules:
- alert: ApiHighErrorRate
expr: >-
sum(rate(lab_http_requests_total{status_class="5xx"}[30s])) / sum(rate(lab_http_requests_total[30s])) > 0.1
for: 6s
annotations:
summary: "HTTP 5xx exceeds 10% in 30s"
runbook: "infra/otel/runbook.md#api"
- alert: AttachmentQueueLag
expr: >-
max(lab_queue_oldest_seconds{queue="attachments"}) > 8 and max(lab_queue_depth{queue="attachments"}) > 0
for: 9s
annotations:
summary: "Oldest unfinished attachment exceeds eight seconds"
runbook: "infra/otel/runbook.md#queue"
- alert: ApiBurnFast
expr: >-
(sum(rate(lab_http_requests_total{status_class="5xx"}[1m])) / sum(rate(lab_http_requests_total[1m])) > 0.05) and (sum(rate(lab_http_requests_total{status_class="5xx"}[15s])) / sum(rate(lab_http_requests_total[15s])) > 0.05) and (sum(increase(lab_http_requests_total[1m])) >= 6)
for: 9s
annotations:
summary: "Api burn > 5x in 1m and 15s"
runbook: "infra/otel/runbook.md#api"
- alert: ApiBurnSlow
expr: >-
(sum(rate(lab_http_requests_total{status_class="5xx"}[3m])) / sum(rate(lab_http_requests_total[3m])) > 0.02) and (sum(rate(lab_http_requests_total{status_class="5xx"}[45s])) / sum(rate(lab_http_requests_total[45s])) > 0.02) and (sum(increase(lab_http_requests_total[3m])) >= 12)
for: 18s
annotations:
summary: "Api burn > 2x in 3m and 45s"
runbook: "infra/otel/runbook.md#api"
- alert: ReadyBurnFast
expr: >-
(sum(rate(lab_ready_sli_total{outcome="bad"}[1m])) / sum(rate(lab_ready_sli_total[1m])) > 0.25) and (sum(rate(lab_ready_sli_total{outcome="bad"}[15s])) / sum(rate(lab_ready_sli_total[15s])) > 0.25) and (sum(increase(lab_ready_sli_total[1m])) >= 6)
for: 9s
annotations:
summary: "Ready burn > 5x in 1m and 15s"
runbook: "infra/otel/runbook.md#queue"
- alert: ReadyBurnSlow
expr: >-
(sum(rate(lab_ready_sli_total{outcome="bad"}[3m])) / sum(rate(lab_ready_sli_total[3m])) > 0.1) and (sum(rate(lab_ready_sli_total{outcome="bad"}[45s])) / sum(rate(lab_ready_sli_total[45s])) > 0.1) and (sum(increase(lab_ready_sli_total[3m])) >= 12)
for: 18s
annotations:
summary: "Ready burn > 2x in 3m and 45s"
runbook: "infra/otel/runbook.md#queue"
+62
View File
@@ -0,0 +1,62 @@
receivers:
otlp:
protocols:
http:
endpoint: 0.0.0.0:4318
processors:
memory_limiter:
check_interval: 1s
limit_mib: 128
spike_limit_mib: 32
batch:
timeout: 1s
send_batch_size: 128
send_batch_max_size: 256
exporters:
prometheus:
endpoint: 0.0.0.0:8889
metric_expiration: 20s
otlp/tempo:
endpoint: tempo:4317
tls:
insecure: true
timeout: 2s
sending_queue:
queue_size: 32
num_consumers: 1
retry_on_failure:
initial_interval: 1s
max_interval: 3s
max_elapsed_time: 10s
otlphttp/loki:
endpoint: http://loki:3100/otlp
timeout: 2s
sending_queue:
queue_size: 32
num_consumers: 1
retry_on_failure:
initial_interval: 1s
max_interval: 3s
max_elapsed_time: 10s
service:
telemetry:
metrics:
readers:
- pull:
exporter:
prometheus:
host: 0.0.0.0
port: 8888
pipelines:
metrics:
receivers: [otlp]
processors: [memory_limiter, batch]
exporters: [prometheus]
logs:
receivers: [otlp]
processors: [memory_limiter, batch]
exporters: [otlphttp/loki]
traces:
receivers: [otlp]
processors: [memory_limiter, batch]
exporters: [otlp/tempo]
@@ -0,0 +1,501 @@
{
"uid": "messenger-lab6",
"title": "Messenger Lab 6",
"schemaVersion": 39,
"version": 1,
"refresh": "5s",
"time": {
"from": "now-15m",
"to": "now"
},
"panels": [
{
"id": 1,
"title": "API requests / second",
"type": "timeseries",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 0,
"y": 0,
"w": 12,
"h": 8
},
"fieldConfig": {
"defaults": {
"unit": "reqps"
},
"overrides": []
},
"targets": [
{
"refId": "A",
"expr": "sum by (status_class) (rate(lab_http_requests_total[1m]))",
"legendFormat": "{{status_class}}"
}
]
},
{
"id": 2,
"title": "API 5xx share",
"type": "timeseries",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 12,
"y": 0,
"w": 12,
"h": 8
},
"fieldConfig": {
"defaults": {
"unit": "percentunit"
},
"overrides": []
},
"targets": [
{
"refId": "A",
"expr": "(sum(rate(lab_http_requests_total{status_class=\"5xx\"}[1m])) or vector(0)) / sum(rate(lab_http_requests_total[1m]))",
"legendFormat": "5xx"
}
]
},
{
"id": 3,
"title": "HTTP latency across replicas",
"type": "timeseries",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 0,
"y": 8,
"w": 12,
"h": 8
},
"fieldConfig": {
"defaults": {
"unit": "s"
},
"overrides": []
},
"targets": [
{
"refId": "A",
"expr": "histogram_quantile(0.5, sum by (le) (rate(lab_http_duration_seconds_bucket[1m])))",
"legendFormat": "p50"
},
{
"refId": "B",
"expr": "histogram_quantile(0.95, sum by (le) (rate(lab_http_duration_seconds_bucket[1m])))",
"legendFormat": "p95"
},
{
"refId": "C",
"expr": "histogram_quantile(0.99, sum by (le) (rate(lab_http_duration_seconds_bucket[1m])))",
"legendFormat": "p99"
}
]
},
{
"id": 4,
"title": "Worker delivery outcomes / second",
"type": "timeseries",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 12,
"y": 8,
"w": 12,
"h": 8
},
"fieldConfig": {
"defaults": {
"unit": "ops"
},
"overrides": []
},
"targets": [
{
"refId": "A",
"expr": "sum by (outcome) (rate(lab_jobs_total[1m]))",
"legendFormat": "{{outcome}}"
}
]
},
{
"id": 5,
"title": "Worker delivery latency",
"type": "timeseries",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 0,
"y": 16,
"w": 12,
"h": 8
},
"fieldConfig": {
"defaults": {
"unit": "s"
},
"overrides": []
},
"targets": [
{
"refId": "A",
"expr": "histogram_quantile(0.5, sum by (le) (rate(lab_job_duration_seconds_bucket[1m])))",
"legendFormat": "p50"
},
{
"refId": "B",
"expr": "histogram_quantile(0.95, sum by (le) (rate(lab_job_duration_seconds_bucket[1m])))",
"legendFormat": "p95"
},
{
"refId": "C",
"expr": "histogram_quantile(0.99, sum by (le) (rate(lab_job_duration_seconds_bucket[1m])))",
"legendFormat": "p99"
}
]
},
{
"id": 6,
"title": "Acceptance to READY",
"type": "timeseries",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 12,
"y": 16,
"w": 12,
"h": 8
},
"fieldConfig": {
"defaults": {
"unit": "s"
},
"overrides": []
},
"targets": [
{
"refId": "A",
"expr": "histogram_quantile(0.5, sum by (le) (rate(lab_ready_duration_seconds_bucket[3m])))",
"legendFormat": "p50"
},
{
"refId": "B",
"expr": "histogram_quantile(0.95, sum by (le) (rate(lab_ready_duration_seconds_bucket[3m])))",
"legendFormat": "p95"
},
{
"refId": "C",
"expr": "histogram_quantile(0.99, sum by (le) (rate(lab_ready_duration_seconds_bucket[3m])))",
"legendFormat": "p99"
}
]
},
{
"id": 7,
"title": "Unfinished jobs",
"type": "timeseries",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 0,
"y": 24,
"w": 12,
"h": 8
},
"fieldConfig": {
"defaults": {
"unit": "short"
},
"overrides": []
},
"targets": [
{
"refId": "A",
"expr": "max(lab_queue_depth)",
"legendFormat": "depth"
}
]
},
{
"id": 8,
"title": "Oldest unfinished job",
"type": "timeseries",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 12,
"y": 24,
"w": 12,
"h": 8
},
"fieldConfig": {
"defaults": {
"unit": "s"
},
"overrides": []
},
"targets": [
{
"refId": "A",
"expr": "max(lab_queue_oldest_seconds)",
"legendFormat": "age"
}
]
},
{
"id": 9,
"title": "DB pool per API",
"type": "timeseries",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 0,
"y": 32,
"w": 12,
"h": 8
},
"fieldConfig": {
"defaults": {
"unit": "short"
},
"overrides": []
},
"targets": [
{
"refId": "A",
"expr": "lab_db_pool_connections",
"legendFormat": "{{instance}} {{state}}"
}
]
},
{
"id": 10,
"title": "Worker saturation",
"type": "timeseries",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 12,
"y": 32,
"w": 12,
"h": 8
},
"fieldConfig": {
"defaults": {
"unit": "percentunit"
},
"overrides": []
},
"targets": [
{
"refId": "A",
"expr": "sum(lab_worker_busy) / sum(lab_worker_capacity)",
"legendFormat": "busy/capacity"
}
]
},
{
"id": 11,
"title": "Process CPU",
"type": "timeseries",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 0,
"y": 40,
"w": 12,
"h": 8
},
"fieldConfig": {
"defaults": {
"unit": "short"
},
"overrides": []
},
"targets": [
{
"refId": "A",
"expr": "rate(lab_process_cpu_seconds_total[1m])",
"legendFormat": "{{job}} {{instance}}"
}
]
},
{
"id": 12,
"title": "Process RSS",
"type": "timeseries",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 12,
"y": 40,
"w": 12,
"h": 8
},
"fieldConfig": {
"defaults": {
"unit": "bytes"
},
"overrides": []
},
"targets": [
{
"refId": "A",
"expr": "lab_process_rss_bytes",
"legendFormat": "{{job}} {{instance}}"
}
]
},
{
"id": 13,
"title": "Burn rates",
"type": "timeseries",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 0,
"y": 48,
"w": 12,
"h": 8
},
"fieldConfig": {
"defaults": {
"unit": "short"
},
"overrides": []
},
"targets": [
{
"refId": "A",
"expr": "sum(rate(lab_http_requests_total{status_class=\"5xx\"}[1m])) / sum(rate(lab_http_requests_total[1m])) / 0.01",
"legendFormat": "API"
},
{
"refId": "B",
"expr": "sum(rate(lab_ready_sli_total{outcome=\"bad\"}[1m])) / sum(rate(lab_ready_sli_total[1m])) / 0.05",
"legendFormat": "READY"
}
]
},
{
"id": 14,
"title": "Active alerts",
"type": "timeseries",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 12,
"y": 48,
"w": 12,
"h": 8
},
"fieldConfig": {
"defaults": {
"unit": "short"
},
"overrides": []
},
"targets": [
{
"refId": "A",
"expr": "ALERTS{alertstate=~\"pending|firing\"}",
"legendFormat": "{{alertname}} {{alertstate}}"
}
]
},
{
"id": 15,
"title": "Correlated API and worker logs",
"type": "logs",
"datasource": {
"type": "loki",
"uid": "loki"
},
"gridPos": {
"x": 0,
"y": 56,
"w": 12,
"h": 8
},
"fieldConfig": {
"defaults": {
"unit": "short"
},
"overrides": []
},
"targets": [
{
"refId": "A",
"expr": "{service_name=~\"messenger-(api|worker|dispatcher)\"}",
"legendFormat": ""
}
]
},
{
"id": 16,
"title": "SLO attainment over 30 minutes",
"type": "timeseries",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 12,
"y": 56,
"w": 12,
"h": 8
},
"fieldConfig": {
"defaults": {
"unit": "percentunit"
},
"overrides": []
},
"targets": [
{
"refId": "A",
"legendFormat": "API success (target 99%)",
"expr": "1 - (sum(increase(lab_http_requests_total{status_class=\"5xx\"}[30m])) or vector(0)) / sum(increase(lab_http_requests_total[30m]))"
},
{
"refId": "B",
"legendFormat": "READY within 5s (target 95%)",
"expr": "sum(increase(lab_ready_sli_total{outcome=\"good\"}[30m])) / sum(increase(lab_ready_sli_total[30m]))"
}
]
}
]
}
@@ -0,0 +1,6 @@
apiVersion: 1
providers:
- name: messenger
type: file
options:
path: /var/lib/grafana/dashboards
@@ -0,0 +1,22 @@
apiVersion: 1
datasources:
- name: Prometheus
type: prometheus
uid: prometheus
url: http://prometheus:9090
isDefault: true
- name: Loki
type: loki
uid: loki
url: http://loki:3100
jsonData:
derivedFields:
- name: TraceID
matcherType: label
matcherRegex: trace_id
datasourceUid: tempo
url: '$${__value.raw}'
- name: Tempo
type: tempo
uid: tempo
url: http://tempo:3200
+29
View File
@@ -0,0 +1,29 @@
auth_enabled: false
server:
http_listen_port: 3100
common:
instance_addr: 127.0.0.1
path_prefix: /loki
storage:
filesystem:
chunks_directory: /loki/chunks
rules_directory: /loki/rules
replication_factor: 1
ring:
kvstore:
store: inmemory
schema_config:
configs:
- from: 2024-01-01
store: tsdb
object_store: filesystem
schema: v13
index:
prefix: index_
period: 24h
limits_config:
allow_structured_metadata: true
retention_period: 24h
compactor:
retention_enabled: true
delete_request_store: filesystem
+13
View File
@@ -0,0 +1,13 @@
global:
scrape_interval: 3s
evaluation_interval: 3s
rule_files:
- /etc/prometheus/alerts.yaml
scrape_configs:
- job_name: otlp
honor_labels: true
static_configs:
- targets: [otel-collector:8889]
- job_name: collector
static_configs:
- targets: [otel-collector:8888]
+22
View File
@@ -0,0 +1,22 @@
# Диагностика учебного стенда
Откройте dashboard Messenger Lab 6 по адресу http://127.0.0.1:13006/d/messenger-lab6. Для определения времени инцидента используйте состояние правил Prometheus и отметки проб в evidence. Для локального запуска тестов используйте команды из REPORT.md.
## API
1. По панели API 5xx share найдите интервал деградации. Сопоставьте его с API latency и DB pool used/waiting. Проверьте наличие трафика перед интерпретацией доли ошибок.
2. В Explore выберите Loki. Запрос `{service_name="messenger-api"} | status_class="5xx"` покажет события завершения запросов. Найдите тот же `request_id`, что в HTTP-заголовке. Временно сузьте диапазон времени, чтобы исключить ошибки предыдущего опыта.
3. Скопируйте `trace_id` в Tempo или откройте ссылку TraceID. Длинный дочерний span `postgres.session.lookup` с ошибкой показывает, что запрос ждал PostgreSQL в ходе проверки сессии. Если задержка приходится на другое дочернее действие, смотрите его имя и статус.
4. Снимите операторскую блокировку и проверьте, что 200 восстановились, доля 5xx снизилась и правила перешли в inactive. При необходимости проверьте состояние DB-контейнера и ожидания в `pg_stat_activity`.
## Queue
1. При росте `Oldest unfinished job` сравните backlog с активностью worker. Большой backlog при исчезновении рядов capacity означает отсутствие свежей телеметрии воркеров. Подтвердите состояние контейнеров через `docker compose ps`. Активные воркеры при высоком busy/capacity указывают на насыщение.
2. По X-Request-Id принятого upload найдите `http.completed` в Loki. В Tempo проверьте producer `attachments publish` и consumer `attachments consume`. По `job.attempt` видно повторную обработку. Ошибки S3 и БД различаются по дочерним spans.
3. Восстановите работу воркеров. Проверьте исчезновение backlog, переход AttachmentQueueLag в inactive и завершение ранее принятых вложений. Ready burn может сработать после обработки накопившихся медленных вложений и завершится после выхода этих наблюдений из короткого окна.
## Telemetry
1. При отсутствии логов проверьте состояние Loki и запросы через datasource. Сопоставьте с Prometheus `up` для Collector и с `otelcol_exporter_send_failed_log_records_total`.
2. По `otelcol_exporter_queue_size` и `otelcol_exporter_queue_capacity` проверьте предел очереди. Рост ошибок экспорта после истечения retry window означает потерю наблюдений.
3. Проверьте HTTP-запись и чтение сообщений, затем восстановите Loki и найдите свежий `http.completed` в Grafana. SDK и Collector держат ограниченные очереди в памяти.
+20
View File
@@ -0,0 +1,20 @@
server:
http_listen_port: 3200
distributor:
receivers:
otlp:
protocols:
grpc:
endpoint: 0.0.0.0:4317
ingester:
max_block_duration: 5m
compactor:
compaction:
block_retention: 24h
storage:
trace:
backend: local
local:
path: /var/tempo/blocks
wal:
path: /var/tempo/wal