Лаба6 - оценка 4
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
# 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
|
||||
labels:
|
||||
severity: warning
|
||||
component: api
|
||||
annotations:
|
||||
summary: "Доля 5xx ответов API превысила 1% в окне 2 минуты."
|
||||
description: |
|
||||
SLI: 5xx / все HTTP-запросы. Окно 2m. Порог 0.01.
|
||||
runbook: |
|
||||
1. Откройте dashboard 'messenger-overview', панель 'HTTP 5xx error ratio'.
|
||||
2. Посмотрите 'HTTP latency p50/p95/p99': резкий рост p99 указывает
|
||||
на зависимый сервис (БД/S3).
|
||||
3. Найдите трассу с 5xx через Tempo: service.name=messenger-api,
|
||||
status.code=ERROR. В дочерних spans ищите db.client или
|
||||
s3.operation с ошибками.
|
||||
4. Проверьте логи Loki: {service_name="messenger-api"} |= "error".
|
||||
5. Отличите медленный DB handler от недоступной БД:
|
||||
- недоступная БД: много 'database unavailable', /health/ready = 503;
|
||||
- медленный handler: /health/ready = 200, но p99 > 5s и
|
||||
db.client.operation.duration растёт.
|
||||
data:
|
||||
- refId: A
|
||||
relativeTimeRange: { from: 120, to: 0 }
|
||||
datasourceUid: prometheus
|
||||
model:
|
||||
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]))"
|
||||
instant: true
|
||||
- refId: B
|
||||
datasourceUid: __expr__
|
||||
model: { type: "reduce", expression: "A", reducer: "last" }
|
||||
- refId: C
|
||||
datasourceUid: __expr__
|
||||
model: { 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
|
||||
labels:
|
||||
severity: warning
|
||||
component: worker
|
||||
annotations:
|
||||
summary: "Возраст старейшего задания в очереди превысил 30 секунд в окне 2 минуты."
|
||||
description: |
|
||||
SLI: messenger_queue_oldest_age_seconds. Рост указывает, что worker
|
||||
не справляется или недоступен. Проверьте также messenger_jobs_oldest_queued_age_seconds.
|
||||
runbook: |
|
||||
1. Dashboard 'messenger-overview', панели 'Queue oldest age' и
|
||||
'Worker saturation'.
|
||||
2. Проверьте worker через `docker compose ps worker`:
|
||||
- Up — worker жив, но не справляется (смотрим Job duration p99);
|
||||
- Exited — worker упал, перезапустите и проверьте логи:
|
||||
`docker compose logs worker --tail 100`.
|
||||
3. Если worker жив, а depth растёт — посмотрите 'Jobs processed rate
|
||||
by outcome': высокий retry_scheduled/retry_exhausted указывает
|
||||
на внешнюю проблему (S3, БД).
|
||||
4. Трассы worker'а в Tempo: service.name=messenger-worker,
|
||||
name=attachment.process. Дочерние spans redis/pgsql/s3 покажут,
|
||||
где задержка.
|
||||
5. После устранения причины — очередь должна уменьшиться,
|
||||
alert перейдёт в resolved автоматически.
|
||||
data:
|
||||
- refId: A
|
||||
relativeTimeRange: { from: 120, to: 0 }
|
||||
datasourceUid: prometheus
|
||||
model:
|
||||
expr: "max(messenger_queue_oldest_age_seconds{service_name=\"messenger-api\"})"
|
||||
instant: true
|
||||
- refId: B
|
||||
datasourceUid: __expr__
|
||||
model: { type: "reduce", expression: "A", reducer: "last" }
|
||||
- refId: C
|
||||
datasourceUid: __expr__
|
||||
model: { type: "threshold", expression: "B", conditions: [{ evaluator: { type: "gt", params: [30] } }] }
|
||||
@@ -0,0 +1,16 @@
|
||||
# LAB 6: dashboard импортируется из Git, а не набирается руками.
|
||||
# JSON-файлы кладём в подпапку json/ (добавим на части 2).
|
||||
|
||||
apiVersion: 1
|
||||
|
||||
providers:
|
||||
- name: messenger
|
||||
orgId: 1
|
||||
folder: Messenger
|
||||
type: file
|
||||
disableDeletion: false
|
||||
updateIntervalSeconds: 30
|
||||
allowUiUpdates: true
|
||||
options:
|
||||
path: /etc/grafana/provisioning/dashboards/json
|
||||
foldersFromFilesStructure: false
|
||||
@@ -0,0 +1,189 @@
|
||||
{
|
||||
"uid": "messenger-overview",
|
||||
"title": "Messenger — observability level 4",
|
||||
"description": "API, worker, queue, saturation. PromQL ссылается на реальные имена метрик, экспортированные SDK.",
|
||||
"tags": ["messenger", "lab6"],
|
||||
"timezone": "utc",
|
||||
"editable": true,
|
||||
"time": { "from": "now-30m", "to": "now" },
|
||||
"refresh": "10s",
|
||||
"panels": [
|
||||
{
|
||||
"type": "row",
|
||||
"title": "HTTP API",
|
||||
"gridPos": { "h": 1, "w": 24, "x": 0, "y": 0 },
|
||||
"collapsed": false
|
||||
},
|
||||
{
|
||||
"type": "timeseries",
|
||||
"title": "HTTP RPS (by method, all replicas)",
|
||||
"description": "Сумма rate по всем репликам. Метрика: http_server_request_duration_seconds_count.",
|
||||
"datasource": { "uid": "prometheus", "type": "prometheus" },
|
||||
"gridPos": { "h": 8, "w": 8, "x": 0, "y": 1 },
|
||||
"targets": [
|
||||
{
|
||||
"expr": "sum by (http_request_method) (rate(http_server_request_duration_seconds_count{service_name=\"messenger-api\"}[$__rate_interval]))",
|
||||
"legendFormat": "{{http_request_method}}"
|
||||
}
|
||||
],
|
||||
"fieldConfig": {
|
||||
"defaults": { "unit": "reqps", "custom": { "lineWidth": 2, "fillOpacity": 15 } }
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "timeseries",
|
||||
"title": "HTTP 5xx error ratio",
|
||||
"description": "SLI: 5xx / все запросы. Health GET не даёт 5xx при живой БД и не искажает знаменатель.",
|
||||
"datasource": { "uid": "prometheus", "type": "prometheus" },
|
||||
"gridPos": { "h": 8, "w": 8, "x": 8, "y": 1 },
|
||||
"targets": [
|
||||
{
|
||||
"expr": "sum(rate(http_server_request_duration_seconds_count{service_name=\"messenger-api\",http_response_status_code=~\"5..\"}[$__rate_interval])) / sum(rate(http_server_request_duration_seconds_count{service_name=\"messenger-api\"}[$__rate_interval]))",
|
||||
"legendFormat": "5xx ratio"
|
||||
}
|
||||
],
|
||||
"fieldConfig": {
|
||||
"defaults": { "unit": "percentunit", "max": 1, "custom": { "lineWidth": 2 } },
|
||||
"overrides": [
|
||||
{ "matcher": { "id": "byName", "options": "5xx ratio" },
|
||||
"properties": [{ "id": "color", "value": { "mode": "fixed", "fixedColor": "red" } }] }
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "timeseries",
|
||||
"title": "HTTP latency p50 / p95 / p99",
|
||||
"description": "Глобальные percentiles из суммы histogram buckets всех реплик. Среднее p99 реплик НЕ вычисляется.",
|
||||
"datasource": { "uid": "prometheus", "type": "prometheus" },
|
||||
"gridPos": { "h": 8, "w": 8, "x": 16, "y": 1 },
|
||||
"targets": [
|
||||
{ "expr": "histogram_quantile(0.50, sum by (le) (rate(http_server_request_duration_seconds_bucket{service_name=\"messenger-api\"}[$__rate_interval])))", "legendFormat": "p50" },
|
||||
{ "expr": "histogram_quantile(0.95, sum by (le) (rate(http_server_request_duration_seconds_bucket{service_name=\"messenger-api\"}[$__rate_interval])))", "legendFormat": "p95" },
|
||||
{ "expr": "histogram_quantile(0.99, sum by (le) (rate(http_server_request_duration_seconds_bucket{service_name=\"messenger-api\"}[$__rate_interval])))", "legendFormat": "p99" }
|
||||
],
|
||||
"fieldConfig": { "defaults": { "unit": "s" } }
|
||||
},
|
||||
{
|
||||
"type": "row",
|
||||
"title": "Worker & Jobs",
|
||||
"gridPos": { "h": 1, "w": 24, "x": 0, "y": 9 },
|
||||
"collapsed": false
|
||||
},
|
||||
{
|
||||
"type": "timeseries",
|
||||
"title": "Jobs processed rate (by outcome)",
|
||||
"description": "Успехи, retries, терминальные отказы. Метрика: messenger_jobs_processed_total.",
|
||||
"datasource": { "uid": "prometheus", "type": "prometheus" },
|
||||
"gridPos": { "h": 8, "w": 8, "x": 0, "y": 10 },
|
||||
"targets": [
|
||||
{
|
||||
"expr": "sum by (outcome) (rate(messenger_jobs_processed_total{service_name=\"messenger-worker\"}[$__rate_interval]))",
|
||||
"legendFormat": "{{outcome}}"
|
||||
}
|
||||
],
|
||||
"fieldConfig": { "defaults": { "unit": "ops" } }
|
||||
},
|
||||
{
|
||||
"type": "timeseries",
|
||||
"title": "Job processing duration p50 / p95 / p99",
|
||||
"description": "Время в worker.process (staging -> variants -> original -> COMMIT). Метрика: messenger_job_duration_seconds.",
|
||||
"datasource": { "uid": "prometheus", "type": "prometheus" },
|
||||
"gridPos": { "h": 8, "w": 8, "x": 8, "y": 10 },
|
||||
"targets": [
|
||||
{ "expr": "histogram_quantile(0.50, sum by (le) (rate(messenger_job_duration_seconds_bucket{service_name=\"messenger-worker\"}[$__rate_interval])))", "legendFormat": "p50" },
|
||||
{ "expr": "histogram_quantile(0.95, sum by (le) (rate(messenger_job_duration_seconds_bucket{service_name=\"messenger-worker\"}[$__rate_interval])))", "legendFormat": "p95" },
|
||||
{ "expr": "histogram_quantile(0.99, sum by (le) (rate(messenger_job_duration_seconds_bucket{service_name=\"messenger-worker\"}[$__rate_interval])))", "legendFormat": "p99" }
|
||||
],
|
||||
"fieldConfig": { "defaults": { "unit": "s" } }
|
||||
},
|
||||
{
|
||||
"type": "timeseries",
|
||||
"title": "End-to-end time to ready p50 / p95 / p99",
|
||||
"description": "От durable acceptance (202) до ready. SLI. Метрика: messenger_time_to_ready_seconds.",
|
||||
"datasource": { "uid": "prometheus", "type": "prometheus" },
|
||||
"gridPos": { "h": 8, "w": 8, "x": 16, "y": 10 },
|
||||
"targets": [
|
||||
{ "expr": "histogram_quantile(0.50, sum by (le) (rate(messenger_time_to_ready_seconds_bucket[$__rate_interval])))", "legendFormat": "p50" },
|
||||
{ "expr": "histogram_quantile(0.95, sum by (le) (rate(messenger_time_to_ready_seconds_bucket[$__rate_interval])))", "legendFormat": "p95" },
|
||||
{ "expr": "histogram_quantile(0.99, sum by (le) (rate(messenger_time_to_ready_seconds_bucket[$__rate_interval])))", "legendFormat": "p99" }
|
||||
],
|
||||
"fieldConfig": { "defaults": { "unit": "s" } }
|
||||
},
|
||||
{
|
||||
"type": "row",
|
||||
"title": "Queue & Backlog",
|
||||
"gridPos": { "h": 1, "w": 24, "x": 0, "y": 18 },
|
||||
"collapsed": false
|
||||
},
|
||||
{
|
||||
"type": "timeseries",
|
||||
"title": "Queue depth (broker stream + DB jobs queued)",
|
||||
"description": "Broker = Redis Streams PEL (pending не-acked). DB = jobs.status='queued'. Источники: messenger_queue_depth, messenger_jobs_queued.",
|
||||
"datasource": { "uid": "prometheus", "type": "prometheus" },
|
||||
"gridPos": { "h": 8, "w": 12, "x": 0, "y": 19 },
|
||||
"targets": [
|
||||
{ "expr": "sum(messenger_queue_depth{service_name=\"messenger-api\"})", "legendFormat": "broker pending" },
|
||||
{ "expr": "sum(messenger_jobs_queued{service_name=\"messenger-api\"})", "legendFormat": "DB queued jobs" }
|
||||
],
|
||||
"fieldConfig": { "defaults": { "unit": "short" } }
|
||||
},
|
||||
{
|
||||
"type": "timeseries",
|
||||
"title": "Queue oldest age (broker + DB)",
|
||||
"description": "Сколько секунд старейшее сообщение/задание ещё не обработано. Рост = worker не справляется или недоступен.",
|
||||
"datasource": { "uid": "prometheus", "type": "prometheus" },
|
||||
"gridPos": { "h": 8, "w": 12, "x": 12, "y": 19 },
|
||||
"targets": [
|
||||
{ "expr": "max(messenger_queue_oldest_age_seconds{service_name=\"messenger-api\"})", "legendFormat": "broker oldest (s)" },
|
||||
{ "expr": "max(messenger_jobs_oldest_queued_age_seconds{service_name=\"messenger-api\"})", "legendFormat": "DB oldest (s)" }
|
||||
],
|
||||
"fieldConfig": { "defaults": { "unit": "s" } }
|
||||
},
|
||||
{
|
||||
"type": "row",
|
||||
"title": "Saturation",
|
||||
"gridPos": { "h": 1, "w": 24, "x": 0, "y": 27 },
|
||||
"collapsed": false
|
||||
},
|
||||
{
|
||||
"type": "timeseries",
|
||||
"title": "DB pool used / capacity",
|
||||
"description": "Acquired connections из pgx pool. Метрики: messenger_db_pool_used, messenger_db_pool_capacity.",
|
||||
"datasource": { "uid": "prometheus", "type": "prometheus" },
|
||||
"gridPos": { "h": 8, "w": 8, "x": 0, "y": 28 },
|
||||
"targets": [
|
||||
{ "expr": "sum(messenger_db_pool_used{service_name=\"messenger-api\"})", "legendFormat": "used (api)" },
|
||||
{ "expr": "sum(messenger_db_pool_capacity{service_name=\"messenger-api\"})", "legendFormat": "capacity (api)" },
|
||||
{ "expr": "sum(messenger_db_pool_used{service_name=\"messenger-worker\"})", "legendFormat": "used (worker)" },
|
||||
{ "expr": "sum(messenger_db_pool_capacity{service_name=\"messenger-worker\"})", "legendFormat": "capacity (worker)" }
|
||||
],
|
||||
"fieldConfig": { "defaults": { "unit": "short" } }
|
||||
},
|
||||
{
|
||||
"type": "timeseries",
|
||||
"title": "Worker saturation (busy / capacity)",
|
||||
"description": "1 = worker занят, 0 = простаивает. Для одного worker это occupancy rate.",
|
||||
"datasource": { "uid": "prometheus", "type": "prometheus" },
|
||||
"gridPos": { "h": 8, "w": 8, "x": 8, "y": 28 },
|
||||
"targets": [
|
||||
{ "expr": "sum(messenger_worker_busy{service_name=\"messenger-worker\"})", "legendFormat": "busy" },
|
||||
{ "expr": "sum(messenger_worker_capacity{service_name=\"messenger-worker\"})", "legendFormat": "capacity" }
|
||||
],
|
||||
"fieldConfig": { "defaults": { "unit": "short" } }
|
||||
},
|
||||
{
|
||||
"type": "timeseries",
|
||||
"title": "DB pool empty-acquire events",
|
||||
"description": "Счётчик случаев, когда acquire ждал свободного соединения. Рост = пул undersized. Метрика: messenger_db_pool_empty_acquires_total.",
|
||||
"datasource": { "uid": "prometheus", "type": "prometheus" },
|
||||
"gridPos": { "h": 8, "w": 8, "x": 16, "y": 28 },
|
||||
"targets": [
|
||||
{
|
||||
"expr": "sum by (service_name) (rate(messenger_db_pool_empty_acquires_total[$__rate_interval]))",
|
||||
"legendFormat": "{{service_name}}"
|
||||
}
|
||||
],
|
||||
"fieldConfig": { "defaults": { "unit": "ops" } }
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
# LAB 6: три источника данных. Grafana — интерфейс, она НЕ хранит сигналы.
|
||||
# uid фиксированы: на них ссылаются dashboard JSON и alert rules из Git.
|
||||
|
||||
apiVersion: 1
|
||||
|
||||
datasources:
|
||||
- name: Prometheus
|
||||
uid: prometheus
|
||||
type: prometheus
|
||||
access: proxy
|
||||
url: http://prometheus:9090
|
||||
isDefault: true
|
||||
editable: false
|
||||
jsonData:
|
||||
timeInterval: 5s
|
||||
httpMethod: POST
|
||||
|
||||
- name: Loki
|
||||
uid: loki
|
||||
type: loki
|
||||
access: proxy
|
||||
url: http://loki:3100
|
||||
editable: false
|
||||
jsonData:
|
||||
maxLines: 1000
|
||||
# Переход лог -> трасса: trace_id из structured metadata OTLP-записи.
|
||||
derivedFields:
|
||||
- name: TraceID
|
||||
matcherRegex: '"?trace_id"?[=:]"?([a-f0-9]{32})'
|
||||
url: '$${__value.raw}'
|
||||
datasourceUid: tempo
|
||||
urlDisplayLabel: Open trace in Tempo
|
||||
|
||||
- name: Tempo
|
||||
uid: tempo
|
||||
type: tempo
|
||||
access: proxy
|
||||
url: http://tempo:3200
|
||||
editable: false
|
||||
jsonData:
|
||||
# Обратный переход трасса -> логи того же trace_id.
|
||||
tracesToLogsV2:
|
||||
datasourceUid: loki
|
||||
filterByTraceID: true
|
||||
filterBySpanID: false
|
||||
customQuery: false
|
||||
serviceMap:
|
||||
datasourceUid: prometheus
|
||||
nodeGraph:
|
||||
enabled: true
|
||||
search:
|
||||
hide: false
|
||||
Reference in New Issue
Block a user