This commit is contained in:
2026-11-27 16:42:18 +03:00
parent 20afc2c790
commit a884c07867
133 changed files with 27001 additions and 120 deletions
@@ -0,0 +1,963 @@
{
"uid": "messenger-lab7",
"title": "Messenger — Observability (lab7)",
"description": "API/worker сигналы, SLO, очередь, saturation и telemetry pipeline. Данные — своего приложения.",
"tags": [
"lab7",
"messenger",
"otel"
],
"timezone": "browser",
"schemaVersion": 41,
"version": 1,
"refresh": "10s",
"time": {
"from": "now-30m",
"to": "now"
},
"editable": false,
"graphTooltip": 1,
"panels": [
{
"id": 1,
"type": "stat",
"title": "API RPS",
"description": "Все бизнес-запросы API; health исключён.",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 0,
"y": 0,
"w": 6,
"h": 4
},
"fieldConfig": {
"defaults": {
"unit": "reqps",
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
},
{
"color": "orange",
"value": 0.02
},
{
"color": "red",
"value": 0.05
}
]
},
"color": {
"mode": "thresholds"
}
},
"overrides": []
},
"options": {
"reduceOptions": {
"calcs": [
"lastNotNull"
],
"fields": "",
"values": false
},
"orientation": "auto",
"textMode": "auto",
"colorMode": "value"
},
"targets": [
{
"refId": "A",
"expr": "sum(rate(http_server_requests_total{http_route!~\"/health.*\"}[$__rate_interval]))",
"legendFormat": "",
"editorMode": "code",
"range": true
}
]
},
{
"id": 2,
"type": "stat",
"title": "5xx error ratio",
"description": "5xx / все бизнес-запросы за 5m, health исключён. 4xx не входят в numerator.",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 6,
"y": 0,
"w": 6,
"h": 4
},
"fieldConfig": {
"defaults": {
"unit": "percentunit",
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
},
{
"color": "orange",
"value": 0.02
},
{
"color": "red",
"value": 0.05
}
]
},
"color": {
"mode": "thresholds"
}
},
"overrides": []
},
"options": {
"reduceOptions": {
"calcs": [
"lastNotNull"
],
"fields": "",
"values": false
},
"orientation": "auto",
"textMode": "auto",
"colorMode": "value"
},
"targets": [
{
"refId": "A",
"expr": "sli:messenger_http_error_ratio:5m",
"legendFormat": "",
"editorMode": "code",
"range": true
}
]
},
{
"id": 3,
"type": "stat",
"title": "API p95 latency",
"description": "p95 из histogram buckets всех API-реплик, не среднее.",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 12,
"y": 0,
"w": 6,
"h": 4
},
"fieldConfig": {
"defaults": {
"unit": "s",
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
},
{
"color": "orange",
"value": 0.02
},
{
"color": "red",
"value": 0.05
}
]
},
"color": {
"mode": "thresholds"
}
},
"overrides": []
},
"options": {
"reduceOptions": {
"calcs": [
"lastNotNull"
],
"fields": "",
"values": false
},
"orientation": "auto",
"textMode": "auto",
"colorMode": "value"
},
"targets": [
{
"refId": "A",
"expr": "sli:messenger_http_latency_p95:5m",
"legendFormat": "",
"editorMode": "code",
"range": true
}
]
},
{
"id": 4,
"type": "stat",
"title": "Oldest queued job",
"description": "Возраст старейшей queued-задачи: backlog, не latency обработки.",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 18,
"y": 0,
"w": 6,
"h": 4
},
"fieldConfig": {
"defaults": {
"unit": "s",
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
},
{
"color": "orange",
"value": 0.02
},
{
"color": "red",
"value": 0.05
}
]
},
"color": {
"mode": "thresholds"
}
},
"overrides": []
},
"options": {
"reduceOptions": {
"calcs": [
"lastNotNull"
],
"fields": "",
"values": false
},
"orientation": "auto",
"textMode": "auto",
"colorMode": "value"
},
"targets": [
{
"refId": "A",
"expr": "max(queue_oldest_job_age_seconds{queue_name=\"attachment.jobs\"})",
"legendFormat": "",
"editorMode": "code",
"range": true
}
]
},
{
"id": 5,
"type": "timeseries",
"title": "API requests by route",
"description": "RPS по шаблону маршрута, а не по UUID.",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 0,
"y": 4,
"w": 12,
"h": 8
},
"fieldConfig": {
"defaults": {
"unit": "reqps",
"custom": {
"drawStyle": "line",
"lineWidth": 1,
"fillOpacity": 8
}
},
"overrides": []
},
"options": {
"legend": {
"displayMode": "list",
"placement": "bottom",
"showLegend": true
},
"tooltip": {
"mode": "multi",
"sort": "desc"
}
},
"targets": [
{
"refId": "A",
"expr": "sum by (http_route) (rate(http_server_requests_total{http_route!~\"/health.*\"}[$__rate_interval]))",
"legendFormat": "{{http_route}}",
"editorMode": "code",
"range": true
}
]
},
{
"id": 6,
"type": "timeseries",
"title": "API latency p50 / p95 / p99 (histogram)",
"description": "p50/p95/p99 считаются из histogram buckets; агрегируются все реплики.",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 12,
"y": 4,
"w": 12,
"h": 8
},
"fieldConfig": {
"defaults": {
"unit": "s",
"custom": {
"drawStyle": "line",
"lineWidth": 1,
"fillOpacity": 8
}
},
"overrides": []
},
"options": {
"legend": {
"displayMode": "list",
"placement": "bottom",
"showLegend": true
},
"tooltip": {
"mode": "multi",
"sort": "desc"
}
},
"targets": [
{
"refId": "A",
"expr": "histogram_quantile(0.50, sum by (le) (rate(http_server_duration_seconds_bucket{http_route!~\"/health.*\"}[$__rate_interval])))",
"legendFormat": "p50",
"editorMode": "code",
"range": true
},
{
"refId": "B",
"expr": "histogram_quantile(0.95, sum by (le) (rate(http_server_duration_seconds_bucket{http_route!~\"/health.*\"}[$__rate_interval])))",
"legendFormat": "p95",
"editorMode": "code",
"range": true
},
{
"refId": "C",
"expr": "histogram_quantile(0.99, sum by (le) (rate(http_server_duration_seconds_bucket{http_route!~\"/health.*\"}[$__rate_interval])))",
"legendFormat": "p99",
"editorMode": "code",
"range": true
}
]
},
{
"id": 7,
"type": "timeseries",
"title": "Jobs processed by outcome",
"description": "job type = attachment.process.v1.",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 0,
"y": 12,
"w": 8,
"h": 8
},
"fieldConfig": {
"defaults": {
"unit": "ops",
"custom": {
"drawStyle": "line",
"lineWidth": 1,
"fillOpacity": 8
}
},
"overrides": []
},
"options": {
"legend": {
"displayMode": "list",
"placement": "bottom",
"showLegend": true
},
"tooltip": {
"mode": "multi",
"sort": "desc"
}
},
"targets": [
{
"refId": "A",
"expr": "sum by (job_outcome) (rate(jobs_processed_total[$__rate_interval]))",
"legendFormat": "{{job_outcome}}",
"editorMode": "code",
"range": true
}
]
},
{
"id": 8,
"type": "timeseries",
"title": "Job duration p95",
"description": "Длительность обработки worker-ом, p95.",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 8,
"y": 12,
"w": 8,
"h": 8
},
"fieldConfig": {
"defaults": {
"unit": "s",
"custom": {
"drawStyle": "line",
"lineWidth": 1,
"fillOpacity": 8
}
},
"overrides": []
},
"options": {
"legend": {
"displayMode": "list",
"placement": "bottom",
"showLegend": true
},
"tooltip": {
"mode": "multi",
"sort": "desc"
}
},
"targets": [
{
"refId": "A",
"expr": "histogram_quantile(0.95, sum by (le, job_outcome) (rate(jobs_duration_seconds_bucket[$__rate_interval])))",
"legendFormat": "{{job_outcome}}",
"editorMode": "code",
"range": true
}
]
},
{
"id": 9,
"type": "timeseries",
"title": "Queue depth / in-flight",
"description": "queued (лежит в PostgreSQL; broker лишь доставляет ссылки).",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 16,
"y": 12,
"w": 4,
"h": 8
},
"fieldConfig": {
"defaults": {
"unit": "short",
"custom": {
"drawStyle": "line",
"lineWidth": 1,
"fillOpacity": 8
}
},
"overrides": []
},
"options": {
"legend": {
"displayMode": "list",
"placement": "bottom",
"showLegend": true
},
"tooltip": {
"mode": "multi",
"sort": "desc"
}
},
"targets": [
{
"refId": "A",
"expr": "queue_depth{queue_name=\"attachment.jobs\"}",
"legendFormat": "queued",
"editorMode": "code",
"range": true
},
{
"refId": "B",
"expr": "queue_in_flight{queue_name=\"attachment.jobs\"}",
"legendFormat": "processing",
"editorMode": "code",
"range": true
}
]
},
{
"id": 10,
"type": "timeseries",
"title": "Time to ready p95",
"description": "От устойчивого принятия upload до ready.",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 20,
"y": 12,
"w": 4,
"h": 8
},
"fieldConfig": {
"defaults": {
"unit": "s",
"custom": {
"drawStyle": "line",
"lineWidth": 1,
"fillOpacity": 8
}
},
"overrides": []
},
"options": {
"legend": {
"displayMode": "list",
"placement": "bottom",
"showLegend": true
},
"tooltip": {
"mode": "multi",
"sort": "desc"
}
},
"targets": [
{
"refId": "A",
"expr": "histogram_quantile(0.95, sum by (le) (rate(attachment_time_to_ready_seconds_bucket[$__rate_interval])))",
"legendFormat": "p95",
"editorMode": "code",
"range": true
}
]
},
{
"id": 11,
"type": "timeseries",
"title": "DB pool",
"description": "used/capacity/waiting пула SQLAlchemy по каждому процессу API.",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 0,
"y": 20,
"w": 8,
"h": 8
},
"fieldConfig": {
"defaults": {
"unit": "short",
"custom": {
"drawStyle": "line",
"lineWidth": 1,
"fillOpacity": 8
}
},
"overrides": []
},
"options": {
"legend": {
"displayMode": "list",
"placement": "bottom",
"showLegend": true
},
"tooltip": {
"mode": "multi",
"sort": "desc"
}
},
"targets": [
{
"refId": "A",
"expr": "db_pool_connections{state=\"used\"}",
"legendFormat": "used",
"editorMode": "code",
"range": true
},
{
"refId": "B",
"expr": "db_pool_connections{state=\"capacity\"}",
"legendFormat": "capacity",
"editorMode": "code",
"range": true
},
{
"refId": "C",
"expr": "db_pool_connections{state=\"waiting\"}",
"legendFormat": "waiting",
"editorMode": "code",
"range": true
}
]
},
{
"id": 12,
"type": "timeseries",
"title": "Worker busy / capacity",
"description": "Saturation worker-а: растёт backlog при нехватке слотов.",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 8,
"y": 20,
"w": 8,
"h": 8
},
"fieldConfig": {
"defaults": {
"unit": "percentunit",
"custom": {
"drawStyle": "line",
"lineWidth": 1,
"fillOpacity": 8
}
},
"overrides": []
},
"options": {
"legend": {
"displayMode": "list",
"placement": "bottom",
"showLegend": true
},
"tooltip": {
"mode": "multi",
"sort": "desc"
}
},
"targets": [
{
"refId": "A",
"expr": "worker_busy / clamp_min(worker_capacity, 1)",
"legendFormat": "busy (0..1)",
"editorMode": "code",
"range": true
}
]
},
{
"id": 13,
"type": "timeseries",
"title": "Process CPU",
"description": "CPU-секунды процесса в секунду; сравните telemetry off/on в отчёте.",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 16,
"y": 20,
"w": 8,
"h": 8
},
"fieldConfig": {
"defaults": {
"unit": "cores",
"custom": {
"drawStyle": "line",
"lineWidth": 1,
"fillOpacity": 8
}
},
"overrides": []
},
"options": {
"legend": {
"displayMode": "list",
"placement": "bottom",
"showLegend": true
},
"tooltip": {
"mode": "multi",
"sort": "desc"
}
},
"targets": [
{
"refId": "A",
"expr": "sum by (service_name) (rate(process_cpu_seconds_total[$__rate_interval]))",
"legendFormat": "{{service_name}}",
"editorMode": "code",
"range": true
}
]
},
{
"id": 14,
"type": "timeseries",
"title": "Process memory",
"description": "RSS процесса; лимит контейнера можно сравнить в таблице ниже.",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 0,
"y": 28,
"w": 12,
"h": 8
},
"fieldConfig": {
"defaults": {
"unit": "bytes",
"custom": {
"drawStyle": "line",
"lineWidth": 1,
"fillOpacity": 8
}
},
"overrides": []
},
"options": {
"legend": {
"displayMode": "list",
"placement": "bottom",
"showLegend": true
},
"tooltip": {
"mode": "multi",
"sort": "desc"
}
},
"targets": [
{
"refId": "A",
"expr": "process_memory_usage_bytes",
"legendFormat": "{{service_name}}",
"editorMode": "code",
"range": true
},
{
"refId": "B",
"expr": "process_memory_limit_bytes",
"legendFormat": "{{service_name}} limit",
"editorMode": "code",
"range": true
}
]
},
{
"id": 15,
"type": "timeseries",
"title": "Collector: spans accepted vs failed export",
"description": "Приём Collector-ом и отказы экспорта: потерянные/ограниченные spans видны здесь.",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 12,
"y": 28,
"w": 12,
"h": 8
},
"fieldConfig": {
"defaults": {
"unit": "ops",
"custom": {
"drawStyle": "line",
"lineWidth": 1,
"fillOpacity": 8
}
},
"overrides": []
},
"options": {
"legend": {
"displayMode": "list",
"placement": "bottom",
"showLegend": true
},
"tooltip": {
"mode": "multi",
"sort": "desc"
}
},
"targets": [
{
"refId": "A",
"expr": "sum(rate(otelcol_receiver_accepted_spans_total[$__rate_interval]))",
"legendFormat": "accepted",
"editorMode": "code",
"range": true
},
{
"refId": "B",
"expr": "sum(rate(otelcol_exporter_sent_spans_total[$__rate_interval]))",
"legendFormat": "exported",
"editorMode": "code",
"range": true
},
{
"refId": "C",
"expr": "sum(rate(otelcol_exporter_send_failed_spans_total[$__rate_interval]))",
"legendFormat": "failed export",
"editorMode": "code",
"range": true
}
]
},
{
"id": 16,
"type": "logs",
"title": "Structured logs (Loki)",
"description": "JSON-строки с trace_id/span_id; derived field открывает trace в Tempo.",
"datasource": {
"type": "loki",
"uid": "loki"
},
"gridPos": {
"x": 0,
"y": 36,
"w": 12,
"h": 10
},
"options": {
"showTime": true,
"sortOrder": "Descending",
"wrapLogMessage": true,
"enableLogDetails": true
},
"targets": [
{
"refId": "A",
"expr": "{service_name=~\"messenger-api|messenger-worker\"} | json",
"queryType": "range"
}
]
},
{
"id": 17,
"type": "traces",
"title": "Recent traces (Tempo)",
"description": "Реальные server/consumer spans; откройте trace и перейдите к логам по trace_id.",
"datasource": {
"type": "tempo",
"uid": "tempo"
},
"gridPos": {
"x": 12,
"y": 36,
"w": 12,
"h": 10
},
"options": {},
"targets": [
{
"refId": "A",
"queryType": "traceql",
"query": "{resource.service.name=~\"messenger-api|messenger-worker\"}"
}
]
},
{
"id": 18,
"type": "stat",
"title": "SLO availability (1h)",
"description": "Целевой SLO 99.5% за 30 дней; окно 1h для оперативного контроля.",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 0,
"y": 46,
"w": 8,
"h": 5
},
"fieldConfig": {
"defaults": {
"unit": "percentunit",
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "red",
"value": null
},
{
"color": "orange",
"value": 0.995
},
{
"color": "green",
"value": 0.999
}
]
},
"color": {
"mode": "thresholds"
}
},
"overrides": []
},
"options": {
"reduceOptions": {
"calcs": [
"lastNotNull"
],
"fields": "",
"values": false
},
"orientation": "auto",
"textMode": "auto",
"colorMode": "value"
},
"targets": [
{
"refId": "A",
"expr": "1 - (sum(increase(http_server_requests_total{http_response_status_class=\"5xx\",http_route!~\"/health.*\"}[1h])) / clamp_min(sum(increase(http_server_requests_total{http_route!~\"/health.*\"}[1h])), 1))",
"legendFormat": "",
"editorMode": "code",
"range": true
}
]
}
]
}
@@ -0,0 +1,13 @@
apiVersion: 1
providers:
- name: messenger-lab7
orgId: 1
folder: Messenger
type: file
disableDeletion: false
updateIntervalSeconds: 30
allowUiUpdates: false
options:
path: /var/lib/grafana/dashboards
foldersFromFilesStructure: false
@@ -0,0 +1,64 @@
apiVersion: 1
datasources:
- name: Prometheus
uid: prometheus
type: prometheus
access: proxy
url: https://prometheus-tls:8443
isDefault: true
jsonData:
timeInterval: 5s
tlsAuth: true
tlsAuthWithCACert: true
secureJsonData:
tlsCACert: $__file{/certs/ca.crt}
tlsClientCert: $__file{/certs/grafana-client.crt}
tlsClientKey: $__file{/certs/grafana-client.key}
- name: Loki
uid: loki
type: loki
access: proxy
url: https://loki-tls:8443
jsonData:
maxLines: 1000
tlsAuth: true
tlsAuthWithCACert: true
# JSON-строка лога содержит trace_id; derived field делает её ссылкой
# в Tempo прямо из Explore/Dashboard.
derivedFields:
- name: trace_id
matcherRegex: '"trace_id":"([a-f0-9]{32})"'
url: "$${__value.raw}"
datasourceUid: tempo
secureJsonData:
tlsCACert: $__file{/certs/ca.crt}
tlsClientCert: $__file{/certs/grafana-client.crt}
tlsClientKey: $__file{/certs/grafana-client.key}
- name: Tempo
uid: tempo
type: tempo
access: proxy
url: https://tempo-tls:8443
jsonData:
httpMethod: GET
tlsAuth: true
tlsAuthWithCACert: true
# Из trace можно перейти к логам того же trace: строка лога содержит
# trace_id, поэтому filterByTraceID ищет его в теле.
tracesToLogsV2:
datasourceUid: loki
spanStartTimeShift: "-1h"
spanEndTimeShift: "1h"
filterByTraceID: true
filterBySpanID: false
serviceMap:
datasourceUid: prometheus
nodeGraph:
enabled: true
secureJsonData:
tlsCACert: $__file{/certs/ca.crt}
tlsClientCert: $__file{/certs/grafana-client.crt}
tlsClientKey: $__file{/certs/grafana-client.key}