forked from mtusi2026/mtusi2026lab7
Добавить стенд лабораторной 7 с mTLS, OpenBao и least privilege worker.
Закрывает обязательный минимум и трек 1: ротация leaf и секрета, sealed OpenBao и сохранность queued-задачи.
This commit is contained in:
@@ -0,0 +1,187 @@
|
||||
{
|
||||
"uid": "messenger-overview",
|
||||
"title": "Messenger observability",
|
||||
"timezone": "utc",
|
||||
"schemaVersion": 39,
|
||||
"version": 1,
|
||||
"refresh": "10s",
|
||||
"tags": ["messenger", "lab6"],
|
||||
"time": {"from": "now-1h", "to": "now"},
|
||||
"panels": [
|
||||
{
|
||||
"id": 1,
|
||||
"type": "text",
|
||||
"title": "Signal stores",
|
||||
"gridPos": {"h": 4, "w": 24, "x": 0, "y": 0},
|
||||
"options": {
|
||||
"mode": "markdown",
|
||||
"content": "Prometheus stores metrics (rates, histograms, gauges). Loki stores structured logs. Tempo stores traces. The collector is not a database: it receives OTLP, redacts, batches, and exports. Grafana only queries those stores. Percentiles use `histogram_quantile` on cumulative buckets, summed across API replicas before the quantile."
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"type": "timeseries",
|
||||
"title": "API RPS by route",
|
||||
"description": "Unit: requests per second. Sum of rates across replicas.",
|
||||
"datasource": {"type": "prometheus", "uid": "prometheus"},
|
||||
"gridPos": {"h": 8, "w": 12, "x": 0, "y": 4},
|
||||
"fieldConfig": {"defaults": {"unit": "reqps", "custom": {"drawStyle": "line"}}, "overrides": []},
|
||||
"targets": [
|
||||
{
|
||||
"refId": "A",
|
||||
"expr": "sum by (http_route) (rate(http_server_requests_total{service_name=\"messenger-api\"}[1m]))",
|
||||
"legendFormat": "{{http_route}}"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"type": "timeseries",
|
||||
"title": "API error ratio (5xx / business)",
|
||||
"description": "Unit: fraction 0-1. Numerator is status class 5xx. Denominator is business routes, excluding /health and unmatched. 4xx is not an error for this SLI.",
|
||||
"datasource": {"type": "prometheus", "uid": "prometheus"},
|
||||
"gridPos": {"h": 8, "w": 12, "x": 12, "y": 4},
|
||||
"fieldConfig": {"defaults": {"unit": "percentunit", "min": 0, "max": 1}, "overrides": []},
|
||||
"targets": [
|
||||
{"refId": "A", "expr": "messenger:api_error_ratio:rate5m", "legendFormat": "5m"},
|
||||
{"refId": "B", "expr": "messenger:api_error_ratio:rate1m", "legendFormat": "1m"}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 4,
|
||||
"type": "timeseries",
|
||||
"title": "API duration p50/p95/p99",
|
||||
"description": "Unit: seconds. histogram_quantile over the sum of bucket rates. Not an average of per-replica quantiles.",
|
||||
"datasource": {"type": "prometheus", "uid": "prometheus"},
|
||||
"gridPos": {"h": 8, "w": 12, "x": 0, "y": 12},
|
||||
"fieldConfig": {"defaults": {"unit": "s"}, "overrides": []},
|
||||
"targets": [
|
||||
{"refId": "A", "expr": "histogram_quantile(0.50, sum by (le) (rate(http_server_duration_seconds_bucket{service_name=\"messenger-api\",http_route!~\"/health/.*|unmatched\"}[5m])))", "legendFormat": "p50"},
|
||||
{"refId": "B", "expr": "histogram_quantile(0.95, sum by (le) (rate(http_server_duration_seconds_bucket{service_name=\"messenger-api\",http_route!~\"/health/.*|unmatched\"}[5m])))", "legendFormat": "p95"},
|
||||
{"refId": "C", "expr": "histogram_quantile(0.99, sum by (le) (rate(http_server_duration_seconds_bucket{service_name=\"messenger-api\",http_route!~\"/health/.*|unmatched\"}[5m])))", "legendFormat": "p99"}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 5,
|
||||
"type": "timeseries",
|
||||
"title": "Jobs by outcome",
|
||||
"description": "Unit: jobs per second. outcome is success, failed, or retry. job_type is attachment.process.v1.",
|
||||
"datasource": {"type": "prometheus", "uid": "prometheus"},
|
||||
"gridPos": {"h": 8, "w": 12, "x": 12, "y": 12},
|
||||
"fieldConfig": {"defaults": {"unit": "reqps"}, "overrides": []},
|
||||
"targets": [
|
||||
{"refId": "A", "expr": "sum by (outcome) (rate(messenger_jobs_total[1m]))", "legendFormat": "{{outcome}}"}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 6,
|
||||
"type": "timeseries",
|
||||
"title": "Worker job duration p95",
|
||||
"description": "Unit: seconds, from the job histogram.",
|
||||
"datasource": {"type": "prometheus", "uid": "prometheus"},
|
||||
"gridPos": {"h": 8, "w": 8, "x": 0, "y": 20},
|
||||
"fieldConfig": {"defaults": {"unit": "s"}, "overrides": []},
|
||||
"targets": [
|
||||
{"refId": "A", "expr": "histogram_quantile(0.95, sum by (le, outcome) (rate(messenger_job_duration_seconds_bucket[5m])))", "legendFormat": "{{outcome}}"}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 7,
|
||||
"type": "timeseries",
|
||||
"title": "Queue depth and oldest age",
|
||||
"description": "Depth is a count of queued+processing attachments. Age is seconds since the oldest of those rows was accepted. max() avoids double-counting the two API replicas.",
|
||||
"datasource": {"type": "prometheus", "uid": "prometheus"},
|
||||
"gridPos": {"h": 8, "w": 8, "x": 8, "y": 20},
|
||||
"fieldConfig": {"defaults": {"unit": "short"}, "overrides": [{"matcher": {"id": "byName", "options": "age"}, "properties": [{"id": "unit", "value": "s"}]}]},
|
||||
"targets": [
|
||||
{"refId": "A", "expr": "max(messenger_queue_depth{queue=\"attachment.process.v1\"})", "legendFormat": "depth"},
|
||||
{"refId": "B", "expr": "max(messenger_queue_oldest_age_seconds{queue=\"attachment.process.v1\"})", "legendFormat": "age"}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 8,
|
||||
"type": "timeseries",
|
||||
"title": "Time to ready p95",
|
||||
"description": "Unit: seconds from durable acceptance to ready. Completed jobs only.",
|
||||
"datasource": {"type": "prometheus", "uid": "prometheus"},
|
||||
"gridPos": {"h": 8, "w": 8, "x": 16, "y": 20},
|
||||
"fieldConfig": {"defaults": {"unit": "s"}, "overrides": []},
|
||||
"targets": [
|
||||
{"refId": "A", "expr": "histogram_quantile(0.95, sum by (le) (rate(messenger_attachment_time_to_ready_seconds_bucket[15m])))", "legendFormat": "p95"}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 9,
|
||||
"type": "timeseries",
|
||||
"title": "DB pool used and waiting",
|
||||
"description": "Unit: connections. Summed across processes. waiting is requests blocked on the pool.",
|
||||
"datasource": {"type": "prometheus", "uid": "prometheus"},
|
||||
"gridPos": {"h": 8, "w": 8, "x": 0, "y": 28},
|
||||
"fieldConfig": {"defaults": {"unit": "short"}, "overrides": []},
|
||||
"targets": [
|
||||
{"refId": "A", "expr": "sum(messenger_db_pool_used)", "legendFormat": "used"},
|
||||
{"refId": "B", "expr": "sum(messenger_db_pool_waiting)", "legendFormat": "waiting"}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 10,
|
||||
"type": "timeseries",
|
||||
"title": "Worker saturation and consumers",
|
||||
"description": "busy/capacity are counts inside the worker. consumers is the RabbitMQ consumer count observed by the API.",
|
||||
"datasource": {"type": "prometheus", "uid": "prometheus"},
|
||||
"gridPos": {"h": 8, "w": 8, "x": 8, "y": 28},
|
||||
"fieldConfig": {"defaults": {"unit": "short"}, "overrides": []},
|
||||
"targets": [
|
||||
{"refId": "A", "expr": "max(messenger_worker_busy)", "legendFormat": "busy"},
|
||||
{"refId": "B", "expr": "max(messenger_worker_capacity)", "legendFormat": "capacity"},
|
||||
{"refId": "C", "expr": "max(messenger_worker_consumers{service_name=\"messenger-api\"})", "legendFormat": "consumers"}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 11,
|
||||
"type": "timeseries",
|
||||
"title": "Process CPU and memory",
|
||||
"description": "CPU unit is process CPU-seconds per wall second (can exceed 1). Memory unit is bytes of RSS.",
|
||||
"datasource": {"type": "prometheus", "uid": "prometheus"},
|
||||
"gridPos": {"h": 8, "w": 8, "x": 16, "y": 28},
|
||||
"fieldConfig": {"defaults": {"unit": "short"}, "overrides": []},
|
||||
"targets": [
|
||||
{"refId": "A", "expr": "max by (service_name) (messenger_process_cpu_utilization)", "legendFormat": "cpu {{service_name}}"},
|
||||
{"refId": "B", "expr": "max by (service_name) (messenger_process_memory_bytes)", "legendFormat": "rss {{service_name}}"}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 12,
|
||||
"type": "timeseries",
|
||||
"title": "DB duration p95",
|
||||
"description": "Unit: seconds. Includes an injected db_slow fault. Compare with the server span to separate a slow database from a slow handler.",
|
||||
"datasource": {"type": "prometheus", "uid": "prometheus"},
|
||||
"gridPos": {"h": 8, "w": 12, "x": 0, "y": 36},
|
||||
"fieldConfig": {"defaults": {"unit": "s"}, "overrides": []},
|
||||
"targets": [
|
||||
{"refId": "A", "expr": "histogram_quantile(0.95, sum by (le) (rate(messenger_db_duration_seconds_bucket[5m])))", "legendFormat": "db p95"}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 13,
|
||||
"type": "table",
|
||||
"title": "Prometheus alert state",
|
||||
"description": "Local firing/pending state. No external notification channel is configured.",
|
||||
"datasource": {"type": "prometheus", "uid": "prometheus"},
|
||||
"gridPos": {"h": 8, "w": 12, "x": 12, "y": 36},
|
||||
"targets": [
|
||||
{"refId": "A", "expr": "ALERTS{alertstate=~\"firing|pending\"}", "instant": true, "format": "table"}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 14,
|
||||
"type": "logs",
|
||||
"title": "API and worker logs",
|
||||
"datasource": {"type": "loki", "uid": "loki"},
|
||||
"gridPos": {"h": 10, "w": 24, "x": 0, "y": 44},
|
||||
"targets": [
|
||||
{"refId": "A", "expr": "{service_name=~\"messenger-api|messenger-worker\"}"}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
apiVersion: 1
|
||||
|
||||
providers:
|
||||
- name: messenger
|
||||
orgId: 1
|
||||
folder: Messenger
|
||||
type: file
|
||||
disableDeletion: false
|
||||
updateIntervalSeconds: 30
|
||||
allowUiUpdates: false
|
||||
options:
|
||||
path: /var/lib/grafana/dashboards
|
||||
@@ -0,0 +1,53 @@
|
||||
apiVersion: 1
|
||||
|
||||
datasources:
|
||||
- name: Prometheus
|
||||
uid: prometheus
|
||||
type: prometheus
|
||||
access: proxy
|
||||
url: https://prometheus:9090
|
||||
isDefault: true
|
||||
editable: false
|
||||
jsonData:
|
||||
timeInterval: 5s
|
||||
tlsAuthWithCACert: true
|
||||
serverName: prometheus
|
||||
secureJsonData:
|
||||
tlsCACert: $__file{/etc/grafana/certs/ca.crt}
|
||||
- name: Loki
|
||||
uid: loki
|
||||
type: loki
|
||||
access: proxy
|
||||
url: https://loki:3100
|
||||
editable: false
|
||||
jsonData:
|
||||
tlsAuthWithCACert: true
|
||||
serverName: loki
|
||||
derivedFields:
|
||||
- name: TraceID
|
||||
matcherRegex: "\"trace_id\":\"([0-9a-f]+)\""
|
||||
url: "$${__value.raw}"
|
||||
datasourceUid: tempo
|
||||
urlDisplayLabel: View trace
|
||||
secureJsonData:
|
||||
tlsCACert: $__file{/etc/grafana/certs/ca.crt}
|
||||
- name: Tempo
|
||||
uid: tempo
|
||||
type: tempo
|
||||
access: proxy
|
||||
url: https://tempo:3200
|
||||
editable: false
|
||||
jsonData:
|
||||
tlsAuthWithCACert: true
|
||||
serverName: tempo
|
||||
tracesToLogsV2:
|
||||
datasourceUid: loki
|
||||
filterByTraceID: true
|
||||
serviceMap:
|
||||
datasourceUid: prometheus
|
||||
nodeGraph:
|
||||
enabled: true
|
||||
lokiSearch:
|
||||
datasourceUid: loki
|
||||
secureJsonData:
|
||||
tlsCACert: $__file{/etc/grafana/certs/ca.crt}
|
||||
@@ -0,0 +1,44 @@
|
||||
auth_enabled: false
|
||||
|
||||
server:
|
||||
http_listen_address: 0.0.0.0
|
||||
http_listen_port: 3100
|
||||
grpc_listen_address: 127.0.0.1
|
||||
grpc_listen_port: 9096
|
||||
log_level: warn
|
||||
http_tls_config:
|
||||
cert_file: /certs/loki.crt
|
||||
key_file: /certs/loki.key
|
||||
|
||||
common:
|
||||
instance_addr: 127.0.0.1
|
||||
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:
|
||||
allow_structured_metadata: true
|
||||
volume_enabled: true
|
||||
reject_old_samples: false
|
||||
ingestion_rate_mb: 8
|
||||
ingestion_burst_size_mb: 16
|
||||
max_query_series: 500
|
||||
|
||||
analytics:
|
||||
reporting_enabled: false
|
||||
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"Version": "2012-10-17",
|
||||
"Statement": [
|
||||
{
|
||||
"Effect": "Allow",
|
||||
"Action": ["s3:GetObject", "s3:PutObject", "s3:DeleteObject"],
|
||||
"Resource": ["arn:aws:s3:::messenger-attachments/staging/*"]
|
||||
},
|
||||
{
|
||||
"Effect": "Allow",
|
||||
"Action": ["s3:GetObject"],
|
||||
"Resource": [
|
||||
"arn:aws:s3:::messenger-attachments/originals/*",
|
||||
"arn:aws:s3:::messenger-attachments/variants/*"
|
||||
]
|
||||
},
|
||||
{
|
||||
"Effect": "Allow",
|
||||
"Action": ["s3:ListBucket"],
|
||||
"Resource": ["arn:aws:s3:::messenger-attachments"],
|
||||
"Condition": { "StringLike": { "s3:prefix": ["staging/*", "originals/*", "variants/*"] } }
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"Version": "2012-10-17",
|
||||
"Statement": [
|
||||
{
|
||||
"Effect": "Allow",
|
||||
"Action": ["s3:*"],
|
||||
"Resource": ["arn:aws:s3:::messenger-attachments", "arn:aws:s3:::messenger-attachments/*"]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"Version": "2012-10-17",
|
||||
"Statement": [
|
||||
{
|
||||
"Effect": "Allow",
|
||||
"Action": ["s3:GetObject", "s3:DeleteObject"],
|
||||
"Resource": ["arn:aws:s3:::messenger-attachments/staging/*"]
|
||||
},
|
||||
{
|
||||
"Effect": "Allow",
|
||||
"Action": ["s3:GetObject", "s3:PutObject"],
|
||||
"Resource": [
|
||||
"arn:aws:s3:::messenger-attachments/originals/*",
|
||||
"arn:aws:s3:::messenger-attachments/variants/*"
|
||||
]
|
||||
},
|
||||
{
|
||||
"Effect": "Allow",
|
||||
"Action": ["s3:ListBucket"],
|
||||
"Resource": ["arn:aws:s3:::messenger-attachments"],
|
||||
"Condition": { "StringLike": { "s3:prefix": ["staging/*", "originals/*", "variants/*"] } }
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
upstream messenger_api {
|
||||
server api-1:8443 max_fails=2 fail_timeout=5s;
|
||||
server api-2:8443 max_fails=2 fail_timeout=5s;
|
||||
}
|
||||
|
||||
server {
|
||||
listen 8443 ssl;
|
||||
server_name localhost;
|
||||
|
||||
ssl_certificate /certs/ingress.crt;
|
||||
ssl_certificate_key /certs/ingress.key;
|
||||
ssl_protocols TLSv1.2 TLSv1.3;
|
||||
ssl_prefer_server_ciphers off;
|
||||
|
||||
proxy_connect_timeout 2s;
|
||||
proxy_send_timeout 30s;
|
||||
proxy_read_timeout 60s;
|
||||
proxy_next_upstream error timeout http_502 http_503 non_idempotent;
|
||||
proxy_next_upstream_tries 2;
|
||||
|
||||
location / {
|
||||
proxy_pass https://messenger_api;
|
||||
proxy_ssl_certificate /certs/lb.crt;
|
||||
proxy_ssl_certificate_key /certs/lb.key;
|
||||
proxy_ssl_trusted_certificate /certs/ca.crt;
|
||||
proxy_ssl_verify on;
|
||||
proxy_ssl_name messenger_api;
|
||||
proxy_ssl_server_name on;
|
||||
proxy_ssl_protocols TLSv1.2 TLSv1.3;
|
||||
proxy_ssl_session_reuse off;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header Connection "";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
worker_processes 1;
|
||||
error_log /dev/stderr warn;
|
||||
pid /tmp/nginx.pid;
|
||||
|
||||
events {
|
||||
worker_connections 256;
|
||||
}
|
||||
|
||||
http {
|
||||
access_log off;
|
||||
map_hash_bucket_size 128;
|
||||
client_max_body_size 11m;
|
||||
proxy_http_version 1.1;
|
||||
include /etc/nginx/conf.d/*.conf;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
include /etc/nginx/serials.conf;
|
||||
|
||||
server {
|
||||
listen 4318 ssl;
|
||||
server_name otel-edge;
|
||||
|
||||
ssl_certificate /certs/server.crt;
|
||||
ssl_certificate_key /certs/server.key;
|
||||
ssl_client_certificate /certs/ca.crt;
|
||||
ssl_verify_client on;
|
||||
ssl_verify_depth 2;
|
||||
ssl_protocols TLSv1.2 TLSv1.3;
|
||||
|
||||
location / {
|
||||
if ($otel_cn_ok = 0) { return 403; }
|
||||
if ($otel_serial_ok = 0) { return 403; }
|
||||
resolver 127.0.0.11 ipv6=off valid=10s;
|
||||
set $otel_upstream otel-collector:4318;
|
||||
proxy_pass http://$otel_upstream;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header Connection "";
|
||||
proxy_read_timeout 10s;
|
||||
proxy_send_timeout 10s;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
ui = false
|
||||
log_level = "warn"
|
||||
|
||||
listener "tcp" {
|
||||
address = "0.0.0.0:8200"
|
||||
tls_cert_file = "/openbao/tls/server.crt"
|
||||
tls_key_file = "/openbao/tls/server.key"
|
||||
tls_client_ca_file = "/openbao/tls/ca.crt"
|
||||
tls_require_and_verify_client_cert = true
|
||||
tls_min_version = "tls12"
|
||||
}
|
||||
|
||||
storage "file" {
|
||||
path = "/openbao/data"
|
||||
}
|
||||
|
||||
api_addr = "https://openbao:8200"
|
||||
cluster_addr = "https://openbao:8201"
|
||||
@@ -0,0 +1,27 @@
|
||||
path "secret/data/api/*" {
|
||||
capabilities = ["read"]
|
||||
}
|
||||
|
||||
path "secret/metadata/api/*" {
|
||||
capabilities = ["read", "list"]
|
||||
}
|
||||
|
||||
path "secret/data/worker/*" {
|
||||
capabilities = ["deny"]
|
||||
}
|
||||
|
||||
path "secret/metadata/worker/*" {
|
||||
capabilities = ["deny"]
|
||||
}
|
||||
|
||||
path "auth/token/renew-self" {
|
||||
capabilities = ["update"]
|
||||
}
|
||||
|
||||
path "auth/token/lookup-self" {
|
||||
capabilities = ["read"]
|
||||
}
|
||||
|
||||
path "sys/*" {
|
||||
capabilities = ["deny"]
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
path "secret/data/worker/*" {
|
||||
capabilities = ["read"]
|
||||
}
|
||||
|
||||
path "secret/metadata/worker/*" {
|
||||
capabilities = ["read", "list"]
|
||||
}
|
||||
|
||||
path "secret/data/api/*" {
|
||||
capabilities = ["deny"]
|
||||
}
|
||||
|
||||
path "secret/metadata/api/*" {
|
||||
capabilities = ["deny"]
|
||||
}
|
||||
|
||||
path "auth/token/renew-self" {
|
||||
capabilities = ["update"]
|
||||
}
|
||||
|
||||
path "auth/token/lookup-self" {
|
||||
capabilities = ["read"]
|
||||
}
|
||||
|
||||
path "sys/*" {
|
||||
capabilities = ["deny"]
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
extensions:
|
||||
health_check:
|
||||
endpoint: 0.0.0.0:13133
|
||||
|
||||
receivers:
|
||||
otlp:
|
||||
protocols:
|
||||
http:
|
||||
endpoint: 0.0.0.0:4318
|
||||
|
||||
processors:
|
||||
memory_limiter:
|
||||
check_interval: 1s
|
||||
limit_mib: 160
|
||||
spike_limit_mib: 40
|
||||
attributes/redact:
|
||||
actions:
|
||||
- key: url.full
|
||||
action: delete
|
||||
- key: url.query
|
||||
action: delete
|
||||
- key: url.path
|
||||
action: delete
|
||||
- key: http.url
|
||||
action: delete
|
||||
- key: http.target
|
||||
action: delete
|
||||
- key: db.statement
|
||||
action: delete
|
||||
- key: db.query.text
|
||||
action: delete
|
||||
- key: http.request.header.authorization
|
||||
action: delete
|
||||
- key: http.request.header.cookie
|
||||
action: delete
|
||||
batch:
|
||||
timeout: 2s
|
||||
send_batch_size: 256
|
||||
send_batch_max_size: 512
|
||||
|
||||
exporters:
|
||||
otlp/tempo:
|
||||
endpoint: tempo:4317
|
||||
tls:
|
||||
insecure: false
|
||||
ca_file: /certs/ca.crt
|
||||
cert_file: /certs/collector.crt
|
||||
key_file: /certs/collector.key
|
||||
server_name_override: tempo
|
||||
timeout: 5s
|
||||
retry_on_failure:
|
||||
enabled: true
|
||||
initial_interval: 1s
|
||||
max_interval: 15s
|
||||
max_elapsed_time: 30s
|
||||
sending_queue:
|
||||
enabled: true
|
||||
num_consumers: 2
|
||||
queue_size: 200
|
||||
otlphttp/loki:
|
||||
logs_endpoint: https://loki:3100/otlp/v1/logs
|
||||
tls:
|
||||
insecure: false
|
||||
ca_file: /certs/ca.crt
|
||||
cert_file: /certs/collector.crt
|
||||
key_file: /certs/collector.key
|
||||
timeout: 5s
|
||||
retry_on_failure:
|
||||
enabled: true
|
||||
initial_interval: 1s
|
||||
max_interval: 15s
|
||||
max_elapsed_time: 30s
|
||||
sending_queue:
|
||||
enabled: true
|
||||
num_consumers: 2
|
||||
queue_size: 200
|
||||
prometheus:
|
||||
endpoint: 0.0.0.0:8889
|
||||
tls:
|
||||
cert_file: /certs/collector.crt
|
||||
key_file: /certs/collector.key
|
||||
resource_to_telemetry_conversion:
|
||||
enabled: true
|
||||
metric_expiration: 180s
|
||||
|
||||
service:
|
||||
extensions: [health_check]
|
||||
telemetry:
|
||||
metrics:
|
||||
address: 127.0.0.1:8888
|
||||
pipelines:
|
||||
traces:
|
||||
receivers: [otlp]
|
||||
processors: [memory_limiter, attributes/redact, batch]
|
||||
exporters: [otlp/tempo]
|
||||
metrics:
|
||||
receivers: [otlp]
|
||||
processors: [memory_limiter, attributes/redact, batch]
|
||||
exporters: [prometheus]
|
||||
logs:
|
||||
receivers: [otlp]
|
||||
processors: [memory_limiter, attributes/redact, batch]
|
||||
exporters: [otlphttp/loki]
|
||||
@@ -0,0 +1,13 @@
|
||||
REVOKE ALL ON SCHEMA public FROM PUBLIC;
|
||||
GRANT USAGE ON SCHEMA public TO api_login, worker_login;
|
||||
|
||||
GRANT SELECT, INSERT, UPDATE ON
|
||||
users, sessions, chats, chat_members, messages,
|
||||
attachments, attachment_variants, message_attachments,
|
||||
idempotency, outbox
|
||||
TO api_login;
|
||||
|
||||
GRANT SELECT, UPDATE ON attachments TO worker_login;
|
||||
GRANT SELECT, INSERT, UPDATE ON attachment_variants TO worker_login;
|
||||
|
||||
REVOKE ALL ON users, sessions, chats, chat_members, messages, idempotency, outbox FROM worker_login;
|
||||
@@ -0,0 +1,7 @@
|
||||
FROM postgres:16.6-alpine
|
||||
|
||||
COPY entrypoint.sh /usr/local/bin/lab-entrypoint.sh
|
||||
RUN chmod 755 /usr/local/bin/lab-entrypoint.sh
|
||||
|
||||
ENTRYPOINT ["/usr/local/bin/lab-entrypoint.sh"]
|
||||
CMD ["postgres"]
|
||||
@@ -0,0 +1,16 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
mkdir -p /var/lib/postgresql/certs
|
||||
cp /certs-src/server.crt /var/lib/postgresql/certs/server.crt
|
||||
cp /certs-src/server.key /var/lib/postgresql/certs/server.key
|
||||
cp /certs-src/ca.crt /var/lib/postgresql/certs/ca.crt
|
||||
chown postgres:postgres /var/lib/postgresql/certs/server.crt /var/lib/postgresql/certs/server.key /var/lib/postgresql/certs/ca.crt
|
||||
chmod 600 /var/lib/postgresql/certs/server.key
|
||||
exec docker-entrypoint.sh postgres \
|
||||
-c ssl=on \
|
||||
-c ssl_cert_file=/var/lib/postgresql/certs/server.crt \
|
||||
-c ssl_key_file=/var/lib/postgresql/certs/server.key \
|
||||
-c ssl_ca_file=/var/lib/postgresql/certs/ca.crt \
|
||||
-c ssl_min_protocol_version=TLSv1.2 \
|
||||
-c hba_file=/etc/postgres/pg_hba.conf \
|
||||
-c password_encryption=scram-sha-256
|
||||
@@ -0,0 +1,3 @@
|
||||
local all all trust
|
||||
hostssl all all all scram-sha-256
|
||||
hostnossl all all all reject
|
||||
@@ -0,0 +1,16 @@
|
||||
global:
|
||||
scrape_interval: 5s
|
||||
evaluation_interval: 5s
|
||||
scrape_timeout: 4s
|
||||
|
||||
rule_files:
|
||||
- /etc/prometheus/rules.yml
|
||||
|
||||
scrape_configs:
|
||||
- job_name: otel-collector
|
||||
scheme: https
|
||||
tls_config:
|
||||
ca_file: /etc/prometheus/ca.crt
|
||||
server_name: otel-collector
|
||||
static_configs:
|
||||
- targets: ["otel-collector:8889"]
|
||||
@@ -0,0 +1,96 @@
|
||||
groups:
|
||||
- name: messenger-sli
|
||||
interval: 5s
|
||||
rules:
|
||||
- record: messenger:api_requests:rate1m
|
||||
expr: sum(rate(http_server_requests_total{service_name="messenger-api",http_route!~"/health/.*|unmatched"}[1m]))
|
||||
- record: messenger:api_5xx:rate1m
|
||||
expr: sum(rate(http_server_requests_total{service_name="messenger-api",http_route!~"/health/.*|unmatched",http_response_status_class="5xx"}[1m]))
|
||||
- record: messenger:api_error_ratio:rate1m
|
||||
expr: messenger:api_5xx:rate1m / clamp_min(messenger:api_requests:rate1m, 1e-9)
|
||||
- record: messenger:api_requests:rate5m
|
||||
expr: sum(rate(http_server_requests_total{service_name="messenger-api",http_route!~"/health/.*|unmatched"}[5m]))
|
||||
- record: messenger:api_5xx:rate5m
|
||||
expr: sum(rate(http_server_requests_total{service_name="messenger-api",http_route!~"/health/.*|unmatched",http_response_status_class="5xx"}[5m]))
|
||||
- record: messenger:api_error_ratio:rate5m
|
||||
expr: messenger:api_5xx:rate5m / clamp_min(messenger:api_requests:rate5m, 1e-9)
|
||||
- record: messenger:api_requests:rate15m
|
||||
expr: sum(rate(http_server_requests_total{service_name="messenger-api",http_route!~"/health/.*|unmatched"}[15m]))
|
||||
- record: messenger:api_5xx:rate15m
|
||||
expr: sum(rate(http_server_requests_total{service_name="messenger-api",http_route!~"/health/.*|unmatched",http_response_status_class="5xx"}[15m]))
|
||||
- record: messenger:api_error_ratio:rate15m
|
||||
expr: messenger:api_5xx:rate15m / clamp_min(messenger:api_requests:rate15m, 1e-9)
|
||||
|
||||
- name: messenger-alerts
|
||||
interval: 5s
|
||||
rules:
|
||||
- alert: ApiHighErrorRate
|
||||
expr: messenger:api_error_ratio:rate5m > 0.05 and messenger:api_requests:rate5m > 0.2
|
||||
for: 1m
|
||||
labels:
|
||||
severity: page
|
||||
slo: api-availability
|
||||
annotations:
|
||||
summary: API business 5xx ratio is above 5%
|
||||
description: Numerator is 5xx on business routes. Denominator is all business requests. Health checks and 4xx are excluded. Window 5m, for 1m.
|
||||
runbook: docs/runbooks/api-error-budget.md
|
||||
- alert: ApiErrorBudgetFastBurn
|
||||
expr: messenger:api_error_ratio:rate1m > 0.144 and messenger:api_error_ratio:rate5m > 0.144 and messenger:api_requests:rate1m > 0.2
|
||||
for: 30s
|
||||
labels:
|
||||
severity: page
|
||||
slo: api-availability
|
||||
burn: fast
|
||||
annotations:
|
||||
summary: Fast multi-window burn of the 1% API error budget
|
||||
description: Both the 1m and 5m error ratios exceed 14.4% (14.4x a 1% budget). A sub-minute spike does not satisfy the 5m window when healthy traffic is present.
|
||||
runbook: docs/runbooks/api-error-budget.md
|
||||
- alert: ApiErrorBudgetSlowBurn
|
||||
expr: messenger:api_error_ratio:rate5m > 0.06 and messenger:api_error_ratio:rate15m > 0.06 and messenger:api_requests:rate5m > 0.2
|
||||
for: 1m
|
||||
labels:
|
||||
severity: ticket
|
||||
slo: api-availability
|
||||
burn: slow
|
||||
annotations:
|
||||
summary: Slow multi-window burn of the API error budget
|
||||
description: 5m and 15m error ratios exceed 6% (6x a 1% budget). This catches a long mild degradation that the fast burn may miss.
|
||||
runbook: docs/runbooks/api-error-budget.md
|
||||
- alert: QueueLagHigh
|
||||
expr: max(messenger_queue_oldest_age_seconds{queue="attachment.process.v1"}) > 30
|
||||
for: 1m
|
||||
labels:
|
||||
severity: page
|
||||
slo: time-to-ready
|
||||
annotations:
|
||||
summary: Oldest attachment job is older than 30s
|
||||
description: Backlog age is not processing latency. It grows when the worker is stopped or cannot finish jobs. Unit is seconds.
|
||||
runbook: docs/runbooks/queue-lag.md
|
||||
- alert: WorkerConsumersZero
|
||||
expr: max(messenger_worker_consumers{service_name="messenger-api",queue="attachment.process.v1"}) == 0
|
||||
for: 1m
|
||||
labels:
|
||||
severity: page
|
||||
annotations:
|
||||
summary: RabbitMQ has no attachment consumers
|
||||
description: The API polls the RabbitMQ management API, so this series stays fresh after the worker process stops.
|
||||
runbook: docs/runbooks/queue-lag.md
|
||||
- alert: AttachmentReadyLatencyHigh
|
||||
expr: histogram_quantile(0.95, sum by (le) (rate(messenger_attachment_time_to_ready_seconds_bucket[15m]))) > 10
|
||||
for: 2m
|
||||
labels:
|
||||
severity: ticket
|
||||
slo: time-to-ready
|
||||
annotations:
|
||||
summary: p95 time to ready is above 10s
|
||||
description: Histogram of completed jobs only. A stalled queue does not move this SLO; use QueueLagHigh for that.
|
||||
runbook: docs/runbooks/time-to-ready.md
|
||||
- alert: DatabaseUnready
|
||||
expr: min(messenger_db_up) == 0
|
||||
for: 30s
|
||||
labels:
|
||||
severity: page
|
||||
annotations:
|
||||
summary: An API or worker process cannot use PostgreSQL
|
||||
description: Distinguish this from a slow handler by comparing the db.transaction span with the server span.
|
||||
runbook: docs/runbooks/db-latency.md
|
||||
@@ -0,0 +1,4 @@
|
||||
tls_server_config:
|
||||
cert_file: /certs/prometheus.crt
|
||||
key_file: /certs/prometheus.key
|
||||
min_version: TLS12
|
||||
@@ -0,0 +1,7 @@
|
||||
FROM rabbitmq:3.13.7-management-alpine
|
||||
|
||||
COPY entrypoint.sh /usr/local/bin/lab-entrypoint.sh
|
||||
RUN chmod 755 /usr/local/bin/lab-entrypoint.sh \
|
||||
&& rabbitmq-plugins enable --offline rabbitmq_auth_mechanism_ssl
|
||||
|
||||
ENTRYPOINT ["/usr/local/bin/lab-entrypoint.sh"]
|
||||
@@ -0,0 +1,33 @@
|
||||
{
|
||||
"vhosts": [{ "name": "/" }],
|
||||
"exchanges": [
|
||||
{
|
||||
"name": "attachment.process",
|
||||
"vhost": "/",
|
||||
"type": "direct",
|
||||
"durable": true,
|
||||
"auto_delete": false,
|
||||
"internal": false,
|
||||
"arguments": {}
|
||||
}
|
||||
],
|
||||
"queues": [
|
||||
{
|
||||
"name": "attachment.process.v1",
|
||||
"vhost": "/",
|
||||
"durable": true,
|
||||
"auto_delete": false,
|
||||
"arguments": {}
|
||||
}
|
||||
],
|
||||
"bindings": [
|
||||
{
|
||||
"source": "attachment.process",
|
||||
"vhost": "/",
|
||||
"destination": "attachment.process.v1",
|
||||
"destination_type": "queue",
|
||||
"routing_key": "attachment.process.v1",
|
||||
"arguments": {}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
mkdir -p /etc/rabbitmq/certs
|
||||
cp /certs-src/ca.crt /etc/rabbitmq/certs/ca.crt
|
||||
cp /certs-src/server.crt /etc/rabbitmq/certs/server.crt
|
||||
cp /certs-src/server.key /etc/rabbitmq/certs/server.key
|
||||
chown -R rabbitmq:rabbitmq /etc/rabbitmq/certs
|
||||
chmod 640 /etc/rabbitmq/certs/server.key
|
||||
exec docker-entrypoint.sh rabbitmq-server
|
||||
@@ -0,0 +1,17 @@
|
||||
listeners.tcp = none
|
||||
listeners.ssl.default = 5671
|
||||
management.tcp.port = 15672
|
||||
management.tcp.ip = 127.0.0.1
|
||||
prometheus.tcp.port = 15692
|
||||
prometheus.tcp.ip = 127.0.0.1
|
||||
ssl_options.cacertfile = /etc/rabbitmq/certs/ca.crt
|
||||
ssl_options.certfile = /etc/rabbitmq/certs/server.crt
|
||||
ssl_options.keyfile = /etc/rabbitmq/certs/server.key
|
||||
ssl_options.verify = verify_peer
|
||||
ssl_options.fail_if_no_peer_cert = true
|
||||
ssl_options.versions.1 = tlsv1.2
|
||||
ssl_options.versions.2 = tlsv1.3
|
||||
auth_mechanisms.1 = EXTERNAL
|
||||
ssl_cert_login_from = common_name
|
||||
management.load_definitions = /etc/rabbitmq/definitions.json
|
||||
log.console.level = warning
|
||||
@@ -0,0 +1,41 @@
|
||||
stream_over_http_enabled: true
|
||||
|
||||
server:
|
||||
http_listen_address: 0.0.0.0
|
||||
http_listen_port: 3200
|
||||
grpc_listen_address: 127.0.0.1
|
||||
grpc_listen_port: 9096
|
||||
log_level: warn
|
||||
http_tls_config:
|
||||
cert_file: /certs/tempo.crt
|
||||
key_file: /certs/tempo.key
|
||||
|
||||
distributor:
|
||||
receivers:
|
||||
otlp:
|
||||
protocols:
|
||||
grpc:
|
||||
endpoint: 0.0.0.0:4317
|
||||
tls:
|
||||
cert_file: /certs/tempo.crt
|
||||
key_file: /certs/tempo.key
|
||||
min_version: "1.2"
|
||||
|
||||
ingester:
|
||||
trace_idle_period: 10s
|
||||
max_block_duration: 5m
|
||||
|
||||
compactor:
|
||||
compaction:
|
||||
block_retention: 48h
|
||||
|
||||
storage:
|
||||
trace:
|
||||
backend: local
|
||||
wal:
|
||||
path: /var/tempo/wal
|
||||
local:
|
||||
path: /var/tempo/traces
|
||||
|
||||
querier:
|
||||
max_concurrent_queries: 4
|
||||
@@ -0,0 +1,14 @@
|
||||
bind 0.0.0.0
|
||||
port 0
|
||||
tls-port 6379
|
||||
tls-cert-file /certs/server.crt
|
||||
tls-key-file /certs/server.key
|
||||
tls-ca-cert-file /certs/ca.crt
|
||||
tls-auth-clients no
|
||||
tls-protocols "TLSv1.2 TLSv1.3"
|
||||
aclfile /etc/valkey/users.acl
|
||||
dir /data
|
||||
appendonly yes
|
||||
appendfsync everysec
|
||||
protected-mode no
|
||||
save ""
|
||||
Reference in New Issue
Block a user