Реализовать лабораторную 6 на 5: SLO и обнаружение инцидентов

This commit is contained in:
Ванек
2026-11-19 18:53:24 +03:00
parent 470d9d6f1e
commit 8dad129edf
127 changed files with 53496 additions and 61 deletions
+618
View File
@@ -0,0 +1,618 @@
{
"uid": "messenger-lab6",
"title": "Messenger — Lab 6: signals and SLO",
"schemaVersion": 41,
"version": 1,
"refresh": "5s",
"time": {
"from": "now-30m",
"to": "now"
},
"tags": [
"lab6",
"slo"
],
"panels": [
{
"id": 1,
"title": "Business API RPS",
"type": "timeseries",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 0,
"y": 0,
"w": 12,
"h": 8
},
"fieldConfig": {
"defaults": {
"unit": "reqps"
},
"overrides": []
},
"description": "",
"targets": [
{
"refId": "A",
"expr": "sum by (method, route) (rate(messenger_http_requests_total[1m]))",
"legendFormat": "{{method}} {{route}}"
}
]
},
{
"id": 2,
"title": "API 5xx / all business requests",
"type": "timeseries",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 12,
"y": 0,
"w": 12,
"h": 8
},
"fieldConfig": {
"defaults": {
"unit": "percentunit"
},
"overrides": []
},
"description": "",
"targets": [
{
"refId": "A",
"expr": "lab6:api_bad_ratio:1m",
"legendFormat": "API 5xx / all business requests"
}
]
},
{
"id": 3,
"title": "API latency: aggregated histogram",
"type": "timeseries",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 0,
"y": 8,
"w": 12,
"h": 8
},
"fieldConfig": {
"defaults": {
"unit": "s"
},
"overrides": []
},
"description": "Seconds to response headers; excludes health. Sum buckets across replicas before percentile.",
"targets": [
{
"refId": "A",
"expr": "histogram_quantile(0.5, sum by (le) (rate(messenger_http_duration_seconds_bucket[1m])))",
"legendFormat": "p50"
},
{
"refId": "B",
"expr": "histogram_quantile(0.95, sum by (le) (rate(messenger_http_duration_seconds_bucket[1m])))",
"legendFormat": "p95"
},
{
"refId": "C",
"expr": "histogram_quantile(0.99, sum by (le) (rate(messenger_http_duration_seconds_bucket[1m])))",
"legendFormat": "p99"
}
]
},
{
"id": 4,
"title": "Time from acceptance to ready: completed jobs",
"type": "timeseries",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 12,
"y": 8,
"w": 12,
"h": 8
},
"fieldConfig": {
"defaults": {
"unit": "s"
},
"overrides": []
},
"description": "Success histogram only. SLO below also includes jobs that never complete.",
"targets": [
{
"refId": "A",
"expr": "histogram_quantile(0.5, sum by (le) (rate(messenger_attachment_ready_duration_seconds_bucket[2m])))",
"legendFormat": "p50"
},
{
"refId": "B",
"expr": "histogram_quantile(0.95, sum by (le) (rate(messenger_attachment_ready_duration_seconds_bucket[2m])))",
"legendFormat": "p95"
},
{
"refId": "C",
"expr": "histogram_quantile(0.99, sum by (le) (rate(messenger_attachment_ready_duration_seconds_bucket[2m])))",
"legendFormat": "p99"
}
]
},
{
"id": 5,
"title": "Job attempts by outcome",
"type": "timeseries",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 0,
"y": 16,
"w": 12,
"h": 8
},
"fieldConfig": {
"defaults": {
"unit": "ops"
},
"overrides": []
},
"description": "",
"targets": [
{
"refId": "A",
"expr": "sum by (outcome) (rate(messenger_job_attempts_total[1m]))",
"legendFormat": "{{outcome}}"
}
]
},
{
"id": 6,
"title": "Worker processing p95",
"type": "timeseries",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 12,
"y": 16,
"w": 12,
"h": 8
},
"fieldConfig": {
"defaults": {
"unit": "s"
},
"overrides": []
},
"description": "",
"targets": [
{
"refId": "A",
"expr": "histogram_quantile(0.95, sum by (le, outcome) (rate(messenger_job_duration_seconds_bucket[1m])))",
"legendFormat": "{{outcome}}"
}
]
},
{
"id": 7,
"title": "Outstanding jobs (DB source of truth)",
"type": "timeseries",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 0,
"y": 24,
"w": 12,
"h": 8
},
"fieldConfig": {
"defaults": {
"unit": "short"
},
"overrides": []
},
"description": "Queued + processing durable jobs, including retry/outbox; not Redis XLEN.",
"targets": [
{
"refId": "A",
"expr": "max(messenger_queue_depth)",
"legendFormat": "Outstanding jobs (DB source of truth)"
}
]
},
{
"id": 8,
"title": "Oldest unfinished job age",
"type": "timeseries",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 12,
"y": 24,
"w": 12,
"h": 8
},
"fieldConfig": {
"defaults": {
"unit": "s"
},
"overrides": []
},
"description": "",
"targets": [
{
"refId": "A",
"expr": "max(messenger_queue_oldest_age_seconds)",
"legendFormat": "Oldest unfinished job age"
}
]
},
{
"id": 9,
"title": "DB pool used / waiting",
"type": "timeseries",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 0,
"y": 32,
"w": 12,
"h": 8
},
"fieldConfig": {
"defaults": {
"unit": "short"
},
"overrides": []
},
"description": "",
"targets": [
{
"refId": "A",
"expr": "sum by (service_name, state) (messenger_db_pool)",
"legendFormat": "{{service_name}} {{state}}"
}
]
},
{
"id": 10,
"title": "Worker busy / capacity",
"type": "timeseries",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 12,
"y": 32,
"w": 12,
"h": 8
},
"fieldConfig": {
"defaults": {
"unit": "short"
},
"overrides": []
},
"description": "",
"targets": [
{
"refId": "A",
"expr": "sum(messenger_worker_busy) or vector(0)",
"legendFormat": "busy"
},
{
"refId": "B",
"expr": "sum(messenger_worker_capacity) or vector(0)",
"legendFormat": "capacity"
}
]
},
{
"id": 11,
"title": "Process CPU: cores consumed",
"type": "timeseries",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 0,
"y": 40,
"w": 12,
"h": 8
},
"fieldConfig": {
"defaults": {
"unit": "short"
},
"overrides": []
},
"description": "",
"targets": [
{
"refId": "A",
"expr": "sum by (service_name) (rate(messenger_process_cpu_time_seconds_total[1m]))",
"legendFormat": "{{service_name}}"
}
]
},
{
"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": []
},
"description": "",
"targets": [
{
"refId": "A",
"expr": "sum by (service_name) (messenger_process_memory_bytes)",
"legendFormat": "{{service_name}}"
}
]
},
{
"id": 13,
"title": "API availability SLO: >= 99% / 1h",
"type": "timeseries",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 0,
"y": 48,
"w": 12,
"h": 8
},
"fieldConfig": {
"defaults": {
"unit": "percentunit"
},
"overrides": []
},
"description": "5xx bad; all instrumented business requests denominator; 4xx not server failures.",
"targets": [
{
"refId": "A",
"expr": "1-lab6:api_bad_ratio:1h",
"legendFormat": "API availability SLO: >= 99% / 1h"
}
]
},
{
"id": 14,
"title": "Ready SLO: >= 95% within 30s / 1h",
"type": "timeseries",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 12,
"y": 48,
"w": 12,
"h": 8
},
"fieldConfig": {
"defaults": {
"unit": "percentunit"
},
"overrides": []
},
"description": "Acceptance cohorts mature after 30s. Failed, stuck and late jobs are BAD. No ready-only bias.",
"targets": [
{
"refId": "A",
"expr": "1-lab6:ready_bad_ratio:1h",
"legendFormat": "Ready SLO: >= 95% within 30s / 1h"
}
]
},
{
"id": 15,
"title": "API burn rate (budget / hour)",
"type": "timeseries",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 0,
"y": 56,
"w": 12,
"h": 8
},
"fieldConfig": {
"defaults": {
"unit": "short"
},
"overrides": []
},
"description": "Fast: 2m AND 30s > 6x, for 15s. Slow: 6m AND 1m > 3x, for 30s.",
"targets": [
{
"refId": "A",
"expr": "lab6:api_bad_ratio:30s/0.01",
"legendFormat": "30s"
},
{
"refId": "B",
"expr": "lab6:api_bad_ratio:2m/0.01",
"legendFormat": "2m"
},
{
"refId": "C",
"expr": "lab6:api_bad_ratio:1m/0.01",
"legendFormat": "1m"
},
{
"refId": "D",
"expr": "lab6:api_bad_ratio:6m/0.01",
"legendFormat": "6m"
}
]
},
{
"id": 16,
"title": "Ready burn rate (budget / hour)",
"type": "timeseries",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 12,
"y": 56,
"w": 12,
"h": 8
},
"fieldConfig": {
"defaults": {
"unit": "short"
},
"overrides": []
},
"description": "Fast: 2m AND 30s > 6x, for 15s. Slow: 6m AND 1m > 3x, for 30s.",
"targets": [
{
"refId": "A",
"expr": "lab6:ready_bad_ratio:30s/0.05",
"legendFormat": "30s"
},
{
"refId": "B",
"expr": "lab6:ready_bad_ratio:2m/0.05",
"legendFormat": "2m"
},
{
"refId": "C",
"expr": "lab6:ready_bad_ratio:1m/0.05",
"legendFormat": "1m"
},
{
"refId": "D",
"expr": "lab6:ready_bad_ratio:6m/0.05",
"legendFormat": "6m"
}
]
},
{
"id": 17,
"title": "Local alert states",
"type": "timeseries",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 0,
"y": 64,
"w": 12,
"h": 8
},
"fieldConfig": {
"defaults": {
"unit": "short"
},
"overrides": []
},
"description": "",
"targets": [
{
"refId": "A",
"expr": "ALERTS{alertstate=~\"pending|firing\"}",
"legendFormat": "{{alertname}} {{alertstate}}"
}
]
},
{
"id": 18,
"title": "API / worker structured logs (click TraceID)",
"type": "logs",
"datasource": {
"type": "loki",
"uid": "loki"
},
"gridPos": {
"x": 12,
"y": 64,
"w": 12,
"h": 8
},
"targets": [
{
"refId": "A",
"expr": "{service_name=~\"messenger-api|messenger-worker\"} | json"
}
],
"options": {
"showTime": true,
"wrapLogMessage": true
}
},
{
"id": 19,
"title": "Recent real worker traces",
"type": "table",
"datasource": {
"type": "tempo",
"uid": "tempo"
},
"gridPos": {
"x": 0,
"y": 72,
"w": 24,
"h": 9
},
"targets": [
{
"refId": "A",
"queryType": "traceql",
"query": "{ resource.service.name = \"messenger-worker\" }",
"limit": 20,
"tableType": "traces",
"filters": []
}
]
}
],
"annotations": {
"list": []
}
}
@@ -0,0 +1,9 @@
apiVersion: 1
providers:
- name: messenger
folder: Lab 6
type: file
disableDeletion: false
updateIntervalSeconds: 10
options:
path: /var/lib/grafana/dashboards
@@ -0,0 +1,35 @@
apiVersion: 1
datasources:
- name: Prometheus
uid: prometheus
type: prometheus
access: proxy
url: http://prometheus:9090
isDefault: true
jsonData:
timeInterval: 5s
- name: Loki
uid: loki
type: loki
access: proxy
url: http://loki:3100
jsonData:
derivedFields:
- name: TraceID
matcherRegex: '"trace_id": "([a-f0-9]{32})"'
datasourceUid: tempo
url: '$${__value.raw}'
- name: Tempo
uid: tempo
type: tempo
access: proxy
url: http://tempo:3200
jsonData:
tracesToLogs:
datasourceUid: loki
spanStartTimeShift: '-1m'
spanEndTimeShift: '1m'
filterByTraceID: true
tags: [{key: service.name, value: service_name}]
nodeGraph:
enabled: true