This commit is contained in:
2026-10-30 21:38:40 +03:00
parent 470d9d6f1e
commit f7e3e72056
149 changed files with 417010 additions and 29 deletions
+18
View File
@@ -0,0 +1,18 @@
#!/bin/sh
set -eu
# Пароль не передаётся аргументом процесса и не печатается в лог.
# Root-owned directory avoids sticky /tmp protected_regular on container restart.
mkdir -p /run/broker
chmod 755 /run/broker
{
echo 'dir /data'
echo 'appendonly yes'
echo 'appendfsync always'
echo 'save ""'
echo 'maxmemory 192mb'
echo 'maxmemory-policy noeviction'
printf 'requirepass %s\n' "$(cat /run/secrets/broker_password)"
} > /run/broker/broker.conf
chmod 600 /run/broker/broker.conf
chown redis:redis /run/broker/broker.conf
exec /usr/local/bin/docker-entrypoint.sh redis-server /run/broker/broker.conf
+37
View File
@@ -0,0 +1,37 @@
global
log stdout format raw local0
maxconn 2048
defaults
mode http
log global
option httplog
timeout connect 500ms
timeout client 30s
timeout server 50s
timeout check 1s
retries 0
resolvers docker
nameserver dns 127.0.0.11:53
resolve_retries 1
timeout resolve 1s
timeout retry 1s
hold valid 1s
hold nx 1s
hold other 1s
hold refused 1s
hold timeout 1s
hold obsolete 1s
frontend public
bind :8080
http-request deny if { path_beg /internal/ }
default_backend messenger
backend messenger
balance roundrobin
option httpchk GET /health/ready
http-check expect status 200
default-server inter 1s fastinter 500ms downinter 1s fall 2 rise 1
server-template api 1-4 api:8080 check resolvers docker init-addr none resolve-prefer ipv4
+5
View File
@@ -0,0 +1,5 @@
#!/bin/sh
set -eu
export MINIO_ROOT_USER="$(cat /run/secrets/s3_root_user)"
export MINIO_ROOT_PASSWORD="$(cat /run/secrets/s3_root_password)"
exec minio "$@"
+44
View File
@@ -0,0 +1,44 @@
groups:
- name: incidents
rules:
- alert: APIHighErrorRate
expr: slo:api_error_ratio:30s > 0.05
for: 10s
labels:
severity: warning
annotations:
summary: API 5xx > 5% / 30s
runbook: 'REPORT.md: DB incident'
- alert: QueueLagGrowing
expr: max(queue_oldest_age_seconds) > 15 and max(queue_depth) > 0
for: 10s
labels:
severity: warning
annotations:
summary: Durable unfinished job age > 15s
runbook: 'REPORT.md: worker incident'
- alert: APIErrorBudgetBurnFast
expr: slo:api_error_ratio:30s > 0.144 and slo:api_error_ratio:2m > 0.144
for: 10s
labels:
severity: critical
annotations:
summary: 'API 99% SLO: burn >14.4 over 30s AND 2m'
runbook: 'REPORT.md: DB incident'
- alert: APIErrorBudgetBurnSlow
expr: slo:api_error_ratio:1m > 0.06 and slo:api_error_ratio:5m > 0.06
for: 20s
labels:
severity: warning
annotations:
summary: 'API 99% SLO: burn >6 over 1m AND 5m'
runbook: 'REPORT.md: DB incident'
- alert: ReadyErrorBudgetBurn
expr: slo:ready_bad_ratio:30s > 0.144 and slo:ready_bad_ratio:2m > 0.144 and sum(rate(ready_deadline_jobs_total[30s]))
> 0
for: 10s
labels:
severity: warning
annotations:
summary: 'Ready <=10s / 99%: burn >14.4'
runbook: 'REPORT.md: worker incident'
+96
View File
@@ -0,0 +1,96 @@
extensions:
health_check:
endpoint: 0.0.0.0:13133
file_storage:
directory: /var/lib/otel
compaction:
on_start: true
directory: /var/lib/otel/compact
create_directory: true
receivers:
otlp:
protocols:
http:
endpoint: 0.0.0.0:4318
grpc:
endpoint: 0.0.0.0:4317
processors:
memory_limiter:
check_interval: 1s
limit_mib: 160
spike_limit_mib: 32
batch:
timeout: 1s
send_batch_size: 128
send_batch_max_size: 256
exporters:
prometheus:
endpoint: 0.0.0.0:8889
resource_to_telemetry_conversion:
enabled: true
otlphttp/loki:
endpoint: http://loki:3100/otlp
timeout: 2s
sending_queue:
enabled: true
queue_size: 32
num_consumers: 1
storage: file_storage
retry_on_failure:
enabled: true
initial_interval: 1s
max_interval: 3s
max_elapsed_time: 10s
otlp/tempo:
endpoint: tempo:4317
tls:
insecure: true
timeout: 2s
sending_queue:
enabled: true
queue_size: 32
num_consumers: 1
storage: file_storage
retry_on_failure:
enabled: true
initial_interval: 1s
max_interval: 3s
max_elapsed_time: 10s
service:
extensions:
- health_check
- file_storage
telemetry:
metrics:
level: detailed
readers:
- pull:
exporter:
prometheus:
host: 0.0.0.0
port: 8888
pipelines:
metrics:
receivers:
- otlp
processors:
- memory_limiter
- batch
exporters:
- prometheus
logs:
receivers:
- otlp
processors:
- memory_limiter
- batch
exporters:
- otlphttp/loki
traces:
receivers:
- otlp
processors:
- memory_limiter
- batch
exporters:
- otlp/tempo
+484
View File
@@ -0,0 +1,484 @@
{
"uid": "lab6",
"title": "Lab6 \u2014 Messenger observations",
"schemaVersion": 39,
"version": 1,
"refresh": "5s",
"time": {
"from": "now-15m",
"to": "now"
},
"panels": [
{
"id": 1,
"type": "timeseries",
"title": "Business API requests / second",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 0,
"y": 0,
"w": 12,
"h": 8
},
"targets": [
{
"expr": "sum(rate(app_http_requests_total[1m]))",
"refId": "A"
}
],
"fieldConfig": {
"defaults": {
"unit": "reqps"
},
"overrides": []
}
},
{
"id": 2,
"type": "timeseries",
"title": "API 5xx / business requests",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 12,
"y": 0,
"w": 12,
"h": 8
},
"targets": [
{
"expr": "slo:api_error_ratio:1m",
"refId": "A"
}
],
"fieldConfig": {
"defaults": {
"unit": "percentunit"
},
"overrides": []
}
},
{
"id": 3,
"type": "timeseries",
"title": "API latency p50 / p95 / p99, all replicas",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 0,
"y": 8,
"w": 12,
"h": 8
},
"targets": [
{
"expr": "histogram_quantile(0.5,sum by(le)(rate(app_http_duration_seconds_bucket[1m])))",
"refId": "A"
},
{
"expr": "histogram_quantile(0.95,sum by(le)(rate(app_http_duration_seconds_bucket[1m])))",
"refId": "B"
},
{
"expr": "histogram_quantile(0.99,sum by(le)(rate(app_http_duration_seconds_bucket[1m])))",
"refId": "C"
}
],
"fieldConfig": {
"defaults": {
"unit": "s"
},
"overrides": []
}
},
{
"id": 4,
"type": "timeseries",
"title": "Jobs processed / second by outcome",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 12,
"y": 8,
"w": 12,
"h": 8
},
"targets": [
{
"expr": "sum by(outcome)(rate(jobs_processed_total[1m]))",
"refId": "A"
}
],
"fieldConfig": {
"defaults": {
"unit": "ops"
},
"overrides": []
}
},
{
"id": 5,
"type": "timeseries",
"title": "Worker processing p95",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 0,
"y": 16,
"w": 12,
"h": 8
},
"targets": [
{
"expr": "histogram_quantile(0.95,sum by(le)(rate(job_duration_seconds_bucket[1m])))",
"refId": "A"
}
],
"fieldConfig": {
"defaults": {
"unit": "s"
},
"overrides": []
}
},
{
"id": 6,
"type": "timeseries",
"title": "Ready time p50 / p95 / p99",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 12,
"y": 16,
"w": 12,
"h": 8
},
"targets": [
{
"expr": "histogram_quantile(0.5,sum by(le)(rate(attachment_ready_seconds_bucket[2m])))",
"refId": "A"
},
{
"expr": "histogram_quantile(0.95,sum by(le)(rate(attachment_ready_seconds_bucket[2m])))",
"refId": "B"
},
{
"expr": "histogram_quantile(0.99,sum by(le)(rate(attachment_ready_seconds_bucket[2m])))",
"refId": "C"
}
],
"fieldConfig": {
"defaults": {
"unit": "s"
},
"overrides": []
}
},
{
"id": 7,
"type": "timeseries",
"title": "Durable unfinished jobs",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 0,
"y": 24,
"w": 12,
"h": 8
},
"targets": [
{
"expr": "max(queue_depth)",
"refId": "A"
}
],
"fieldConfig": {
"defaults": {
"unit": "short"
},
"overrides": []
}
},
{
"id": 8,
"type": "timeseries",
"title": "Oldest unfinished job / seconds",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 12,
"y": 24,
"w": 12,
"h": 8
},
"targets": [
{
"expr": "max(queue_oldest_age_seconds)",
"refId": "A"
}
],
"fieldConfig": {
"defaults": {
"unit": "s"
},
"overrides": []
}
},
{
"id": 9,
"type": "timeseries",
"title": "DB pool used / waiting",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 0,
"y": 32,
"w": 12,
"h": 8
},
"targets": [
{
"expr": "sum(db_pool_used)",
"refId": "A"
},
{
"expr": "sum(db_pool_waiting)",
"refId": "B"
}
],
"fieldConfig": {
"defaults": {
"unit": "short"
},
"overrides": []
}
},
{
"id": 10,
"type": "timeseries",
"title": "Worker busy / capacity",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 12,
"y": 32,
"w": 12,
"h": 8
},
"targets": [
{
"expr": "sum(worker_busy)",
"refId": "A"
},
{
"expr": "sum(worker_capacity)",
"refId": "B"
}
],
"fieldConfig": {
"defaults": {
"unit": "short"
},
"overrides": []
}
},
{
"id": 11,
"type": "timeseries",
"title": "Process CPU / cores",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 0,
"y": 40,
"w": 12,
"h": 8
},
"targets": [
{
"expr": "rate(process_cpu_seconds[1m])",
"refId": "A"
}
],
"fieldConfig": {
"defaults": {
"unit": "short"
},
"overrides": []
}
},
{
"id": 12,
"type": "timeseries",
"title": "Process RSS high water / bytes",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 12,
"y": 40,
"w": 12,
"h": 8
},
"targets": [
{
"expr": "process_memory_bytes",
"refId": "A"
}
],
"fieldConfig": {
"defaults": {
"unit": "bytes"
},
"overrides": []
}
},
{
"id": 13,
"type": "timeseries",
"title": "API budget burn / 30s / 2m / 5m",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 0,
"y": 48,
"w": 12,
"h": 8
},
"targets": [
{
"expr": "slo:api_error_ratio:30s / 0.01",
"refId": "A"
},
{
"expr": "slo:api_error_ratio:2m / 0.01",
"refId": "B"
},
{
"expr": "slo:api_error_ratio:5m / 0.01",
"refId": "C"
}
],
"fieldConfig": {
"defaults": {
"unit": "short"
},
"overrides": []
}
},
{
"id": 14,
"type": "timeseries",
"title": "Active alerts",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 12,
"y": 48,
"w": 12,
"h": 8
},
"targets": [
{
"expr": "ALERTS{alertstate=\"firing\"}",
"refId": "A"
}
],
"fieldConfig": {
"defaults": {
"unit": "short"
},
"overrides": []
}
},
{
"id": 15,
"type": "timeseries",
"title": "Queue probe valid (0 = DB unavailable)",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 0,
"y": 56,
"w": 12,
"h": 8
},
"targets": [
{
"expr": "queue_probe_ok_ratio",
"refId": "A"
}
],
"fieldConfig": {
"defaults": {
"unit": "short"
},
"overrides": []
}
},
{
"id": 16,
"type": "timeseries",
"title": "Collector failed exports / refused spans",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 12,
"y": 56,
"w": 12,
"h": 8
},
"targets": [
{
"expr": "rate(otelcol_exporter_send_failed_spans_total[1m])",
"refId": "A"
},
{
"expr": "rate(otelcol_receiver_refused_spans_total[1m])",
"refId": "B"
}
],
"fieldConfig": {
"defaults": {
"unit": "short"
},
"overrides": []
}
}
],
"tags": [
"lab6"
]
}
@@ -0,0 +1,6 @@
apiVersion: 1
providers:
- name: Lab6
type: file
options:
path: /var/lib/grafana/dashboards
@@ -0,0 +1,28 @@
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:
derivedFields:
- name: TraceID
matcherRegex: '"trace_id":"([0-9a-f]{32})"'
datasourceUid: tempo
url: ${__value.raw}
- name: Tempo
uid: tempo
type: tempo
access: proxy
url: http://tempo:3200
jsonData:
tracesToLogsV2:
datasourceUid: loki
filterByTraceID: true
+31
View File
@@ -0,0 +1,31 @@
auth_enabled: false
server:
http_listen_port: 3100
common:
path_prefix: /loki
replication_factor: 1
ring:
kvstore:
store: inmemory
storage:
filesystem:
chunks_directory: /loki/chunks
rules_directory: /loki/rules
schema_config:
configs:
- from: '2024-01-01'
store: tsdb
object_store: filesystem
schema: v13
index:
prefix: index_
period: 24h
limits_config:
allow_structured_metadata: true
retention_period: 48h
compactor:
working_directory: /loki/compactor
retention_enabled: true
delete_request_store: filesystem
analytics:
reporting_enabled: false
+15
View File
@@ -0,0 +1,15 @@
global:
scrape_interval: 5s
evaluation_interval: 5s
rule_files:
- /etc/prometheus/recording.yaml
- /etc/prometheus/alerts.yaml
scrape_configs:
- job_name: application
static_configs:
- targets:
- collector:8889
- job_name: collector
static_configs:
- targets:
- collector:8888
+28
View File
@@ -0,0 +1,28 @@
groups:
- name: slo
interval: 5s
rules:
- record: slo:api_error_ratio:30s
expr: (sum(rate(app_http_requests_total{status_class="5xx",route!~"/health.*"}[30s]))
or vector(0)) / clamp_min(sum(rate(app_http_requests_total{route!~"/health.*"}[30s])),
0.001)
- record: slo:ready_bad_ratio:30s
expr: sum(rate(ready_deadline_missed_total[30s])) / clamp_min(sum(rate(ready_deadline_jobs_total[30s])),0.001)
- record: slo:api_error_ratio:1m
expr: (sum(rate(app_http_requests_total{status_class="5xx",route!~"/health.*"}[1m]))
or vector(0)) / clamp_min(sum(rate(app_http_requests_total{route!~"/health.*"}[1m])),
0.001)
- record: slo:ready_bad_ratio:1m
expr: sum(rate(ready_deadline_missed_total[1m])) / clamp_min(sum(rate(ready_deadline_jobs_total[1m])),0.001)
- record: slo:api_error_ratio:2m
expr: (sum(rate(app_http_requests_total{status_class="5xx",route!~"/health.*"}[2m]))
or vector(0)) / clamp_min(sum(rate(app_http_requests_total{route!~"/health.*"}[2m])),
0.001)
- record: slo:ready_bad_ratio:2m
expr: sum(rate(ready_deadline_missed_total[2m])) / clamp_min(sum(rate(ready_deadline_jobs_total[2m])),0.001)
- record: slo:api_error_ratio:5m
expr: (sum(rate(app_http_requests_total{status_class="5xx",route!~"/health.*"}[5m]))
or vector(0)) / clamp_min(sum(rate(app_http_requests_total{route!~"/health.*"}[5m])),
0.001)
- record: slo:ready_bad_ratio:5m
expr: sum(rate(ready_deadline_missed_total[5m])) / clamp_min(sum(rate(ready_deadline_jobs_total[5m])),0.001)
+25
View File
@@ -0,0 +1,25 @@
server:
http_listen_port: 3200
distributor:
receivers:
otlp:
protocols:
grpc:
endpoint: 0.0.0.0:4317
http:
endpoint: 0.0.0.0:4318
ingester:
trace_idle_period: 5s
max_block_duration: 1m
compactor:
compaction:
block_retention: 48h
storage:
trace:
backend: local
wal:
path: /var/tempo/wal
local:
path: /var/tempo/blocks
usage_report:
reporting_enabled: false
+45
View File
@@ -0,0 +1,45 @@
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:GetBucketLocation"
],
"Resource": [
"arn:aws:s3:::messenger-attachments"
]
},
{
"Effect": "Allow",
"Action": [
"s3:ListBucket"
],
"Resource": [
"arn:aws:s3:::messenger-attachments"
],
"Condition": {
"StringLike": {
"s3:prefix": [
"originals/*",
"staging/*",
"variants/*"
]
}
}
},
{
"Effect": "Allow",
"Action": [
"s3:GetObject",
"s3:PutObject",
"s3:DeleteObject"
],
"Resource": [
"arn:aws:s3:::messenger-attachments/originals/*",
"arn:aws:s3:::messenger-attachments/staging/*",
"arn:aws:s3:::messenger-attachments/variants/*"
]
}
]
}
+27
View File
@@ -0,0 +1,27 @@
# syntax=docker/dockerfile:1.7.0
FROM python:3.12.10-slim-bookworm
ARG COMPONENT
ARG RELEASE
ARG SHA256
RUN python - <<'PY'
import hashlib
import os
from pathlib import Path
import shutil
import urllib.request
component = os.environ['COMPONENT']
release = os.environ['RELEASE']
assert component in {'minio', 'mc'}
name = f'{component}.linux-amd64.{release}'
url = f'https://github.com/minio/{component}/releases/download/{release}/{name}'
target = Path('/usr/local/bin') / component
with urllib.request.urlopen(url, timeout=180) as response, target.open('wb') as file:
shutil.copyfileobj(response, file)
with target.open('rb') as file:
digest = hashlib.file_digest(file, 'sha256').hexdigest()
assert digest == os.environ['SHA256'], 'Unexpected binary checksum'
target.chmod(0o755)
PY
COPY infra/minio-entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/bin/sh", "/entrypoint.sh"]