Complete lab7 grade 4 implementation
Skeleton contracts / contracts (pull_request) Canceled after 0s
Skeleton contracts / contracts (pull_request) Canceled after 0s
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
apiVersion: 1
|
||||
providers:
|
||||
- name: messenger
|
||||
folder: Messenger
|
||||
type: file
|
||||
disableDeletion: true
|
||||
options:
|
||||
path: /etc/grafana/provisioning/dashboards
|
||||
@@ -0,0 +1,583 @@
|
||||
{
|
||||
"uid": "messenger-lab6",
|
||||
"title": "Messenger — API, worker, очередь",
|
||||
"schemaVersion": 39,
|
||||
"version": 2,
|
||||
"editable": true,
|
||||
"time": {
|
||||
"from": "now-30m",
|
||||
"to": "now"
|
||||
},
|
||||
"refresh": "10s",
|
||||
"tags": [
|
||||
"messenger",
|
||||
"lab6"
|
||||
],
|
||||
"panels": [
|
||||
{
|
||||
"id": 1,
|
||||
"type": "timeseries",
|
||||
"title": "API: запросы/с по маршруту и классу статуса",
|
||||
"description": "http.server.request.duration (count), все реплики; health исключён",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"gridPos": {
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"w": 12,
|
||||
"h": 8
|
||||
},
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"unit": "reqps"
|
||||
},
|
||||
"overrides": []
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"refId": "A",
|
||||
"expr": "sum by (http_route, class) (label_replace(rate(http_server_request_duration_seconds_count{job=\"messenger-api\",http_route!~\"/health.*\"}[1m]), \"class\", \"${1}xx\", \"http_response_status_code\", \"([0-9]).*\"))",
|
||||
"legendFormat": "{{http_route}} {{class}}",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"type": "timeseries",
|
||||
"title": "API: доля 5xx (без health)",
|
||||
"description": "numerator: ответы 5xx; denominator: все бизнес-запросы, кроме /health/*",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"gridPos": {
|
||||
"x": 12,
|
||||
"y": 0,
|
||||
"w": 12,
|
||||
"h": 8
|
||||
},
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"unit": "percentunit"
|
||||
},
|
||||
"overrides": []
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"refId": "A",
|
||||
"expr": "sum(rate(http_server_request_duration_seconds_count{job=\"messenger-api\",http_route!~\"/health.*\",http_response_status_code=~\"5..\"}[5m])) / sum(rate(http_server_request_duration_seconds_count{job=\"messenger-api\",http_route!~\"/health.*\"}[5m]))",
|
||||
"legendFormat": "5xx / все",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"type": "timeseries",
|
||||
"title": "API: длительность p50/p95/p99 (из histogram, все реплики)",
|
||||
"description": "",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"gridPos": {
|
||||
"x": 0,
|
||||
"y": 8,
|
||||
"w": 12,
|
||||
"h": 8
|
||||
},
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"unit": "s"
|
||||
},
|
||||
"overrides": []
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"refId": "A",
|
||||
"expr": "histogram_quantile(0.5, sum by (le) (rate(http_server_request_duration_seconds_bucket{job=\"messenger-api\",http_route!~\"/health.*\"}[5m])))",
|
||||
"legendFormat": "p50",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
}
|
||||
},
|
||||
{
|
||||
"refId": "B",
|
||||
"expr": "histogram_quantile(0.95, sum by (le) (rate(http_server_request_duration_seconds_bucket{job=\"messenger-api\",http_route!~\"/health.*\"}[5m])))",
|
||||
"legendFormat": "p95",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
}
|
||||
},
|
||||
{
|
||||
"refId": "C",
|
||||
"expr": "histogram_quantile(0.99, sum by (le) (rate(http_server_request_duration_seconds_bucket{job=\"messenger-api\",http_route!~\"/health.*\"}[5m])))",
|
||||
"legendFormat": "p99",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 4,
|
||||
"type": "timeseries",
|
||||
"title": "Worker: задания по исходу",
|
||||
"description": "messenger.jobs.processed: done / retry / failed / duplicate / fenced",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"gridPos": {
|
||||
"x": 12,
|
||||
"y": 8,
|
||||
"w": 12,
|
||||
"h": 8
|
||||
},
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"unit": "ops"
|
||||
},
|
||||
"overrides": []
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"refId": "A",
|
||||
"expr": "sum by (outcome) (rate(messenger_jobs_processed_total{job=\"messenger-worker\"}[5m]))",
|
||||
"legendFormat": "{{outcome}}",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 5,
|
||||
"type": "timeseries",
|
||||
"title": "Worker: длительность попытки p50/p95/p99",
|
||||
"description": "",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"gridPos": {
|
||||
"x": 0,
|
||||
"y": 16,
|
||||
"w": 12,
|
||||
"h": 8
|
||||
},
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"unit": "s"
|
||||
},
|
||||
"overrides": []
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"refId": "A",
|
||||
"expr": "histogram_quantile(0.5, sum by (le) (rate(messenger_job_duration_seconds_bucket{job=\"messenger-worker\"}[5m])))",
|
||||
"legendFormat": "p50",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
}
|
||||
},
|
||||
{
|
||||
"refId": "B",
|
||||
"expr": "histogram_quantile(0.95, sum by (le) (rate(messenger_job_duration_seconds_bucket{job=\"messenger-worker\"}[5m])))",
|
||||
"legendFormat": "p95",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
}
|
||||
},
|
||||
{
|
||||
"refId": "C",
|
||||
"expr": "histogram_quantile(0.99, sum by (le) (rate(messenger_job_duration_seconds_bucket{job=\"messenger-worker\"}[5m])))",
|
||||
"legendFormat": "p99",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 6,
|
||||
"type": "timeseries",
|
||||
"title": "Очередь: глубина и возраст самого старого задания",
|
||||
"description": "",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"gridPos": {
|
||||
"x": 12,
|
||||
"y": 16,
|
||||
"w": 12,
|
||||
"h": 8
|
||||
},
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"unit": "short"
|
||||
},
|
||||
"overrides": []
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"refId": "A",
|
||||
"expr": "max(messenger_queue_depth)",
|
||||
"legendFormat": "queued, шт",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
}
|
||||
},
|
||||
{
|
||||
"refId": "B",
|
||||
"expr": "max(messenger_queue_oldest_age_seconds)",
|
||||
"legendFormat": "oldest age, с",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 7,
|
||||
"type": "timeseries",
|
||||
"title": "Worker: занятость (busy / capacity)",
|
||||
"description": "",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"gridPos": {
|
||||
"x": 0,
|
||||
"y": 24,
|
||||
"w": 12,
|
||||
"h": 8
|
||||
},
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"unit": "percentunit"
|
||||
},
|
||||
"overrides": []
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"refId": "A",
|
||||
"expr": "sum(messenger_worker_busy{job=\"messenger-worker\"}) / sum(messenger_worker_capacity{job=\"messenger-worker\"})",
|
||||
"legendFormat": "busy / capacity",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 8,
|
||||
"type": "timeseries",
|
||||
"title": "Время до ready p50/p95 (от 202 до ready)",
|
||||
"description": "",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"gridPos": {
|
||||
"x": 12,
|
||||
"y": 24,
|
||||
"w": 12,
|
||||
"h": 8
|
||||
},
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"unit": "s"
|
||||
},
|
||||
"overrides": []
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"refId": "A",
|
||||
"expr": "histogram_quantile(0.5, sum by (le) (rate(messenger_attachment_time_to_ready_seconds_bucket{job=\"messenger-worker\"}[5m])))",
|
||||
"legendFormat": "p50",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
}
|
||||
},
|
||||
{
|
||||
"refId": "B",
|
||||
"expr": "histogram_quantile(0.95, sum by (le) (rate(messenger_attachment_time_to_ready_seconds_bucket{job=\"messenger-worker\"}[5m])))",
|
||||
"legendFormat": "p95",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 9,
|
||||
"type": "timeseries",
|
||||
"title": "Пул соединений БД (Hikari)",
|
||||
"description": "",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"gridPos": {
|
||||
"x": 0,
|
||||
"y": 32,
|
||||
"w": 12,
|
||||
"h": 8
|
||||
},
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"unit": "short"
|
||||
},
|
||||
"overrides": []
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"refId": "A",
|
||||
"expr": "sum by (job, state) (db_client_connections_usage)",
|
||||
"legendFormat": "{{job}} {{state}}",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
}
|
||||
},
|
||||
{
|
||||
"refId": "B",
|
||||
"expr": "sum by (job) (db_client_connections_pending_requests)",
|
||||
"legendFormat": "{{job}} waiting",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 10,
|
||||
"type": "timeseries",
|
||||
"title": "JVM: CPU и память",
|
||||
"description": "",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"gridPos": {
|
||||
"x": 12,
|
||||
"y": 32,
|
||||
"w": 12,
|
||||
"h": 8
|
||||
},
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"unit": "short"
|
||||
},
|
||||
"overrides": []
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"refId": "A",
|
||||
"expr": "avg by (job, host_name) (jvm_cpu_recent_utilization_ratio)",
|
||||
"legendFormat": "CPU {{job}} {{host_name}}",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
}
|
||||
},
|
||||
{
|
||||
"refId": "B",
|
||||
"expr": "sum by (job, host_name) (jvm_memory_used_bytes) / 1048576",
|
||||
"legendFormat": "heap+non-heap MiB {{job}} {{host_name}}",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 11,
|
||||
"type": "logs",
|
||||
"title": "Логи API и worker (Loki, со ссылкой на trace)",
|
||||
"datasource": {
|
||||
"type": "loki",
|
||||
"uid": "loki"
|
||||
},
|
||||
"gridPos": {
|
||||
"x": 0,
|
||||
"y": 40,
|
||||
"w": 24,
|
||||
"h": 10
|
||||
},
|
||||
"options": {
|
||||
"showTime": true,
|
||||
"wrapLogMessage": true
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"refId": "A",
|
||||
"expr": "{service_name=~\"messenger-api|messenger-worker\"}",
|
||||
"datasource": {
|
||||
"type": "loki",
|
||||
"uid": "loki"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 12,
|
||||
"type": "timeseries",
|
||||
"title": "SLO доступности API: burn rate (page ≥ 14.4 за 2m30s+30s, ticket ≥ 6 за 15m+1m30s)",
|
||||
"description": "burn = доля 5xx (без /health) / бюджет 1 %; окна — SRE Workbook, сжатые в 24 раза (см. infra/prometheus/alerts.yml)",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"gridPos": {
|
||||
"x": 0,
|
||||
"y": 50,
|
||||
"w": 12,
|
||||
"h": 8
|
||||
},
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"unit": "x",
|
||||
"min": 0
|
||||
},
|
||||
"overrides": []
|
||||
},
|
||||
"options": {
|
||||
"legend": {
|
||||
"displayMode": "list",
|
||||
"placement": "bottom"
|
||||
}
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"refId": "A",
|
||||
"expr": "slo:api_errors:ratio_rate30s / 0.01",
|
||||
"legendFormat": "burn 30s",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
}
|
||||
},
|
||||
{
|
||||
"refId": "B",
|
||||
"expr": "slo:api_errors:ratio_rate2m30s / 0.01",
|
||||
"legendFormat": "burn 2m30s",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
}
|
||||
},
|
||||
{
|
||||
"refId": "C",
|
||||
"expr": "slo:api_errors:ratio_rate1m30s / 0.01",
|
||||
"legendFormat": "burn 1m30s",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
}
|
||||
},
|
||||
{
|
||||
"refId": "D",
|
||||
"expr": "slo:api_errors:ratio_rate15m / 0.01",
|
||||
"legendFormat": "burn 15m",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 13,
|
||||
"type": "timeseries",
|
||||
"title": "SLO времени до ready ≤ 10 с: burn rate (те же пороги)",
|
||||
"description": "burn = доля вложений с временем до ready > 10 с / бюджет 1 %; события появляются только при ready",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"gridPos": {
|
||||
"x": 12,
|
||||
"y": 50,
|
||||
"w": 12,
|
||||
"h": 8
|
||||
},
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"unit": "x",
|
||||
"min": 0
|
||||
},
|
||||
"overrides": []
|
||||
},
|
||||
"options": {
|
||||
"legend": {
|
||||
"displayMode": "list",
|
||||
"placement": "bottom"
|
||||
}
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"refId": "A",
|
||||
"expr": "slo:ttr_slow:ratio_rate30s / 0.01",
|
||||
"legendFormat": "burn 30s",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
}
|
||||
},
|
||||
{
|
||||
"refId": "B",
|
||||
"expr": "slo:ttr_slow:ratio_rate2m30s / 0.01",
|
||||
"legendFormat": "burn 2m30s",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
}
|
||||
},
|
||||
{
|
||||
"refId": "C",
|
||||
"expr": "slo:ttr_slow:ratio_rate1m30s / 0.01",
|
||||
"legendFormat": "burn 1m30s",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
}
|
||||
},
|
||||
{
|
||||
"refId": "D",
|
||||
"expr": "slo:ttr_slow:ratio_rate15m / 0.01",
|
||||
"legendFormat": "burn 15m",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
# Grafana ничего не хранит сама: три источника, связанные между собой по trace_id.
|
||||
apiVersion: 1
|
||||
datasources:
|
||||
- name: Prometheus
|
||||
uid: prometheus
|
||||
type: prometheus
|
||||
access: proxy
|
||||
url: http://prometheus:9090
|
||||
isDefault: true
|
||||
- name: Loki
|
||||
uid: loki
|
||||
type: loki
|
||||
access: proxy
|
||||
url: http://loki:3100
|
||||
jsonData:
|
||||
# trace_id из structured metadata записи лога → переход в трассу Tempo.
|
||||
derivedFields:
|
||||
- name: trace_id
|
||||
matcherType: label
|
||||
matcherRegex: trace_id
|
||||
datasourceUid: tempo
|
||||
url: '$${__value.raw}'
|
||||
- name: Tempo
|
||||
uid: tempo
|
||||
type: tempo
|
||||
access: proxy
|
||||
url: http://tempo:3200
|
||||
jsonData:
|
||||
tracesToLogsV2:
|
||||
datasourceUid: loki
|
||||
filterByTraceID: true
|
||||
spanStartTimeShift: -5m
|
||||
spanEndTimeShift: 5m
|
||||
@@ -0,0 +1,31 @@
|
||||
# Loki — логи: однопроцессный режим, файловое хранилище в volume, нативный приём OTLP (/otlp).
|
||||
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: 2024-01-01
|
||||
store: tsdb
|
||||
object_store: filesystem
|
||||
schema: v13
|
||||
index:
|
||||
prefix: index_
|
||||
period: 24h
|
||||
limits_config:
|
||||
# trace_id/span_id и атрибуты записи OTLP хранятся как structured metadata, а не как labels.
|
||||
allow_structured_metadata: true
|
||||
retention_period: 168h
|
||||
compactor:
|
||||
working_directory: /loki/compactor
|
||||
retention_enabled: true
|
||||
delete_request_store: filesystem
|
||||
@@ -0,0 +1,39 @@
|
||||
# Public TLS terminates here. The next hop is a separate mTLS connection to API.
|
||||
resolver 127.0.0.11 valid=5s ipv6=off;
|
||||
upstream api_backend {
|
||||
zone api_backend 64k;
|
||||
server api-1:8080 resolve max_fails=3 fail_timeout=10s;
|
||||
server api-2:8080 resolve max_fails=3 fail_timeout=10s;
|
||||
keepalive 32;
|
||||
}
|
||||
server {
|
||||
listen 8443 ssl;
|
||||
server_name localhost;
|
||||
ssl_certificate /run/secrets/ingress.crt;
|
||||
ssl_certificate_key /run/secrets/ingress.key;
|
||||
ssl_protocols TLSv1.2 TLSv1.3;
|
||||
ssl_session_cache shared:TLS:10m;
|
||||
client_max_body_size 11m;
|
||||
client_body_timeout 15s;
|
||||
proxy_connect_timeout 1s;
|
||||
proxy_send_timeout 60s;
|
||||
proxy_read_timeout 60s;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Connection "";
|
||||
proxy_set_header Host $http_host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto https;
|
||||
# Identity is lb (not merely a certificate from our CA); API additionally allowlists its SAN.
|
||||
proxy_ssl_certificate /run/secrets/lb.crt;
|
||||
proxy_ssl_certificate_key /run/secrets/lb.key;
|
||||
proxy_ssl_trusted_certificate /run/secrets/ca.crt;
|
||||
proxy_ssl_verify on;
|
||||
proxy_ssl_verify_depth 2;
|
||||
proxy_ssl_name api;
|
||||
proxy_ssl_server_name on;
|
||||
location / { proxy_pass https://api_backend; proxy_next_upstream error timeout http_503; }
|
||||
location ~ ^/api/v1/chats/[^/]+/messages$ { proxy_pass https://api_backend; proxy_next_upstream error timeout http_503 non_idempotent; }
|
||||
error_page 413 = @payload_too_large;
|
||||
location @payload_too_large { default_type application/json; add_header X-Request-Id $request_id always; return 413 '{"error":{"code":"payload_too_large","message":"payload too large","request_id":"$request_id"}}'; }
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
ui = false
|
||||
disable_mlock = true
|
||||
storage "file" { path = "/openbao/data" }
|
||||
listener "tcp" {
|
||||
address = "0.0.0.0:8200"
|
||||
tls_cert_file = "/run/secrets/openbao.crt"
|
||||
tls_key_file = "/run/secrets/openbao.key"
|
||||
}
|
||||
api_addr = "https://openbao:8200"
|
||||
@@ -0,0 +1,2 @@
|
||||
path "kv/data/messenger/api" { capabilities = ["read"] }
|
||||
path "kv/metadata/messenger/api" { capabilities = ["read", "list"] }
|
||||
@@ -0,0 +1,2 @@
|
||||
path "kv/data/messenger/worker" { capabilities = ["read"] }
|
||||
path "kv/metadata/messenger/worker" { capabilities = ["read", "list"] }
|
||||
@@ -0,0 +1,63 @@
|
||||
# OTel Collector: принимает OTLP от API и worker, ограничивает память, батчит и раскладывает сигналы
|
||||
# по хранилищам. Сам ничего долго не хранит: очереди экспорта ограничены, повторы — не дольше 60 с.
|
||||
receivers:
|
||||
otlp:
|
||||
protocols:
|
||||
grpc:
|
||||
endpoint: 0.0.0.0:4317
|
||||
http:
|
||||
endpoint: 0.0.0.0:4318
|
||||
|
||||
processors:
|
||||
# Первым в цепочке: при превышении лимита Collector отказывает приёмом (SDK повторит/отбросит), а не растёт в RAM.
|
||||
memory_limiter:
|
||||
check_interval: 1s
|
||||
limit_mib: 180
|
||||
spike_limit_mib: 40
|
||||
batch:
|
||||
send_batch_size: 1024
|
||||
timeout: 2s
|
||||
|
||||
exporters:
|
||||
otlphttp/prometheus:
|
||||
endpoint: http://prometheus:9090/api/v1/otlp
|
||||
sending_queue: { queue_size: 500 }
|
||||
retry_on_failure: { max_elapsed_time: 60s }
|
||||
otlphttp/loki:
|
||||
endpoint: http://loki:3100/otlp
|
||||
sending_queue: { queue_size: 500 }
|
||||
retry_on_failure: { max_elapsed_time: 60s }
|
||||
otlp/tempo:
|
||||
endpoint: tempo:4317
|
||||
tls: { insecure: true }
|
||||
sending_queue: { queue_size: 500 }
|
||||
retry_on_failure: { max_elapsed_time: 60s }
|
||||
|
||||
extensions:
|
||||
health_check:
|
||||
endpoint: 0.0.0.0:13133
|
||||
|
||||
service:
|
||||
extensions: [health_check]
|
||||
# Собственные метрики Collector (принято/отброшено/ошибки экспорта) — их собирает Prometheus.
|
||||
telemetry:
|
||||
metrics:
|
||||
readers:
|
||||
- pull:
|
||||
exporter:
|
||||
prometheus:
|
||||
host: 0.0.0.0
|
||||
port: 8888
|
||||
pipelines:
|
||||
traces:
|
||||
receivers: [otlp]
|
||||
processors: [memory_limiter, batch]
|
||||
exporters: [otlp/tempo]
|
||||
metrics:
|
||||
receivers: [otlp]
|
||||
processors: [memory_limiter, batch]
|
||||
exporters: [otlphttp/prometheus]
|
||||
logs:
|
||||
receivers: [otlp]
|
||||
processors: [memory_limiter, batch]
|
||||
exporters: [otlphttp/loki]
|
||||
@@ -0,0 +1,18 @@
|
||||
server {
|
||||
listen 4318 ssl;
|
||||
server_name otel-gateway;
|
||||
ssl_certificate /run/secrets/collector.crt;
|
||||
ssl_certificate_key /run/secrets/collector.key;
|
||||
ssl_client_certificate /run/secrets/ca.crt;
|
||||
ssl_verify_client on;
|
||||
ssl_verify_depth 2;
|
||||
ssl_protocols TLSv1.2 TLSv1.3;
|
||||
if ($ssl_client_s_dn !~ "^CN=(api-otel|worker-otel)$") { return 403; }
|
||||
location / {
|
||||
proxy_pass http://otel-collector:4318;
|
||||
proxy_set_header Connection "";
|
||||
proxy_http_version 1.1;
|
||||
proxy_read_timeout 60s;
|
||||
proxy_send_timeout 60s;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
|
||||
if [ "$(id -u)" = 0 ]; then
|
||||
install -o postgres -g postgres -m 0600 /run/secrets/postgres.key /var/lib/postgresql/data/server.key
|
||||
install -o postgres -g postgres -m 0644 /run/secrets/postgres.crt /var/lib/postgresql/data/server.crt
|
||||
install -o postgres -g postgres -m 0644 /run/secrets/ca.crt /var/lib/postgresql/data/ca.crt
|
||||
fi
|
||||
|
||||
exec /usr/local/bin/docker-entrypoint.sh "$@"
|
||||
@@ -0,0 +1,107 @@
|
||||
# Правила Prometheus: SLO burn-rate (трек 2) и базовые alerts уровня 4. Состояние видно в Prometheus
|
||||
# /api/v1/alerts и в Grafana → Alerting (data source-managed). Доставка наружу не настроена (не требуется).
|
||||
#
|
||||
# SLO-1 «доступность API»: 99 % бизнес-запросов (все маршруты, кроме /health/*) без 5xx; 4xx — ответ
|
||||
# клиенту, а не отказ сервиса. Бюджет ошибок b = 1 %.
|
||||
# SLO-2 «время до ready»: 99 % вложений становятся ready не позже 10 с после durable acceptance (202).
|
||||
# Бюджет b = 1 %. Плохое событие — время до ready > 10 с (bucket le="10").
|
||||
#
|
||||
# Пороги — multiwindow multi-burn-rate из SRE Workbook (окно SLO 30 дней): 14.4× за 1 ч + 5 мин (page) и
|
||||
# 6× за 6 ч + 30 мин. Учебный стенд сжимает время в 24 раза, чтобы эксперимент занимал минуты:
|
||||
# 1 ч → 2m30s, 6 ч → 15m; короткие окна (1/12 длинного) 12.5 с → 30s и 75 с → 1m30s — не меньше трёх
|
||||
# отсчётов при экспорте метрик раз в 10 с. Короткое окно гасит alert вскоре после восстановления.
|
||||
groups:
|
||||
- name: slo-api-availability
|
||||
interval: 10s
|
||||
rules:
|
||||
- record: slo:api_errors:ratio_rate30s
|
||||
expr: |
|
||||
sum(rate(http_server_request_duration_seconds_count{job="messenger-api", http_route!~"/health.*", http_response_status_code=~"5.."}[30s]))
|
||||
/ sum(rate(http_server_request_duration_seconds_count{job="messenger-api", http_route!~"/health.*"}[30s]))
|
||||
- record: slo:api_errors:ratio_rate1m
|
||||
expr: |
|
||||
sum(rate(http_server_request_duration_seconds_count{job="messenger-api", http_route!~"/health.*", http_response_status_code=~"5.."}[1m]))
|
||||
/ sum(rate(http_server_request_duration_seconds_count{job="messenger-api", http_route!~"/health.*"}[1m]))
|
||||
- record: slo:api_errors:ratio_rate1m30s
|
||||
expr: |
|
||||
sum(rate(http_server_request_duration_seconds_count{job="messenger-api", http_route!~"/health.*", http_response_status_code=~"5.."}[1m30s]))
|
||||
/ sum(rate(http_server_request_duration_seconds_count{job="messenger-api", http_route!~"/health.*"}[1m30s]))
|
||||
- record: slo:api_errors:ratio_rate2m30s
|
||||
expr: |
|
||||
sum(rate(http_server_request_duration_seconds_count{job="messenger-api", http_route!~"/health.*", http_response_status_code=~"5.."}[2m30s]))
|
||||
/ sum(rate(http_server_request_duration_seconds_count{job="messenger-api", http_route!~"/health.*"}[2m30s]))
|
||||
- record: slo:api_errors:ratio_rate15m
|
||||
expr: |
|
||||
sum(rate(http_server_request_duration_seconds_count{job="messenger-api", http_route!~"/health.*", http_response_status_code=~"5.."}[15m]))
|
||||
/ sum(rate(http_server_request_duration_seconds_count{job="messenger-api", http_route!~"/health.*"}[15m]))
|
||||
|
||||
- alert: ApiAvailabilityFastBurn
|
||||
expr: slo:api_errors:ratio_rate2m30s > (14.4 * 0.01) and slo:api_errors:ratio_rate30s > (14.4 * 0.01)
|
||||
labels: { severity: page, slo: api-availability }
|
||||
annotations:
|
||||
summary: "API сжигает бюджет ошибок в 14.4× быстрее допустимого"
|
||||
description: "Доля 5xx за 2m30s и 30s выше 14.4 %. При таком темпе месячный бюджет кончится за ~2 дня (в учебном масштабе — за 2 ч)."
|
||||
runbook: docs/runbook.md#apiavailabilityfastburn--apiavailabilityslowburn--apihigherrorrate
|
||||
- alert: ApiAvailabilitySlowBurn
|
||||
expr: slo:api_errors:ratio_rate15m > (6 * 0.01) and slo:api_errors:ratio_rate1m30s > (6 * 0.01)
|
||||
labels: { severity: ticket, slo: api-availability }
|
||||
annotations:
|
||||
summary: "API длительно сжигает бюджет ошибок (6×)"
|
||||
description: "Доля 5xx за 15m и 1m30s выше 6 %."
|
||||
runbook: docs/runbook.md#apiavailabilityfastburn--apiavailabilityslowburn--apihigherrorrate
|
||||
# Наивное правило уровня 4 «высокий error rate» — одно окно и порог; в треке 2 служит базой
|
||||
# для сравнения ложных срабатываний с burn-rate.
|
||||
- alert: ApiHighErrorRate
|
||||
expr: slo:api_errors:ratio_rate1m > 0.05
|
||||
for: 30s
|
||||
labels: { severity: ticket }
|
||||
annotations:
|
||||
summary: "Доля 5xx API за 1 мин выше 5 %"
|
||||
description: "Числитель — 5xx, знаменатель — все запросы кроме /health/*."
|
||||
runbook: docs/runbook.md#apiavailabilityfastburn--apiavailabilityslowburn--apihigherrorrate
|
||||
|
||||
- name: slo-time-to-ready
|
||||
interval: 10s
|
||||
rules:
|
||||
- record: slo:ttr_slow:ratio_rate30s
|
||||
expr: 1 - sum(rate(messenger_attachment_time_to_ready_seconds_bucket{le="10"}[30s])) / sum(rate(messenger_attachment_time_to_ready_seconds_count[30s]))
|
||||
- record: slo:ttr_slow:ratio_rate1m30s
|
||||
expr: 1 - sum(rate(messenger_attachment_time_to_ready_seconds_bucket{le="10"}[1m30s])) / sum(rate(messenger_attachment_time_to_ready_seconds_count[1m30s]))
|
||||
- record: slo:ttr_slow:ratio_rate2m30s
|
||||
expr: 1 - sum(rate(messenger_attachment_time_to_ready_seconds_bucket{le="10"}[2m30s])) / sum(rate(messenger_attachment_time_to_ready_seconds_count[2m30s]))
|
||||
- record: slo:ttr_slow:ratio_rate15m
|
||||
expr: 1 - sum(rate(messenger_attachment_time_to_ready_seconds_bucket{le="10"}[15m])) / sum(rate(messenger_attachment_time_to_ready_seconds_count[15m]))
|
||||
|
||||
# Событие появляется только при ready: пока worker стоит, этих alerts нет — остановку ловит QueueLagHigh.
|
||||
- alert: TimeToReadyFastBurn
|
||||
expr: slo:ttr_slow:ratio_rate2m30s > (14.4 * 0.01) and slo:ttr_slow:ratio_rate30s > (14.4 * 0.01)
|
||||
labels: { severity: page, slo: time-to-ready }
|
||||
annotations:
|
||||
summary: "Вложения становятся ready дольше 10 с: бюджет горит в 14.4×"
|
||||
runbook: docs/runbook.md#queuelaghigh--workerabsent--timetoready
|
||||
- alert: TimeToReadySlowBurn
|
||||
expr: slo:ttr_slow:ratio_rate15m > (6 * 0.01) and slo:ttr_slow:ratio_rate1m30s > (6 * 0.01)
|
||||
labels: { severity: ticket, slo: time-to-ready }
|
||||
annotations:
|
||||
summary: "Вложения длительно становятся ready дольше 10 с (6×)"
|
||||
runbook: docs/runbook.md#queuelaghigh--workerabsent--timetoready
|
||||
|
||||
- name: pipeline
|
||||
interval: 10s
|
||||
rules:
|
||||
# Возраст старейшего queued-задания (источник — таблица jobs; gauge отдают API и worker, берём max).
|
||||
- alert: QueueLagHigh
|
||||
expr: max(messenger_queue_oldest_age_seconds) > 60
|
||||
for: 30s
|
||||
labels: { severity: page }
|
||||
annotations:
|
||||
summary: "Старейшее задание ждёт дольше 60 с"
|
||||
description: "Очередь не разбирается: worker остановлен, перегружен или не получает сообщения."
|
||||
runbook: docs/runbook.md#queuelaghigh--workerabsent--timetoready
|
||||
# OTLP — push, у пропавшего процесса нет staleness-маркеров: отсутствие отсчётов за 1 мин = worker не жив.
|
||||
- alert: WorkerAbsent
|
||||
expr: absent_over_time(messenger_worker_capacity{job="messenger-worker"}[1m])
|
||||
labels: { severity: page }
|
||||
annotations:
|
||||
summary: "Нет метрик worker больше минуты"
|
||||
runbook: docs/runbook.md#queuelaghigh--workerabsent--timetoready
|
||||
@@ -0,0 +1,22 @@
|
||||
# Prometheus — метрики: принимает OTLP от Collector (--web.enable-otlp-receiver) и сам опрашивает Collector.
|
||||
global:
|
||||
scrape_interval: 15s
|
||||
evaluation_interval: 10s
|
||||
|
||||
# SLO burn-rate и alerts уровня 4.
|
||||
rule_files:
|
||||
- /etc/prometheus/alerts.yml
|
||||
|
||||
# Атрибуты ресурса, которые нужны как labels (реплика и окружение); остальное — в target_info.
|
||||
otlp:
|
||||
promote_resource_attributes: [service.instance.id, host.name, deployment.environment.name]
|
||||
|
||||
# OTLP приходит батчами с задержкой: допускаем отсчёты не по порядку в пределах 30 минут.
|
||||
storage:
|
||||
tsdb:
|
||||
out_of_order_time_window: 30m
|
||||
|
||||
scrape_configs:
|
||||
- job_name: otel-collector
|
||||
static_configs:
|
||||
- targets: ['otel-collector:8888']
|
||||
@@ -0,0 +1 @@
|
||||
[rabbitmq_auth_mechanism_ssl].
|
||||
@@ -0,0 +1,17 @@
|
||||
# Пользователи, права, exchange и очереди импортируются при каждом старте (идемпотентно, по хешу файла).
|
||||
load_definitions = /run/secrets/rabbitmq_definitions.json
|
||||
# The broker accepts only mutually authenticated TLS connections; plaintext AMQP is disabled.
|
||||
listeners.tcp = none
|
||||
listeners.ssl.default = 5671
|
||||
ssl_options.cacertfile = /run/secrets/ca.crt
|
||||
ssl_options.certfile = /run/secrets/broker.crt
|
||||
ssl_options.keyfile = /run/secrets/broker.key
|
||||
ssl_options.verify = verify_peer
|
||||
ssl_options.fail_if_no_peer_cert = true
|
||||
# EXTERNAL maps the verified client certificate CN to the RabbitMQ username.
|
||||
# PLAIN is disabled so a password cannot bypass certificate identity.
|
||||
auth_mechanisms.1 = EXTERNAL
|
||||
ssl_cert_login_from = common_name
|
||||
# Пороги flow control ниже лимита контейнера 512M: при нехватке памяти/диска брокер тормозит издателей, а не падает.
|
||||
vm_memory_high_watermark.absolute = 256MiB
|
||||
disk_free_limit.absolute = 200MB
|
||||
@@ -0,0 +1,17 @@
|
||||
server {
|
||||
listen 8443 ssl;
|
||||
server_name s3-tls;
|
||||
ssl_certificate /run/secrets/s3-tls.crt;
|
||||
ssl_certificate_key /run/secrets/s3-tls.key;
|
||||
ssl_protocols TLSv1.2 TLSv1.3;
|
||||
client_max_body_size 12m;
|
||||
proxy_connect_timeout 2s;
|
||||
proxy_read_timeout 60s;
|
||||
proxy_send_timeout 60s;
|
||||
location / {
|
||||
proxy_pass http://s3:8333;
|
||||
proxy_set_header Host $http_host;
|
||||
proxy_set_header Connection "";
|
||||
proxy_request_buffering off;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
#!/bin/sh
|
||||
# Идемпотентный bootstrap S3: bucket создаётся один раз, повторный запуск ничего не меняет.
|
||||
# Работает с admin-ключами; API их не получает. Ключи передаются curl через stdin, не в argv.
|
||||
set -eu
|
||||
url="$S3_ENDPOINT/$S3_BUCKET"
|
||||
|
||||
s3() {
|
||||
printf 'user = "%s:%s"\n' "$(cat /run/secrets/s3_admin_access_key)" "$(cat /run/secrets/s3_admin_secret_key)" |
|
||||
curl -K - --cacert /run/secrets/ca.crt -s -o /dev/null -w '%{http_code}' --aws-sigv4 "aws:amz:$S3_REGION:s3" "$@"
|
||||
}
|
||||
|
||||
code=$(s3 -I "$url")
|
||||
case "$code" in
|
||||
200) echo "bucket $S3_BUCKET already exists" ;;
|
||||
404)
|
||||
code=$(s3 -X PUT "$url")
|
||||
# 409: bucket успели создать параллельно — это тоже успех.
|
||||
[ "$code" = 200 ] || [ "$code" = 409 ] || { echo "create bucket failed: HTTP $code" >&2; exit 1; }
|
||||
echo "bucket $S3_BUCKET created" ;;
|
||||
*) echo "head bucket failed: HTTP $code" >&2; exit 1 ;;
|
||||
esac
|
||||
|
||||
# Bucket приватный: анонимный листинг и чтение должны получать 403.
|
||||
anon=$(curl --cacert /run/secrets/ca.crt -s -o /dev/null -w '%{http_code}' "$url?list-type=2")
|
||||
[ "$anon" = 403 ] || { echo "bucket is not private: anonymous list -> HTTP $anon" >&2; exit 1; }
|
||||
echo "anonymous list -> 403, bucket is private"
|
||||
@@ -0,0 +1,19 @@
|
||||
# Tempo — трассы: приём OTLP gRPC от Collector, локальное хранилище блоков в volume, хранение 7 дней.
|
||||
server:
|
||||
http_listen_port: 3200
|
||||
distributor:
|
||||
receivers:
|
||||
otlp:
|
||||
protocols:
|
||||
grpc:
|
||||
endpoint: 0.0.0.0:4317
|
||||
storage:
|
||||
trace:
|
||||
backend: local
|
||||
local:
|
||||
path: /var/tempo/traces
|
||||
wal:
|
||||
path: /var/tempo/wal
|
||||
compactor:
|
||||
compaction:
|
||||
block_retention: 168h
|
||||
Reference in New Issue
Block a user