chore: port lab6 solution as lab7 base

This commit is contained in:
2026-11-30 16:36:13 +03:00
parent 20afc2c790
commit f736ff1da4
107 changed files with 23433 additions and 0 deletions
+428
View File
@@ -0,0 +1,428 @@
{
"uid": "messenger-overview",
"title": "Messenger overview",
"tags": ["messenger", "lab6"],
"timezone": "browser",
"schemaVersion": 39,
"version": 2,
"editable": false,
"graphTooltip": 1,
"refresh": "10s",
"time": { "from": "now-30m", "to": "now" },
"templating": { "list": [] },
"annotations": { "list": [] },
"panels": [
{ "type": "row", "title": "SLO и alerts", "id": 100, "collapsed": false, "gridPos": { "h": 1, "w": 24, "x": 0, "y": 0 } },
{
"type": "stat",
"title": "Доступность API, 1 ч (SLO ≥ 99% без 5xx)",
"id": 20,
"datasource": { "type": "prometheus", "uid": "prometheus" },
"gridPos": { "h": 5, "w": 6, "x": 0, "y": 1 },
"fieldConfig": {
"defaults": {
"unit": "percentunit", "decimals": 2,
"thresholds": { "mode": "absolute", "steps": [{ "color": "red", "value": null }, { "color": "green", "value": 0.99 }] }
},
"overrides": []
},
"options": { "reduceOptions": { "calcs": ["lastNotNull"] }, "colorMode": "background" },
"targets": [{ "refId": "A", "datasource": { "type": "prometheus", "uid": "prometheus" }, "expr": "1 - messenger:http_error_ratio:rate1h" }]
},
{
"type": "stat",
"title": "Запросы быстрее 500 мс, 1 ч (SLO ≥ 95%)",
"id": 21,
"datasource": { "type": "prometheus", "uid": "prometheus" },
"gridPos": { "h": 5, "w": 6, "x": 6, "y": 1 },
"fieldConfig": {
"defaults": {
"unit": "percentunit", "decimals": 2,
"thresholds": { "mode": "absolute", "steps": [{ "color": "red", "value": null }, { "color": "green", "value": 0.95 }] }
},
"overrides": []
},
"options": { "reduceOptions": { "calcs": ["lastNotNull"] }, "colorMode": "background" },
"targets": [{ "refId": "A", "datasource": { "type": "prometheus", "uid": "prometheus" }, "expr": "messenger:http_fast_ratio:rate1h" }]
},
{
"type": "stat",
"title": "Вложения готовы за ≤ 10 с, 1 ч (SLO ≥ 95%)",
"id": 22,
"datasource": { "type": "prometheus", "uid": "prometheus" },
"gridPos": { "h": 5, "w": 6, "x": 12, "y": 1 },
"fieldConfig": {
"defaults": {
"unit": "percentunit", "decimals": 2,
"thresholds": { "mode": "absolute", "steps": [{ "color": "red", "value": null }, { "color": "green", "value": 0.95 }] }
},
"overrides": []
},
"options": { "reduceOptions": { "calcs": ["lastNotNull"] }, "colorMode": "background" },
"targets": [{ "refId": "A", "datasource": { "type": "prometheus", "uid": "prometheus" }, "expr": "messenger:time_to_ready_fast_ratio:rate1h" }]
},
{
"type": "state-timeline",
"title": "Alerts (pending / firing)",
"id": 23,
"datasource": { "type": "prometheus", "uid": "prometheus" },
"gridPos": { "h": 5, "w": 6, "x": 18, "y": 1 },
"fieldConfig": {
"defaults": {
"color": { "mode": "thresholds" },
"thresholds": { "mode": "absolute", "steps": [{ "color": "green", "value": null }, { "color": "orange", "value": 1 }, { "color": "red", "value": 2 }] },
"mappings": [{ "type": "value", "options": { "1": { "text": "pending" }, "2": { "text": "firing" } } }]
},
"overrides": []
},
"options": { "showValue": "never", "mergeValues": true, "legend": { "showLegend": false } },
"targets": [
{
"refId": "A",
"datasource": { "type": "prometheus", "uid": "prometheus" },
"expr": "max by (alertname) (ALERTS{alertstate=\"firing\"}) * 2 or max by (alertname) (ALERTS{alertstate=\"pending\"})",
"legendFormat": "{{alertname}}"
}
]
},
{ "type": "row", "title": "API", "id": 101, "collapsed": false, "gridPos": { "h": 1, "w": 24, "x": 0, "y": 6 } },
{
"type": "timeseries",
"title": "RPS по маршрутам (без health)",
"id": 1,
"datasource": { "type": "prometheus", "uid": "prometheus" },
"gridPos": { "h": 8, "w": 12, "x": 0, "y": 7 },
"fieldConfig": { "defaults": { "unit": "reqps" }, "overrides": [] },
"options": { "legend": { "displayMode": "table", "placement": "right", "calcs": ["lastNotNull"] } },
"targets": [
{
"refId": "A",
"datasource": { "type": "prometheus", "uid": "prometheus" },
"expr": "sum by (http_request_method, http_route) (rate(http_server_requests_total{job=\"messenger-api\", http_route!~\"/health.*\"}[$__rate_interval]))",
"legendFormat": "{{http_request_method}} {{http_route}}"
}
]
},
{
"type": "timeseries",
"title": "Ответы по классам статуса (без health)",
"id": 2,
"datasource": { "type": "prometheus", "uid": "prometheus" },
"gridPos": { "h": 8, "w": 12, "x": 12, "y": 7 },
"fieldConfig": { "defaults": { "unit": "reqps" }, "overrides": [] },
"targets": [
{
"refId": "A",
"datasource": { "type": "prometheus", "uid": "prometheus" },
"expr": "sum by (http_response_status_class) (rate(http_server_requests_total{job=\"messenger-api\", http_route!~\"/health.*\"}[$__rate_interval]))",
"legendFormat": "{{http_response_status_class}}"
}
]
},
{
"type": "timeseries",
"title": "Доля 5xx среди бизнес-запросов (окно 5m, порог alert 5%)",
"id": 3,
"datasource": { "type": "prometheus", "uid": "prometheus" },
"gridPos": { "h": 8, "w": 8, "x": 0, "y": 15 },
"fieldConfig": {
"defaults": {
"unit": "percentunit",
"min": 0,
"thresholds": { "mode": "absolute", "steps": [{ "color": "green", "value": null }, { "color": "red", "value": 0.05 }] },
"custom": { "thresholdsStyle": { "mode": "line" } }
},
"overrides": []
},
"targets": [
{ "refId": "A", "datasource": { "type": "prometheus", "uid": "prometheus" }, "expr": "messenger:http_error_ratio:rate5m", "legendFormat": "5xx ratio" }
]
},
{
"type": "timeseries",
"title": "Длительность API p50 / p95 / p99 (все реплики, без health)",
"id": 4,
"datasource": { "type": "prometheus", "uid": "prometheus" },
"gridPos": { "h": 8, "w": 8, "x": 8, "y": 15 },
"fieldConfig": { "defaults": { "unit": "s", "min": 0 }, "overrides": [] },
"targets": [
{
"refId": "A",
"datasource": { "type": "prometheus", "uid": "prometheus" },
"expr": "histogram_quantile(0.50, sum by (le) (rate(http_server_request_duration_seconds_bucket{job=\"messenger-api\", http_route!~\"/health.*\"}[$__rate_interval])))",
"legendFormat": "p50"
},
{
"refId": "B",
"datasource": { "type": "prometheus", "uid": "prometheus" },
"expr": "histogram_quantile(0.95, sum by (le) (rate(http_server_request_duration_seconds_bucket{job=\"messenger-api\", http_route!~\"/health.*\"}[$__rate_interval])))",
"legendFormat": "p95"
},
{
"refId": "C",
"datasource": { "type": "prometheus", "uid": "prometheus" },
"expr": "histogram_quantile(0.99, sum by (le) (rate(http_server_request_duration_seconds_bucket{job=\"messenger-api\", http_route!~\"/health.*\"}[$__rate_interval])))",
"legendFormat": "p99"
}
]
},
{
"type": "timeseries",
"title": "p95 по маршрутам",
"id": 5,
"datasource": { "type": "prometheus", "uid": "prometheus" },
"gridPos": { "h": 8, "w": 8, "x": 16, "y": 15 },
"fieldConfig": { "defaults": { "unit": "s", "min": 0 }, "overrides": [] },
"targets": [
{
"refId": "A",
"datasource": { "type": "prometheus", "uid": "prometheus" },
"expr": "histogram_quantile(0.95, sum by (le, http_request_method, http_route) (rate(http_server_request_duration_seconds_bucket{job=\"messenger-api\", http_route!~\"/health.*\"}[$__rate_interval])))",
"legendFormat": "{{http_request_method}} {{http_route}}"
}
]
},
{ "type": "row", "title": "Очередь и worker", "id": 102, "collapsed": false, "gridPos": { "h": 1, "w": 24, "x": 0, "y": 23 } },
{
"type": "timeseries",
"title": "Глубина очереди attachment.jobs (из attachment_jobs)",
"id": 30,
"datasource": { "type": "prometheus", "uid": "prometheus" },
"gridPos": { "h": 8, "w": 8, "x": 0, "y": 24 },
"fieldConfig": { "defaults": { "unit": "short", "min": 0 }, "overrides": [] },
"targets": [
{
"refId": "A",
"datasource": { "type": "prometheus", "uid": "prometheus" },
"expr": "max by (state) (jobs_queue_depth{job=\"messenger-relay\"})",
"legendFormat": "{{state}}"
}
]
},
{
"type": "timeseries",
"title": "Возраст старейшего готового задания (порог alert 60 s)",
"id": 31,
"datasource": { "type": "prometheus", "uid": "prometheus" },
"gridPos": { "h": 8, "w": 8, "x": 8, "y": 24 },
"fieldConfig": {
"defaults": {
"unit": "s", "min": 0,
"thresholds": { "mode": "absolute", "steps": [{ "color": "green", "value": null }, { "color": "red", "value": 60 }] },
"custom": { "thresholdsStyle": { "mode": "line" } }
},
"overrides": []
},
"targets": [
{ "refId": "A", "datasource": { "type": "prometheus", "uid": "prometheus" }, "expr": "messenger:jobs_queue_oldest_age:max", "legendFormat": "oldest due job age" }
]
},
{
"type": "timeseries",
"title": "Worker: занято / ёмкость",
"id": 32,
"datasource": { "type": "prometheus", "uid": "prometheus" },
"gridPos": { "h": 8, "w": 8, "x": 16, "y": 24 },
"fieldConfig": { "defaults": { "unit": "short", "min": 0 }, "overrides": [] },
"targets": [
{ "refId": "A", "datasource": { "type": "prometheus", "uid": "prometheus" }, "expr": "sum(worker_jobs_busy{job=\"messenger-worker\"})", "legendFormat": "busy" },
{ "refId": "B", "datasource": { "type": "prometheus", "uid": "prometheus" }, "expr": "sum(worker_jobs_capacity{job=\"messenger-worker\"})", "legendFormat": "capacity" },
{ "refId": "C", "datasource": { "type": "prometheus", "uid": "prometheus" }, "expr": "sum(avg_over_time(worker_jobs_busy{job=\"messenger-worker\"}[5m])) / sum(worker_jobs_capacity{job=\"messenger-worker\"})", "legendFormat": "saturation 5m" }
]
},
{
"type": "timeseries",
"title": "Задания по исходу (в секунду)",
"id": 6,
"datasource": { "type": "prometheus", "uid": "prometheus" },
"gridPos": { "h": 8, "w": 8, "x": 0, "y": 32 },
"fieldConfig": { "defaults": { "unit": "ops" }, "overrides": [] },
"targets": [
{
"refId": "A",
"datasource": { "type": "prometheus", "uid": "prometheus" },
"expr": "sum by (job_type, outcome) (rate(jobs_processed_total{job=\"messenger-worker\"}[$__rate_interval]))",
"legendFormat": "{{job_type}} {{outcome}}"
}
]
},
{
"type": "timeseries",
"title": "Длительность обработки задания p50 / p95 / p99",
"id": 7,
"datasource": { "type": "prometheus", "uid": "prometheus" },
"gridPos": { "h": 8, "w": 8, "x": 8, "y": 32 },
"fieldConfig": { "defaults": { "unit": "s", "min": 0 }, "overrides": [] },
"targets": [
{
"refId": "A",
"datasource": { "type": "prometheus", "uid": "prometheus" },
"expr": "histogram_quantile(0.50, sum by (le) (rate(jobs_duration_seconds_bucket{job=\"messenger-worker\", outcome=\"success\"}[$__rate_interval])))",
"legendFormat": "p50 success"
},
{
"refId": "B",
"datasource": { "type": "prometheus", "uid": "prometheus" },
"expr": "histogram_quantile(0.95, sum by (le) (rate(jobs_duration_seconds_bucket{job=\"messenger-worker\", outcome=\"success\"}[$__rate_interval])))",
"legendFormat": "p95 success"
},
{
"refId": "C",
"datasource": { "type": "prometheus", "uid": "prometheus" },
"expr": "histogram_quantile(0.99, sum by (le) (rate(jobs_duration_seconds_bucket{job=\"messenger-worker\", outcome=\"success\"}[$__rate_interval])))",
"legendFormat": "p99 success"
}
]
},
{
"type": "timeseries",
"title": "Время от upload до ready p50 / p95 / p99",
"id": 33,
"datasource": { "type": "prometheus", "uid": "prometheus" },
"gridPos": { "h": 8, "w": 8, "x": 16, "y": 32 },
"fieldConfig": { "defaults": { "unit": "s", "min": 0 }, "overrides": [] },
"targets": [
{
"refId": "A",
"datasource": { "type": "prometheus", "uid": "prometheus" },
"expr": "histogram_quantile(0.50, sum by (le) (rate(attachments_time_to_ready_seconds_bucket{job=\"messenger-worker\"}[$__rate_interval])))",
"legendFormat": "p50"
},
{
"refId": "B",
"datasource": { "type": "prometheus", "uid": "prometheus" },
"expr": "histogram_quantile(0.95, sum by (le) (rate(attachments_time_to_ready_seconds_bucket{job=\"messenger-worker\"}[$__rate_interval])))",
"legendFormat": "p95"
},
{
"refId": "C",
"datasource": { "type": "prometheus", "uid": "prometheus" },
"expr": "histogram_quantile(0.99, sum by (le) (rate(attachments_time_to_ready_seconds_bucket{job=\"messenger-worker\"}[$__rate_interval])))",
"legendFormat": "p99"
}
]
},
{ "type": "row", "title": "БД и ресурсы", "id": 103, "collapsed": false, "gridPos": { "h": 1, "w": 24, "x": 0, "y": 40 } },
{
"type": "timeseries",
"title": "Пул БД: занято / ожидают соединения",
"id": 40,
"datasource": { "type": "prometheus", "uid": "prometheus" },
"gridPos": { "h": 8, "w": 8, "x": 0, "y": 41 },
"fieldConfig": { "defaults": { "unit": "short", "min": 0 }, "overrides": [] },
"targets": [
{ "refId": "A", "datasource": { "type": "prometheus", "uid": "prometheus" }, "expr": "sum by (job) (db_client_connection_count{db_client_connection_state=\"used\"})", "legendFormat": "{{job}} used" },
{ "refId": "B", "datasource": { "type": "prometheus", "uid": "prometheus" }, "expr": "sum by (job) (db_client_connection_pending_requests)", "legendFormat": "{{job}} waiting" },
{ "refId": "C", "datasource": { "type": "prometheus", "uid": "prometheus" }, "expr": "sum by (job) (db_client_connection_max)", "legendFormat": "{{job}} max" }
]
},
{
"type": "timeseries",
"title": "CPU процессов (доля ядра)",
"id": 41,
"datasource": { "type": "prometheus", "uid": "prometheus" },
"gridPos": { "h": 8, "w": 8, "x": 8, "y": 41 },
"fieldConfig": { "defaults": { "unit": "percentunit", "min": 0 }, "overrides": [] },
"targets": [
{
"refId": "A",
"datasource": { "type": "prometheus", "uid": "prometheus" },
"expr": "sum by (job, instance) (rate(process_cpu_time_seconds_total{job=~\"messenger-.+\"}[$__rate_interval]))",
"legendFormat": "{{job}} {{instance}}"
},
{
"refId": "B",
"datasource": { "type": "prometheus", "uid": "prometheus" },
"expr": "rate(otelcol_process_cpu_seconds{job=\"otel-collector\"}[$__rate_interval])",
"legendFormat": "otel-collector"
}
]
},
{
"type": "timeseries",
"title": "RAM процессов (RSS)",
"id": 42,
"datasource": { "type": "prometheus", "uid": "prometheus" },
"gridPos": { "h": 8, "w": 8, "x": 16, "y": 41 },
"fieldConfig": { "defaults": { "unit": "bytes", "min": 0 }, "overrides": [] },
"targets": [
{ "refId": "A", "datasource": { "type": "prometheus", "uid": "prometheus" }, "expr": "process_memory_usage_bytes{job=~\"messenger-.+\"}", "legendFormat": "{{job}} {{instance}}" },
{ "refId": "B", "datasource": { "type": "prometheus", "uid": "prometheus" }, "expr": "otelcol_process_memory_rss{job=\"otel-collector\"}", "legendFormat": "otel-collector" }
]
},
{ "type": "row", "title": "Конвейер телеметрии (Collector)", "id": 104, "collapsed": false, "gridPos": { "h": 1, "w": 24, "x": 0, "y": 49 } },
{
"type": "timeseries",
"title": "Принято / отправлено / ошибки отправки (в секунду)",
"id": 50,
"datasource": { "type": "prometheus", "uid": "prometheus" },
"gridPos": { "h": 8, "w": 12, "x": 0, "y": 50 },
"fieldConfig": { "defaults": { "unit": "short", "min": 0 }, "overrides": [] },
"targets": [
{ "refId": "A", "datasource": { "type": "prometheus", "uid": "prometheus" }, "expr": "sum(rate(otelcol_receiver_accepted_spans[$__rate_interval]))", "legendFormat": "spans accepted" },
{ "refId": "B", "datasource": { "type": "prometheus", "uid": "prometheus" }, "expr": "sum(rate(otelcol_exporter_sent_spans[$__rate_interval]))", "legendFormat": "spans sent" },
{ "refId": "C", "datasource": { "type": "prometheus", "uid": "prometheus" }, "expr": "sum(rate(otelcol_exporter_send_failed_spans[$__rate_interval])) or vector(0)", "legendFormat": "spans failed" },
{ "refId": "D", "datasource": { "type": "prometheus", "uid": "prometheus" }, "expr": "sum(rate(otelcol_exporter_sent_log_records[$__rate_interval]))", "legendFormat": "logs sent" },
{ "refId": "E", "datasource": { "type": "prometheus", "uid": "prometheus" }, "expr": "sum(rate(otelcol_exporter_send_failed_log_records[$__rate_interval])) or vector(0)", "legendFormat": "logs failed" },
{ "refId": "F", "datasource": { "type": "prometheus", "uid": "prometheus" }, "expr": "sum(rate(otelcol_receiver_refused_spans[$__rate_interval])) + sum(rate(otelcol_receiver_refused_log_records[$__rate_interval])) or vector(0)", "legendFormat": "refused (memory_limiter)" }
]
},
{
"type": "timeseries",
"title": "Очередь exporter (ограничена queue_size)",
"id": 51,
"datasource": { "type": "prometheus", "uid": "prometheus" },
"gridPos": { "h": 8, "w": 12, "x": 12, "y": 50 },
"fieldConfig": { "defaults": { "unit": "short", "min": 0 }, "overrides": [] },
"targets": [
{ "refId": "A", "datasource": { "type": "prometheus", "uid": "prometheus" }, "expr": "max by (exporter) (otelcol_exporter_queue_size)", "legendFormat": "{{exporter}} size" },
{ "refId": "B", "datasource": { "type": "prometheus", "uid": "prometheus" }, "expr": "max(otelcol_exporter_queue_capacity)", "legendFormat": "capacity" }
]
},
{ "type": "row", "title": "Логи и трассы", "id": 105, "collapsed": false, "gridPos": { "h": 1, "w": 24, "x": 0, "y": 58 } },
{
"type": "logs",
"title": "Логи API и worker (WARN и выше)",
"id": 8,
"datasource": { "type": "loki", "uid": "loki" },
"gridPos": { "h": 10, "w": 12, "x": 0, "y": 59 },
"options": { "showTime": true, "wrapLogMessage": true, "sortOrder": "Descending", "enableLogDetails": true },
"targets": [
{ "refId": "A", "datasource": { "type": "loki", "uid": "loki" }, "expr": "{service_name=~\"messenger-.+\"} | severity_text=~\"WARN|ERROR|FATAL\"" }
]
},
{
"type": "logs",
"title": "Все логи (http.request, job.handled, …)",
"id": 9,
"datasource": { "type": "loki", "uid": "loki" },
"gridPos": { "h": 10, "w": 12, "x": 12, "y": 59 },
"options": { "showTime": true, "wrapLogMessage": true, "sortOrder": "Descending", "enableLogDetails": true },
"targets": [
{ "refId": "A", "datasource": { "type": "loki", "uid": "loki" }, "expr": "{service_name=~\"messenger-.+\"}" }
]
},
{
"type": "table",
"title": "Последние трассы (HTTP server и consumer spans)",
"id": 10,
"datasource": { "type": "tempo", "uid": "tempo" },
"gridPos": { "h": 10, "w": 24, "x": 0, "y": 69 },
"targets": [
{
"refId": "A",
"datasource": { "type": "tempo", "uid": "tempo" },
"queryType": "traceql",
"query": "{resource.service.name=~\"messenger-.+\" && (kind=server || kind=consumer)}",
"limit": 20,
"tableType": "traces"
}
]
}
]
}
@@ -0,0 +1,10 @@
apiVersion: 1
providers:
- name: messenger
folder: Messenger
type: file
disableDeletion: true
allowUiUpdates: false
options:
path: /var/lib/grafana/dashboards
@@ -0,0 +1,45 @@
apiVersion: 1
datasources:
- name: Prometheus
uid: prometheus
type: prometheus
access: proxy
url: http://prometheus:9090
isDefault: true
jsonData:
httpMethod: POST
exemplarTraceIdDestinations:
- name: trace_id
datasourceUid: tempo
- name: Loki
uid: loki
type: loki
access: proxy
url: http://loki:3100
jsonData:
derivedFields:
- name: trace_id
matcherType: label
matcherRegex: trace_id
url: "$${__value.raw}"
datasourceUid: tempo
- name: Tempo
uid: tempo
type: tempo
access: proxy
url: http://tempo:3200
jsonData:
tracesToLogsV2:
datasourceUid: loki
spanStartTimeShift: -5m
spanEndTimeShift: 5m
filterByTraceID: false
customQuery: true
query: '{service_name=~".+"} | trace_id="$${__span.traceId}"'
tracesToMetrics:
datasourceUid: prometheus
serviceMap:
datasourceUid: prometheus
nodeGraph:
enabled: true
+43
View File
@@ -0,0 +1,43 @@
global
log stdout format raw local0 info
maxconn 2000
defaults
mode http
log global
option httplog
option dontlognull
timeout connect 1s
timeout client 30s
timeout server 10s
timeout http-request 10s
timeout queue 5s
timeout check 1s
retries 2
option redispatch 1
retry-on conn-failure
unique-id-format %[uuid()]
http-error status 502 content-type application/json hdr X-Request-Id "%[unique-id]" lf-string "{\"error\":{\"code\":\"unavailable\",\"message\":\"bad gateway\",\"request_id\":\"%[unique-id]\"}}"
http-error status 503 content-type application/json hdr X-Request-Id "%[unique-id]" lf-string "{\"error\":{\"code\":\"unavailable\",\"message\":\"no API replica available\",\"request_id\":\"%[unique-id]\"}}"
http-error status 504 content-type application/json hdr X-Request-Id "%[unique-id]" lf-string "{\"error\":{\"code\":\"unavailable\",\"message\":\"gateway timeout\",\"request_id\":\"%[unique-id]\"}}"
resolvers docker
nameserver dns 127.0.0.11:53
resolve_retries 3
timeout resolve 1s
timeout retry 1s
hold valid 5s
hold obsolete 5s
accepted_payload_size 8192
frontend public
bind :8080
default_backend api
backend api
balance roundrobin
http-request set-timeout server 60s if { method POST } { path_reg ^/api/v1/chats/[^/]+/attachments$ }
option httpchk GET /health/core
http-check expect status 200
default-server check inter 1s fall 2 rise 2 resolvers docker resolve-prefer ipv4 init-addr none
server-template api 1-4 api:8080
+43
View File
@@ -0,0 +1,43 @@
auth_enabled: false
server:
http_listen_address: 0.0.0.0
http_listen_port: 3100
grpc_listen_port: 9096
log_level: warn
common:
instance_addr: 127.0.0.1
path_prefix: /loki
replication_factor: 1
storage:
filesystem:
chunks_directory: /loki/chunks
rules_directory: /loki/rules
ring:
kvstore:
store: inmemory
schema_config:
configs:
- from: 2026-01-01
store: tsdb
object_store: filesystem
schema: v13
index:
prefix: index_
period: 24h
limits_config:
allow_structured_metadata: true
retention_period: 168h
ingestion_rate_mb: 8
ingestion_burst_size_mb: 16
compactor:
working_directory: /loki/compactor
retention_enabled: true
delete_request_store: filesystem
analytics:
reporting_enabled: false
+85
View File
@@ -0,0 +1,85 @@
extensions:
health_check:
endpoint: 0.0.0.0:13133
receivers:
otlp:
protocols:
http:
endpoint: 0.0.0.0:4318
max_request_body_size: 4194304
processors:
memory_limiter:
check_interval: 1s
limit_mib: 160
spike_limit_mib: 40
batch:
send_batch_size: 512
send_batch_max_size: 1024
timeout: 2s
exporters:
otlphttp/prometheus:
endpoint: http://prometheus:9090/api/v1/otlp
timeout: 5s
sending_queue:
enabled: true
num_consumers: 2
queue_size: 200
retry_on_failure:
enabled: true
initial_interval: 1s
max_interval: 10s
max_elapsed_time: 60s
otlphttp/loki:
endpoint: http://loki:3100/otlp
timeout: 5s
sending_queue:
enabled: true
num_consumers: 2
queue_size: 200
retry_on_failure:
enabled: true
initial_interval: 1s
max_interval: 10s
max_elapsed_time: 60s
otlphttp/tempo:
endpoint: http://tempo:4318
timeout: 5s
sending_queue:
enabled: true
num_consumers: 2
queue_size: 200
retry_on_failure:
enabled: true
initial_interval: 1s
max_interval: 10s
max_elapsed_time: 60s
service:
extensions: [health_check]
telemetry:
logs:
level: warn
metrics:
level: normal
readers:
- pull:
exporter:
prometheus:
host: 0.0.0.0
port: 8888
pipelines:
metrics:
receivers: [otlp]
processors: [memory_limiter, batch]
exporters: [otlphttp/prometheus]
logs:
receivers: [otlp]
processors: [memory_limiter, batch]
exporters: [otlphttp/loki]
traces:
receivers: [otlp]
processors: [memory_limiter, batch]
exporters: [otlphttp/tempo]
+23
View File
@@ -0,0 +1,23 @@
global:
scrape_interval: 15s
evaluation_interval: 15s
otlp:
promote_resource_attributes:
- deployment.environment.name
- service.version
storage:
tsdb:
out_of_order_time_window: 30m
rule_files:
- /etc/prometheus/rules/*.yml
scrape_configs:
- job_name: otel-collector
static_configs:
- targets: ["otel-collector:8888"]
- job_name: prometheus
static_configs:
- targets: ["localhost:9090"]
+77
View File
@@ -0,0 +1,77 @@
groups:
- name: messenger-sli
interval: 15s
rules:
- record: messenger:http_requests:rate5m
expr: sum(rate(http_server_requests_total{job="messenger-api", http_route!~"/health.*"}[5m]))
- record: messenger:http_errors:rate5m
expr: sum(rate(http_server_requests_total{job="messenger-api", http_route!~"/health.*", http_response_status_class="5xx"}[5m])) or vector(0)
- record: messenger:http_error_ratio:rate5m
expr: messenger:http_errors:rate5m / messenger:http_requests:rate5m
- record: messenger:http_error_ratio:rate1h
expr: |
(sum(rate(http_server_requests_total{job="messenger-api", http_route!~"/health.*", http_response_status_class="5xx"}[1h])) or vector(0))
/ sum(rate(http_server_requests_total{job="messenger-api", http_route!~"/health.*"}[1h]))
- record: messenger:http_latency_p95:rate5m
expr: histogram_quantile(0.95, sum by (le) (rate(http_server_request_duration_seconds_bucket{job="messenger-api", http_route!~"/health.*"}[5m])))
- record: messenger:http_fast_ratio:rate1h
expr: |
sum(rate(http_server_request_duration_seconds_bucket{job="messenger-api", http_route!~"/health.*", le="0.5"}[1h]))
/ sum(rate(http_server_request_duration_seconds_count{job="messenger-api", http_route!~"/health.*"}[1h]))
- record: messenger:time_to_ready_fast_ratio:rate1h
expr: |
sum(rate(attachments_time_to_ready_seconds_bucket{job="messenger-worker", le="10"}[1h]))
/ sum(rate(attachments_time_to_ready_seconds_count{job="messenger-worker"}[1h]))
- record: messenger:jobs_queue_oldest_age:max
expr: max(jobs_queue_oldest_age_seconds{job="messenger-relay"})
- name: messenger-alerts
rules:
- alert: MessengerHighErrorRate
expr: messenger:http_error_ratio:rate5m > 0.05 and messenger:http_requests:rate5m > 0.05
for: 1m
labels:
severity: critical
annotations:
summary: "Доля 5xx бизнес-запросов API {{ $value | humanizePercentage }} за 5 минут (порог 5%)"
description: "SLO доступности 99% за 1 ч: при 5% ошибок бюджет сгорает в 5 раз быстрее допустимого. Health-запросы не учитываются."
runbook: "docs/runbooks.md#messengerhigherrorrate"
- alert: MessengerApiNotReady
expr: sum(increase(http_server_requests_total{job="messenger-api", http_route="/health/core", http_response_status_class="5xx"}[1m])) > 10
for: 30s
labels:
severity: critical
annotations:
summary: "Реплики API отвечают 503 на /health/core — HAProxy выводит их из балансировки"
description: "Обычно недоступна БД или реплика останавливается. Пока все реплики не готовы, клиенты получают 503 от LB, и такие ответы не попадают в метрики API (MessengerHighErrorRate их не видит)."
runbook: "docs/runbooks.md#messengerapinotready"
- alert: MessengerJobQueueLag
expr: messenger:jobs_queue_oldest_age:max > 60
for: 1m
labels:
severity: warning
annotations:
summary: "Старейшее готовое к обработке задание ждёт {{ $value | humanizeDuration }} (порог 60 s)"
description: "Задания принимаются, но не обрабатываются: worker остановлен, не справляется или не получает сообщения из брокера."
runbook: "docs/runbooks.md#messengerjobqueuelag"
- alert: MessengerSlowApi
expr: messenger:http_latency_p95:rate5m > 1 and messenger:http_requests:rate5m > 0.05
for: 2m
labels:
severity: warning
annotations:
summary: "p95 бизнес-запросов API {{ $value | humanizeDuration }} за 5 минут (порог 1 s)"
description: "Проверьте ожидание пула БД (db_client_connection_pending_requests) и spans prisma:engine:db_query в трассах медленных запросов."
runbook: "docs/runbooks.md#messengerslowapi"
- alert: TelemetryExportFailing
expr: |
sum(rate(otelcol_exporter_send_failed_spans[2m])) + sum(rate(otelcol_exporter_send_failed_log_records[2m]))
+ sum(rate(otelcol_exporter_send_failed_metric_points[2m])) > 0
or max(otelcol_exporter_queue_size / otelcol_exporter_queue_capacity) > 0.5
for: 1m
labels:
severity: warning
annotations:
summary: "Collector не может доставить телеметрию в хранилище"
description: "Растёт очередь exporter или есть отказы отправки. Мессенджер работает, но часть трасс/логов теряется после заполнения ограниченной очереди."
runbook: "docs/runbooks.md#telemetryexportfailing"
+31
View File
@@ -0,0 +1,31 @@
stream_over_http_enabled: true
server:
http_listen_address: 0.0.0.0
http_listen_port: 3200
log_level: warn
distributor:
receivers:
otlp:
protocols:
http:
endpoint: 0.0.0.0:4318
ingester:
max_block_duration: 5m
compactor:
compaction:
block_retention: 168h
storage:
trace:
backend: local
wal:
path: /var/tempo/wal
local:
path: /var/tempo/blocks
usage_report:
reporting_enabled: false