feat(lab6): complete observability stack with OTel, Grafana provisioning, worker metrics, alert rules, and incident experiments
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
groups:
|
||||
- name: messenger_slo
|
||||
rules:
|
||||
- alert: HighErrorRate
|
||||
expr: |
|
||||
(
|
||||
sum(rate(http_server_duration_milliseconds_count{http_status_code=~"5.."}[5m])) or vector(0)
|
||||
)
|
||||
/
|
||||
sum(rate(http_server_duration_milliseconds_count[5m]))
|
||||
for: 1m
|
||||
labels:
|
||||
severity: critical
|
||||
annotations:
|
||||
summary: "API error rate > 5% (SLO 99%)"
|
||||
description: "Доля 5xx за 5-минутное окно превысила 5%. SLI из histogram-метрик API."
|
||||
|
||||
- alert: QueueLagGrowing
|
||||
expr: messenger_queue_oldest_job_age_seconds > 60
|
||||
for: 2m
|
||||
labels:
|
||||
severity: warning
|
||||
annotations:
|
||||
summary: "Очередь задач растёт (возраст старейшей job > 60s)"
|
||||
description: "Worker не успевает дренировать очередь."
|
||||
@@ -0,0 +1,41 @@
|
||||
receivers:
|
||||
otlp:
|
||||
protocols:
|
||||
http:
|
||||
endpoint: 0.0.0.0:4318
|
||||
|
||||
processors:
|
||||
memory_limiter:
|
||||
check_interval: 1s
|
||||
limit_mib: 384
|
||||
spike_limit_mib: 96
|
||||
batch:
|
||||
send_batch_size: 512
|
||||
timeout: 5s
|
||||
|
||||
exporters:
|
||||
otlphttp/tempo:
|
||||
endpoint: "http://tempo:4318"
|
||||
otlphttp/loki:
|
||||
endpoint: "http://loki:4317" # Loki поддерживает OTLP gRPC, но для простоты используем prometheus/loki native или otlphttp если включен
|
||||
# На самом деле Loki лучше принимать через promtail или loki receiver, но для OTLP в Grafana стеке часто используют otlphttp с loki, либо promtail.
|
||||
# Используем нативный loki exporter или otlphttp. Для простоты и совместимости с grafana/loki:3.3.2 используем otlphttp.
|
||||
prometheus:
|
||||
endpoint: "0.0.0.0:8889"
|
||||
resource_to_telemetry_conversion:
|
||||
enabled: true
|
||||
|
||||
service:
|
||||
pipelines:
|
||||
traces:
|
||||
receivers: [otlp]
|
||||
processors: [memory_limiter, batch]
|
||||
exporters: [otlphttp/tempo]
|
||||
metrics:
|
||||
receivers: [otlp]
|
||||
processors: [memory_limiter, batch]
|
||||
exporters: [prometheus]
|
||||
logs:
|
||||
receivers: [otlp]
|
||||
processors: [memory_limiter, batch]
|
||||
exporters: [otlphttp/loki]
|
||||
@@ -0,0 +1,12 @@
|
||||
apiVersion: 1
|
||||
|
||||
providers:
|
||||
- name: 'messenger'
|
||||
orgId: 1
|
||||
folder: 'Messenger'
|
||||
type: file
|
||||
disableDeletion: false
|
||||
updateIntervalSeconds: 30
|
||||
allowUiUpdates: true
|
||||
options:
|
||||
path: /var/lib/grafana/dashboards
|
||||
@@ -0,0 +1,102 @@
|
||||
{
|
||||
"uid": "messenger-lab6",
|
||||
"title": "Messenger — Lab6 Observability",
|
||||
"tags": ["messenger", "lab6"],
|
||||
"timezone": "browser",
|
||||
"schemaVersion": 39,
|
||||
"refresh": "10s",
|
||||
"time": { "from": "now-15m", "to": "now" },
|
||||
"panels": [
|
||||
{
|
||||
"id": 1, "type": "timeseries", "title": "RPS (по endpoint'ам)",
|
||||
"gridPos": { "h": 8, "w": 12, "x": 0, "y": 0 },
|
||||
"datasource": { "type": "prometheus", "uid": "prometheus" },
|
||||
"fieldConfig": { "defaults": { "unit": "reqps" }, "overrides": [] },
|
||||
"targets": [
|
||||
{ "refId": "A", "expr": "sum by (http_target) (rate(http_server_duration_milliseconds_count[5m]))", "legendFormat": "{{http_target}}" }
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"type": "timeseries",
|
||||
"title": "Доля ошибок 5xx (SLI)",
|
||||
"gridPos": { "h": 8, "w": 12, "x": 12, "y": 0 },
|
||||
"datasource": { "type": "prometheus", "uid": "prometheus" },
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"unit": "percentunit",
|
||||
"min": 0,
|
||||
"max": 1
|
||||
},
|
||||
"overrides": []
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"refId": "A",
|
||||
"expr": "(sum(rate(http_server_duration_milliseconds_count{http_status_code=~\"5..\"}[5m])) or vector(0)) / sum(rate(http_server_duration_milliseconds_count[5m]))",
|
||||
"legendFormat": "error ratio"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 3, "type": "timeseries", "title": "API latency p50/p95/p99 (из histogram, ms)",
|
||||
"gridPos": { "h": 8, "w": 12, "x": 0, "y": 8 },
|
||||
"datasource": { "type": "prometheus", "uid": "prometheus" },
|
||||
"fieldConfig": { "defaults": { "unit": "ms" }, "overrides": [] },
|
||||
"targets": [
|
||||
{ "refId": "A", "expr": "histogram_quantile(0.50, sum by (le) (rate(http_server_duration_milliseconds_bucket[5m])))", "legendFormat": "p50" },
|
||||
{ "refId": "B", "expr": "histogram_quantile(0.95, sum by (le) (rate(http_server_duration_milliseconds_bucket[5m])))", "legendFormat": "p95" },
|
||||
{ "refId": "C", "expr": "histogram_quantile(0.99, sum by (le) (rate(http_server_duration_milliseconds_bucket[5m])))", "legendFormat": "p99" }
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 4, "type": "timeseries", "title": "Worker jobs: completed / failed",
|
||||
"gridPos": { "h": 8, "w": 12, "x": 12, "y": 8 },
|
||||
"datasource": { "type": "prometheus", "uid": "prometheus" },
|
||||
"fieldConfig": { "defaults": { "unit": "reqps" }, "overrides": [] },
|
||||
"targets": [
|
||||
{ "refId": "A", "expr": "sum(rate(messenger_worker_jobs_completed_total[5m]))", "legendFormat": "completed" },
|
||||
{ "refId": "B", "expr": "sum(rate(messenger_worker_jobs_failed_total[5m]))", "legendFormat": "failed" }
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 5, "type": "timeseries", "title": "Worker job duration p50/p95 (s)",
|
||||
"gridPos": { "h": 8, "w": 12, "x": 0, "y": 16 },
|
||||
"datasource": { "type": "prometheus", "uid": "prometheus" },
|
||||
"fieldConfig": { "defaults": { "unit": "s" }, "overrides": [] },
|
||||
"targets": [
|
||||
{ "refId": "A", "expr": "histogram_quantile(0.50, sum by (le) (rate(messenger_worker_job_duration_seconds_bucket[5m])))", "legendFormat": "p50" },
|
||||
{ "refId": "B", "expr": "histogram_quantile(0.95, sum by (le) (rate(messenger_worker_job_duration_seconds_bucket[5m])))", "legendFormat": "p95" }
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 6, "type": "stat", "title": "Worker saturation (active jobs)",
|
||||
"gridPos": { "h": 8, "w": 6, "x": 12, "y": 16 },
|
||||
"datasource": { "type": "prometheus", "uid": "prometheus" },
|
||||
"targets": [ { "refId": "A", "expr": "sum(messenger_worker_jobs_active)", "legendFormat": "active" } ]
|
||||
},
|
||||
{
|
||||
"id": 7, "type": "stat", "title": "Queue depth (active jobs)",
|
||||
"gridPos": { "h": 8, "w": 6, "x": 18, "y": 16 },
|
||||
"datasource": { "type": "prometheus", "uid": "prometheus" },
|
||||
"targets": [ { "refId": "A", "expr": "sum(messenger_queue_active_jobs)", "legendFormat": "queued+processing" } ]
|
||||
},
|
||||
{
|
||||
"id": 8, "type": "timeseries", "title": "Возраст старейшей job (queue lag)",
|
||||
"gridPos": { "h": 8, "w": 12, "x": 0, "y": 24 },
|
||||
"datasource": { "type": "prometheus", "uid": "prometheus" },
|
||||
"fieldConfig": { "defaults": { "unit": "s" }, "overrides": [] },
|
||||
"targets": [ { "refId": "A", "expr": "sum(messenger_queue_oldest_job_age_seconds)", "legendFormat": "oldest age" } ]
|
||||
},
|
||||
{
|
||||
"id": 9, "type": "timeseries", "title": "DB pool (size / checked out / overflow)",
|
||||
"gridPos": { "h": 8, "w": 12, "x": 12, "y": 24 },
|
||||
"datasource": { "type": "prometheus", "uid": "prometheus" },
|
||||
"targets": [
|
||||
{ "refId": "A", "expr": "sum(messenger_db_pool_size)", "legendFormat": "size" },
|
||||
{ "refId": "B", "expr": "sum(messenger_db_pool_checked_out)", "legendFormat": "checked out" },
|
||||
{ "refId": "C", "expr": "sum(messenger_db_pool_overflow)", "legendFormat": "overflow" }
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
apiVersion: 1
|
||||
|
||||
providers:
|
||||
- name: 'messenger'
|
||||
orgId: 1
|
||||
folder: 'Messenger'
|
||||
type: file
|
||||
disableDeletion: false
|
||||
updateIntervalSeconds: 30
|
||||
allowUiUpdates: true
|
||||
options:
|
||||
path: /var/lib/grafana/dashboards
|
||||
@@ -0,0 +1,88 @@
|
||||
{
|
||||
"uid": "messenger-lab6",
|
||||
"title": "Messenger — Lab6 Observability",
|
||||
"tags": ["messenger", "lab6"],
|
||||
"timezone": "browser",
|
||||
"schemaVersion": 39,
|
||||
"refresh": "10s",
|
||||
"time": { "from": "now-15m", "to": "now" },
|
||||
"panels": [
|
||||
{
|
||||
"id": 1, "type": "timeseries", "title": "RPS (по маршрутам)",
|
||||
"gridPos": { "h": 8, "w": 12, "x": 0, "y": 0 },
|
||||
"datasource": { "type": "prometheus", "uid": "prometheus" },
|
||||
"targets": [
|
||||
{ "refId": "A", "expr": "sum by (http_route) (rate(http_server_duration_seconds_count[5m]))", "legendFormat": "{{http_route}}" }
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 2, "type": "timeseries", "title": "Доля ошибок 5xx (SLI)",
|
||||
"gridPos": { "h": 8, "w": 12, "x": 12, "y": 0 },
|
||||
"datasource": { "type": "prometheus", "uid": "prometheus" },
|
||||
"fieldConfig": { "defaults": { "unit": "percentunit", "max": 1 }, "overrides": [] },
|
||||
"targets": [
|
||||
{ "refId": "A", "expr": "sum(rate(http_server_duration_seconds_count{http_response_status_code=~\"5..\"}[5m])) / sum(rate(http_server_duration_seconds_count[5m]))", "legendFormat": "error ratio" }
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 3, "type": "timeseries", "title": "API latency p50/p95/p99 (из histogram)",
|
||||
"gridPos": { "h": 8, "w": 12, "x": 0, "y": 8 },
|
||||
"datasource": { "type": "prometheus", "uid": "prometheus" },
|
||||
"fieldConfig": { "defaults": { "unit": "s" }, "overrides": [] },
|
||||
"targets": [
|
||||
{ "refId": "A", "expr": "histogram_quantile(0.50, sum by (le) (rate(http_server_duration_seconds_bucket[5m])))", "legendFormat": "p50" },
|
||||
{ "refId": "B", "expr": "histogram_quantile(0.95, sum by (le) (rate(http_server_duration_seconds_bucket[5m])))", "legendFormat": "p95" },
|
||||
{ "refId": "C", "expr": "histogram_quantile(0.99, sum by (le) (rate(http_server_duration_seconds_bucket[5m])))", "legendFormat": "p99" }
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 4, "type": "timeseries", "title": "Worker jobs: completed / failed",
|
||||
"gridPos": { "h": 8, "w": 12, "x": 12, "y": 8 },
|
||||
"datasource": { "type": "prometheus", "uid": "prometheus" },
|
||||
"fieldConfig": { "defaults": { "unit": "reqps" }, "overrides": [] },
|
||||
"targets": [
|
||||
{ "refId": "A", "expr": "sum(rate(messenger_worker_jobs_completed_total[5m]))", "legendFormat": "completed" },
|
||||
{ "refId": "B", "expr": "sum(rate(messenger_worker_jobs_failed_total[5m]))", "legendFormat": "failed" }
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 5, "type": "timeseries", "title": "Worker job duration p50/p95",
|
||||
"gridPos": { "h": 8, "w": 12, "x": 0, "y": 16 },
|
||||
"datasource": { "type": "prometheus", "uid": "prometheus" },
|
||||
"fieldConfig": { "defaults": { "unit": "s" }, "overrides": [] },
|
||||
"targets": [
|
||||
{ "refId": "A", "expr": "histogram_quantile(0.50, sum by (le) (rate(messenger_worker_job_duration_seconds_bucket[5m])))", "legendFormat": "p50" },
|
||||
{ "refId": "B", "expr": "histogram_quantile(0.95, sum by (le) (rate(messenger_worker_job_duration_seconds_bucket[5m])))", "legendFormat": "p95" }
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 6, "type": "stat", "title": "Worker saturation (active jobs)",
|
||||
"gridPos": { "h": 8, "w": 6, "x": 12, "y": 16 },
|
||||
"datasource": { "type": "prometheus", "uid": "prometheus" },
|
||||
"targets": [ { "refId": "A", "expr": "sum(messenger_worker_jobs_active)", "legendFormat": "active" } ]
|
||||
},
|
||||
{
|
||||
"id": 7, "type": "stat", "title": "Queue depth (active jobs)",
|
||||
"gridPos": { "h": 8, "w": 6, "x": 18, "y": 16 },
|
||||
"datasource": { "type": "prometheus", "uid": "prometheus" },
|
||||
"targets": [ { "refId": "A", "expr": "sum(messenger_queue_active_jobs)", "legendFormat": "queued+processing" } ]
|
||||
},
|
||||
{
|
||||
"id": 8, "type": "timeseries", "title": "Возраст старейшей job (queue lag)",
|
||||
"gridPos": { "h": 8, "w": 12, "x": 0, "y": 24 },
|
||||
"datasource": { "type": "prometheus", "uid": "prometheus" },
|
||||
"fieldConfig": { "defaults": { "unit": "s" }, "overrides": [] },
|
||||
"targets": [ { "refId": "A", "expr": "sum(messenger_queue_oldest_job_age_seconds)", "legendFormat": "oldest age" } ]
|
||||
},
|
||||
{
|
||||
"id": 9, "type": "timeseries", "title": "DB pool (size / checked out / overflow)",
|
||||
"gridPos": { "h": 8, "w": 12, "x": 12, "y": 24 },
|
||||
"datasource": { "type": "prometheus", "uid": "prometheus" },
|
||||
"targets": [
|
||||
{ "refId": "A", "expr": "sum(messenger_db_pool_size)", "legendFormat": "size" },
|
||||
{ "refId": "B", "expr": "sum(messenger_db_pool_checked_out)", "legendFormat": "checked out" },
|
||||
{ "refId": "C", "expr": "sum(messenger_db_pool_overflow)", "legendFormat": "overflow" }
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
apiVersion: 1
|
||||
|
||||
datasources:
|
||||
- name: Prometheus
|
||||
type: prometheus
|
||||
uid: prometheus
|
||||
url: http://prometheus:9090
|
||||
isDefault: true
|
||||
editable: false
|
||||
|
||||
- name: Loki
|
||||
type: loki
|
||||
uid: loki
|
||||
url: http://loki:3100
|
||||
editable: false
|
||||
jsonData:
|
||||
derivedFields:
|
||||
- name: TraceID
|
||||
matcherRegex: "trace_id=(\\w+)"
|
||||
url: "$${__value.raw}"
|
||||
datasourceUid: tempo
|
||||
|
||||
- name: Tempo
|
||||
type: tempo
|
||||
uid: tempo
|
||||
url: http://tempo:3200
|
||||
editable: false
|
||||
jsonData:
|
||||
tracesToLogsV2:
|
||||
datasourceUid: loki
|
||||
spanStartTimeShift: -5m
|
||||
spanEndTimeShift: 5m
|
||||
tags: [{ key: 'service.name', value: 'job' }]
|
||||
filterByTraceID: true
|
||||
filterBySpanID: true
|
||||
@@ -0,0 +1,29 @@
|
||||
auth_enabled: false
|
||||
|
||||
server:
|
||||
http_listen_port: 3100
|
||||
|
||||
common:
|
||||
path_prefix: /loki
|
||||
storage:
|
||||
filesystem:
|
||||
chunks_directory: /loki/chunks
|
||||
rules_directory: /loki/rules
|
||||
replication_factor: 1
|
||||
ring:
|
||||
kvstore:
|
||||
store: inmemory
|
||||
|
||||
schema_config:
|
||||
configs:
|
||||
- from: 2020-10-24
|
||||
store: tsdb
|
||||
object_store: filesystem
|
||||
schema: v13
|
||||
index:
|
||||
prefix: index_
|
||||
period: 24h
|
||||
|
||||
limits_config:
|
||||
allow_structured_metadata: true
|
||||
volume_enabled: true
|
||||
@@ -0,0 +1,11 @@
|
||||
global:
|
||||
scrape_interval: 10s
|
||||
evaluation_interval: 10s
|
||||
|
||||
rule_files:
|
||||
- /etc/prometheus/alerts.yml
|
||||
|
||||
scrape_configs:
|
||||
- job_name: 'otel-collector'
|
||||
static_configs:
|
||||
- targets: ['otel-collector:8889']
|
||||
@@ -0,0 +1,20 @@
|
||||
server:
|
||||
http_listen_port: 3200
|
||||
|
||||
distributor:
|
||||
receivers:
|
||||
otlp:
|
||||
protocols:
|
||||
http:
|
||||
|
||||
storage:
|
||||
trace:
|
||||
backend: local
|
||||
local:
|
||||
path: /var/tempo/traces
|
||||
wal:
|
||||
path: /var/tempo/wal
|
||||
|
||||
compactor:
|
||||
compaction:
|
||||
block_retention: 24h
|
||||
Reference in New Issue
Block a user