feat: complete lab 7 for grade 4
Skeleton contracts / contracts (pull_request) Blocked by required conditions
Skeleton contracts / contracts (pull_request) Blocked by required conditions
This commit is contained in:
@@ -0,0 +1,682 @@
|
||||
{
|
||||
"title": "Messenger · Lab 6",
|
||||
"uid": "messenger-lab6",
|
||||
"schemaVersion": 39,
|
||||
"version": 1,
|
||||
"refresh": "5s",
|
||||
"time": {
|
||||
"from": "now-15m",
|
||||
"to": "now"
|
||||
},
|
||||
"panels": [
|
||||
{
|
||||
"id": 1,
|
||||
"title": "HTTP · запросов/с",
|
||||
"type": "timeseries",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"gridPos": {
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"w": 12,
|
||||
"h": 8
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"refId": "A",
|
||||
"expr": "sum(rate(lab_http_requests_total[1m]))",
|
||||
"legendFormat": "API",
|
||||
"exemplar": true
|
||||
}
|
||||
],
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"unit": "reqps"
|
||||
},
|
||||
"overrides": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"title": "HTTP · доля 5xx",
|
||||
"type": "timeseries",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"gridPos": {
|
||||
"x": 12,
|
||||
"y": 0,
|
||||
"w": 12,
|
||||
"h": 8
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"refId": "A",
|
||||
"expr": "lab:sli_api_bad:2m / lab:sli_api_total:2m",
|
||||
"legendFormat": "Публичный вход",
|
||||
"exemplar": true
|
||||
},
|
||||
{
|
||||
"refId": "B",
|
||||
"expr": "(sum(rate(lab_http_requests_total{status_class=\"5xx\"}[1m])) or 0 * sum(rate(lab_http_requests_total[1m]))) / sum(rate(lab_http_requests_total[1m]))",
|
||||
"legendFormat": "API",
|
||||
"exemplar": true
|
||||
}
|
||||
],
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"unit": "percentunit"
|
||||
},
|
||||
"overrides": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"title": "HTTP · задержка по всем репликам",
|
||||
"type": "timeseries",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"gridPos": {
|
||||
"x": 0,
|
||||
"y": 8,
|
||||
"w": 12,
|
||||
"h": 8
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"refId": "A",
|
||||
"expr": "histogram_quantile(0.5,sum by (le)(rate(lab_http_duration_seconds_bucket[1m])))",
|
||||
"legendFormat": "p50",
|
||||
"exemplar": true
|
||||
},
|
||||
{
|
||||
"refId": "B",
|
||||
"expr": "histogram_quantile(0.95,sum by (le)(rate(lab_http_duration_seconds_bucket[1m])))",
|
||||
"legendFormat": "p95",
|
||||
"exemplar": true
|
||||
},
|
||||
{
|
||||
"refId": "C",
|
||||
"expr": "histogram_quantile(0.99,sum by (le)(rate(lab_http_duration_seconds_bucket[1m])))",
|
||||
"legendFormat": "p99",
|
||||
"exemplar": true
|
||||
}
|
||||
],
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"unit": "s"
|
||||
},
|
||||
"overrides": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 4,
|
||||
"title": "Реплики и доступность",
|
||||
"type": "timeseries",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"gridPos": {
|
||||
"x": 12,
|
||||
"y": 8,
|
||||
"w": 12,
|
||||
"h": 8
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"refId": "A",
|
||||
"expr": "sum by (service_name)((lab_process_alive and on(service_instance_id) (time()-lab_process_heartbeat_seconds<20)))",
|
||||
"legendFormat": "{{service_name}}",
|
||||
"exemplar": true
|
||||
},
|
||||
{
|
||||
"refId": "B",
|
||||
"expr": "sum(haproxy_server_status{proxy=\"replicas\",state=\"UP\"})",
|
||||
"legendFormat": "Готовые API по HAProxy",
|
||||
"exemplar": true
|
||||
}
|
||||
],
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"unit": "short"
|
||||
},
|
||||
"overrides": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 5,
|
||||
"title": "Очередь · queued",
|
||||
"type": "timeseries",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"gridPos": {
|
||||
"x": 0,
|
||||
"y": 16,
|
||||
"w": 12,
|
||||
"h": 8
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"refId": "A",
|
||||
"expr": "max(lab_queue_depth)",
|
||||
"legendFormat": "queued",
|
||||
"exemplar": true
|
||||
}
|
||||
],
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"unit": "short"
|
||||
},
|
||||
"overrides": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 6,
|
||||
"title": "Старейшая незавершённая работа",
|
||||
"type": "timeseries",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"gridPos": {
|
||||
"x": 12,
|
||||
"y": 16,
|
||||
"w": 12,
|
||||
"h": 8
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"refId": "A",
|
||||
"expr": "max(lab_oldest_job_age_seconds)",
|
||||
"legendFormat": "queued или processing",
|
||||
"exemplar": true
|
||||
}
|
||||
],
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"unit": "s"
|
||||
},
|
||||
"overrides": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 7,
|
||||
"title": "Попытки worker · исходы/с",
|
||||
"type": "timeseries",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"gridPos": {
|
||||
"x": 0,
|
||||
"y": 24,
|
||||
"w": 12,
|
||||
"h": 8
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"refId": "A",
|
||||
"expr": "sum by (outcome)(rate(lab_job_results_total[1m]))",
|
||||
"legendFormat": "{{outcome}}",
|
||||
"exemplar": true
|
||||
}
|
||||
],
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"unit": "short"
|
||||
},
|
||||
"overrides": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 8,
|
||||
"title": "Worker · время попытки",
|
||||
"type": "timeseries",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"gridPos": {
|
||||
"x": 12,
|
||||
"y": 24,
|
||||
"w": 12,
|
||||
"h": 8
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"refId": "A",
|
||||
"expr": "histogram_quantile(0.5,sum by (le)(rate(lab_job_duration_seconds_bucket[1m])))",
|
||||
"legendFormat": "p50",
|
||||
"exemplar": true
|
||||
},
|
||||
{
|
||||
"refId": "B",
|
||||
"expr": "histogram_quantile(0.95,sum by (le)(rate(lab_job_duration_seconds_bucket[1m])))",
|
||||
"legendFormat": "p95",
|
||||
"exemplar": true
|
||||
},
|
||||
{
|
||||
"refId": "C",
|
||||
"expr": "histogram_quantile(0.99,sum by (le)(rate(lab_job_duration_seconds_bucket[1m])))",
|
||||
"legendFormat": "p99",
|
||||
"exemplar": true
|
||||
}
|
||||
],
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"unit": "s"
|
||||
},
|
||||
"overrides": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 9,
|
||||
"title": "Время до готовности · успешные",
|
||||
"type": "timeseries",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"gridPos": {
|
||||
"x": 0,
|
||||
"y": 32,
|
||||
"w": 12,
|
||||
"h": 8
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"refId": "A",
|
||||
"expr": "histogram_quantile(0.5,sum by (le)(rate(lab_time_to_ready_seconds_bucket[1m])))",
|
||||
"legendFormat": "p50",
|
||||
"exemplar": true
|
||||
},
|
||||
{
|
||||
"refId": "B",
|
||||
"expr": "histogram_quantile(0.95,sum by (le)(rate(lab_time_to_ready_seconds_bucket[1m])))",
|
||||
"legendFormat": "p95",
|
||||
"exemplar": true
|
||||
},
|
||||
{
|
||||
"refId": "C",
|
||||
"expr": "histogram_quantile(0.99,sum by (le)(rate(lab_time_to_ready_seconds_bucket[1m])))",
|
||||
"legendFormat": "p99",
|
||||
"exemplar": true
|
||||
}
|
||||
],
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"unit": "s"
|
||||
},
|
||||
"overrides": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 10,
|
||||
"title": "Worker · занятость и ёмкость",
|
||||
"type": "timeseries",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"gridPos": {
|
||||
"x": 12,
|
||||
"y": 32,
|
||||
"w": 12,
|
||||
"h": 8
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"refId": "A",
|
||||
"expr": "sum((lab_worker_busy and on(service_instance_id) (time()-lab_process_heartbeat_seconds<20))) or vector(0)",
|
||||
"legendFormat": "занято",
|
||||
"exemplar": true
|
||||
},
|
||||
{
|
||||
"refId": "B",
|
||||
"expr": "sum((lab_worker_capacity and on(service_instance_id) (time()-lab_process_heartbeat_seconds<20))) or vector(0)",
|
||||
"legendFormat": "ёмкость",
|
||||
"exemplar": true
|
||||
}
|
||||
],
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"unit": "short"
|
||||
},
|
||||
"overrides": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 11,
|
||||
"title": "PostgreSQL · пул",
|
||||
"type": "timeseries",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"gridPos": {
|
||||
"x": 0,
|
||||
"y": 40,
|
||||
"w": 12,
|
||||
"h": 8
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"refId": "A",
|
||||
"expr": "sum by (service_name)(lab_db_pool_used)",
|
||||
"legendFormat": "занято {{service_name}}",
|
||||
"exemplar": true
|
||||
},
|
||||
{
|
||||
"refId": "B",
|
||||
"expr": "sum by (service_name)(lab_db_pool_waiting)",
|
||||
"legendFormat": "ждут {{service_name}}",
|
||||
"exemplar": true
|
||||
},
|
||||
{
|
||||
"refId": "C",
|
||||
"expr": "sum by (service_name)(lab_db_pool_capacity)",
|
||||
"legendFormat": "лимит {{service_name}}",
|
||||
"exemplar": true
|
||||
}
|
||||
],
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"unit": "short"
|
||||
},
|
||||
"overrides": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 12,
|
||||
"title": "Пулы API · ожидание",
|
||||
"type": "timeseries",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"gridPos": {
|
||||
"x": 12,
|
||||
"y": 40,
|
||||
"w": 12,
|
||||
"h": 8
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"refId": "A",
|
||||
"expr": "max by (service_instance_id)(lab_db_pool_waiting{service_name=\"messenger-api\"})",
|
||||
"legendFormat": "{{service_instance_id}}",
|
||||
"exemplar": true
|
||||
}
|
||||
],
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"unit": "short"
|
||||
},
|
||||
"overrides": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 13,
|
||||
"title": "CPU · число ядер на процесс",
|
||||
"type": "timeseries",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"gridPos": {
|
||||
"x": 0,
|
||||
"y": 48,
|
||||
"w": 12,
|
||||
"h": 8
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"refId": "A",
|
||||
"expr": "rate(lab_process_cpu_seconds_total[1m])",
|
||||
"legendFormat": "{{service_name}} / {{service_instance_id}}",
|
||||
"exemplar": true
|
||||
}
|
||||
],
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"unit": "short"
|
||||
},
|
||||
"overrides": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 14,
|
||||
"title": "RAM · RSS процесса",
|
||||
"type": "timeseries",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"gridPos": {
|
||||
"x": 12,
|
||||
"y": 48,
|
||||
"w": 12,
|
||||
"h": 8
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"refId": "A",
|
||||
"expr": "lab_process_rss_bytes",
|
||||
"legendFormat": "{{service_name}} / {{service_instance_id}}",
|
||||
"exemplar": true
|
||||
},
|
||||
{
|
||||
"refId": "B",
|
||||
"expr": "otelcol_process_memory_rss_bytes",
|
||||
"legendFormat": "Collector",
|
||||
"exemplar": true
|
||||
}
|
||||
],
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"unit": "bytes"
|
||||
},
|
||||
"overrides": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 15,
|
||||
"title": "API и ready · SLI за 1 час",
|
||||
"type": "timeseries",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"gridPos": {
|
||||
"x": 0,
|
||||
"y": 56,
|
||||
"w": 12,
|
||||
"h": 8
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"refId": "A",
|
||||
"expr": "1-lab:sli_api_bad:1h/lab:sli_api_total:1h",
|
||||
"legendFormat": "API",
|
||||
"exemplar": true
|
||||
},
|
||||
{
|
||||
"refId": "B",
|
||||
"expr": "1-lab:sli_ready_bad:1h/lab:sli_ready_total:1h",
|
||||
"legendFormat": "Ready",
|
||||
"exemplar": true
|
||||
}
|
||||
],
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"unit": "percentunit"
|
||||
},
|
||||
"overrides": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 16,
|
||||
"title": "Расход бюджета · доля бюджета за 1 час",
|
||||
"type": "timeseries",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"gridPos": {
|
||||
"x": 12,
|
||||
"y": 56,
|
||||
"w": 12,
|
||||
"h": 8
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"refId": "A",
|
||||
"expr": "lab:burn_api:1h",
|
||||
"legendFormat": "API (цель 99%)",
|
||||
"exemplar": true
|
||||
},
|
||||
{
|
||||
"refId": "B",
|
||||
"expr": "lab:burn_ready:1h",
|
||||
"legendFormat": "Ready (цель 95%)",
|
||||
"exemplar": true
|
||||
}
|
||||
],
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"unit": "short"
|
||||
},
|
||||
"overrides": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 17,
|
||||
"title": "Collector · очередь экспорта",
|
||||
"type": "timeseries",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"gridPos": {
|
||||
"x": 0,
|
||||
"y": 64,
|
||||
"w": 12,
|
||||
"h": 8
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"refId": "A",
|
||||
"expr": "otelcol_exporter_queue_size",
|
||||
"legendFormat": "{{exporter}}",
|
||||
"exemplar": true
|
||||
},
|
||||
{
|
||||
"refId": "B",
|
||||
"expr": "otelcol_exporter_queue_capacity",
|
||||
"legendFormat": "лимит {{exporter}}",
|
||||
"exemplar": true
|
||||
}
|
||||
],
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"unit": "short"
|
||||
},
|
||||
"overrides": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 18,
|
||||
"title": "Collector · потери на экспорте",
|
||||
"type": "timeseries",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"gridPos": {
|
||||
"x": 12,
|
||||
"y": 64,
|
||||
"w": 12,
|
||||
"h": 8
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"refId": "A",
|
||||
"expr": "sum by (exporter)(increase(otelcol_exporter_send_failed_spans_total[1m]))",
|
||||
"legendFormat": "spans {{exporter}}",
|
||||
"exemplar": true
|
||||
},
|
||||
{
|
||||
"refId": "B",
|
||||
"expr": "sum by (exporter)(increase(otelcol_exporter_send_failed_log_records_total[1m]))",
|
||||
"legendFormat": "logs {{exporter}}",
|
||||
"exemplar": true
|
||||
}
|
||||
],
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"unit": "short"
|
||||
},
|
||||
"overrides": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 19,
|
||||
"title": "Активные оповещения",
|
||||
"type": "timeseries",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"gridPos": {
|
||||
"x": 0,
|
||||
"y": 72,
|
||||
"w": 12,
|
||||
"h": 8
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"refId": "A",
|
||||
"expr": "ALERTS",
|
||||
"legendFormat": "{{alertname}} {{alertstate}}",
|
||||
"exemplar": true
|
||||
}
|
||||
],
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"unit": "short"
|
||||
},
|
||||
"overrides": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 20,
|
||||
"title": "Связанные логи API / Worker",
|
||||
"type": "logs",
|
||||
"datasource": {
|
||||
"type": "loki",
|
||||
"uid": "loki"
|
||||
},
|
||||
"gridPos": {
|
||||
"x": 12,
|
||||
"y": 72,
|
||||
"w": 12,
|
||||
"h": 8
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"refId": "A",
|
||||
"expr": "{service_name=~\"messenger-api|messenger-worker\"}",
|
||||
"legendFormat": ""
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
apiVersion: 1
|
||||
providers:
|
||||
- name: messenger
|
||||
folder: Lab 6
|
||||
type: file
|
||||
options:
|
||||
path: /var/lib/grafana/dashboards
|
||||
@@ -0,0 +1,57 @@
|
||||
apiVersion: 1
|
||||
datasources:
|
||||
- name: Prometheus
|
||||
uid: prometheus
|
||||
type: prometheus
|
||||
access: proxy
|
||||
url: https://prometheus:9090
|
||||
isDefault: true
|
||||
secureJsonData:
|
||||
tlsCACert: $LAB_CA
|
||||
tlsClientCert: $LAB_CERT
|
||||
tlsClientKey: $LAB_KEY
|
||||
jsonData:
|
||||
tlsAuth: true
|
||||
tlsAuthWithCACert: true
|
||||
timeInterval: 5s
|
||||
exemplarTraceIdDestinations:
|
||||
- name: trace_id
|
||||
datasourceUid: tempo
|
||||
- name: Loki
|
||||
uid: loki
|
||||
type: loki
|
||||
access: proxy
|
||||
url: https://loki:3100
|
||||
secureJsonData:
|
||||
tlsCACert: $LAB_CA
|
||||
tlsClientCert: $LAB_CERT
|
||||
tlsClientKey: $LAB_KEY
|
||||
jsonData:
|
||||
tlsAuth: true
|
||||
tlsAuthWithCACert: true
|
||||
derivedFields:
|
||||
- name: Trace
|
||||
matcherRegex: '"trace_id":"([0-9a-f]{32})"'
|
||||
datasourceUid: tempo
|
||||
url: '$${__value.raw}'
|
||||
- name: Tempo
|
||||
uid: tempo
|
||||
type: tempo
|
||||
access: proxy
|
||||
url: https://tempo:3200
|
||||
secureJsonData:
|
||||
tlsCACert: $LAB_CA
|
||||
tlsClientCert: $LAB_CERT
|
||||
tlsClientKey: $LAB_KEY
|
||||
jsonData:
|
||||
tlsAuth: true
|
||||
tlsAuthWithCACert: true
|
||||
tracesToLogsV2:
|
||||
datasourceUid: loki
|
||||
spanStartTimeShift: '-10s'
|
||||
spanEndTimeShift: '10s'
|
||||
tags:
|
||||
- key: service.name
|
||||
value: service_name
|
||||
customQuery: true
|
||||
query: '{$${__tags}} | json | trace_id="$${__span.traceId}"'
|
||||
@@ -0,0 +1,32 @@
|
||||
global
|
||||
maxconn 1024
|
||||
|
||||
defaults
|
||||
mode http
|
||||
timeout connect 1s
|
||||
timeout client 60s
|
||||
timeout server 60s
|
||||
timeout check 1s
|
||||
retries 0
|
||||
|
||||
resolvers docker
|
||||
nameserver dns 127.0.0.11:53
|
||||
hold valid 2s
|
||||
|
||||
frontend public
|
||||
bind :8443 ssl crt /run/identity/server.pem ssl-min-ver TLSv1.2
|
||||
default_backend replicas
|
||||
|
||||
backend replicas
|
||||
balance roundrobin
|
||||
option httpchk
|
||||
http-check send meth GET uri /health/ready ver HTTP/1.1 hdr Host localhost
|
||||
http-check expect status 200
|
||||
default-server inter 1s fall 2 rise 1 resolvers docker init-addr libc,none
|
||||
server a api-a-tls:8444 check ssl verify required ca-file /run/trust/ca.crt crt /run/identity/client.pem sni str(api-a-tls) check-sni api-a-tls verifyhost api-a-tls
|
||||
server b api-b-tls:8444 check ssl verify required ca-file /run/trust/ca.crt crt /run/identity/client.pem sni str(api-b-tls) check-sni api-b-tls verifyhost api-b-tls
|
||||
|
||||
frontend monitoring
|
||||
bind :8404 ssl crt /run/identity/server.pem ca-file /run/trust/ca.crt verify required
|
||||
http-request deny unless { ssl_c_s_dn(cn) -m str prometheus-scrape } { path /metrics }
|
||||
http-request use-service prometheus-exporter
|
||||
@@ -0,0 +1,37 @@
|
||||
auth_enabled: false
|
||||
server:
|
||||
http_listen_address: 127.0.0.1
|
||||
http_listen_port: 13100
|
||||
grpc_listen_address: 127.0.0.1
|
||||
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
|
||||
retention_period: 72h
|
||||
otlp_config:
|
||||
resource_attributes:
|
||||
ignore_defaults: true
|
||||
attributes_config:
|
||||
- action: index_label
|
||||
attributes: [service.name]
|
||||
compactor:
|
||||
retention_enabled: true
|
||||
delete_request_store: filesystem
|
||||
@@ -0,0 +1,39 @@
|
||||
{
|
||||
"Version": "2012-10-17",
|
||||
"Statement": [
|
||||
{
|
||||
"Effect": "Allow",
|
||||
"Action": [
|
||||
"s3:PutObject"
|
||||
],
|
||||
"Resource": [
|
||||
"arn:aws:s3:::messenger-attachments/staging/*"
|
||||
]
|
||||
},
|
||||
{
|
||||
"Effect": "Allow",
|
||||
"Action": [
|
||||
"s3:GetObject"
|
||||
],
|
||||
"Resource": [
|
||||
"arn:aws:s3:::messenger-attachments/results/*"
|
||||
]
|
||||
},
|
||||
{
|
||||
"Effect": "Allow",
|
||||
"Action": [
|
||||
"s3:ListBucket"
|
||||
],
|
||||
"Resource": [
|
||||
"arn:aws:s3:::messenger-attachments"
|
||||
],
|
||||
"Condition": {
|
||||
"StringEquals": {
|
||||
"s3:prefix": [
|
||||
"originals/"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
export MC_CONFIG_DIR=/tmp/mc
|
||||
mkdir -p "$MC_CONFIG_DIR/certs/CAs"
|
||||
cp /run/trust/ca.crt "$MC_CONFIG_DIR/certs/CAs/lab.crt"
|
||||
if ! mc alias set local https://s3:9000 labroot "$(cat /run/identity/admin)" >/dev/null 2>&1; then
|
||||
echo 'MinIO administrative connection failed' >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# New buckets are private by default. Keep the existing bucket policy on replay.
|
||||
mc mb --ignore-existing local/messenger-attachments >/dev/null
|
||||
users=$(mc --no-color admin user list local)
|
||||
policies=$(mc --no-color admin policy list local)
|
||||
for role in api worker recovery; do
|
||||
name="lab-$role"
|
||||
if ! printf '%s\n' "$policies" | grep -Fxq "$name"; then
|
||||
mc admin policy create local "$name" "/lab/$role.json" >/dev/null
|
||||
fi
|
||||
user=$(printf '%s\n' "$users" | awk -v name="$name" '$2 == name')
|
||||
if [ -z "$user" ]; then
|
||||
if ! mc admin user add local "$name" "$(cat "/run/identity/$role")" >/dev/null 2>&1; then
|
||||
printf 'Could not create MinIO user %s\n' "$name" >&2
|
||||
exit 1
|
||||
fi
|
||||
elif [ -n "$(printf '%s\n' "$user" | awk '{print $3}')" ]; then
|
||||
continue
|
||||
fi
|
||||
mc admin policy attach local "$name" --user "$name" >/dev/null
|
||||
done
|
||||
@@ -0,0 +1,30 @@
|
||||
{
|
||||
"Version": "2012-10-17",
|
||||
"Statement": [
|
||||
{
|
||||
"Effect": "Allow",
|
||||
"Action": [
|
||||
"s3:DeleteObject"
|
||||
],
|
||||
"Resource": [
|
||||
"arn:aws:s3:::messenger-attachments/staging/*"
|
||||
]
|
||||
},
|
||||
{
|
||||
"Effect": "Allow",
|
||||
"Action": [
|
||||
"s3:ListBucket"
|
||||
],
|
||||
"Resource": [
|
||||
"arn:aws:s3:::messenger-attachments"
|
||||
],
|
||||
"Condition": {
|
||||
"StringEquals": {
|
||||
"s3:prefix": [
|
||||
"staging/"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"Version": "2012-10-17",
|
||||
"Statement": [
|
||||
{
|
||||
"Effect": "Allow",
|
||||
"Action": [
|
||||
"s3:GetObject"
|
||||
],
|
||||
"Resource": [
|
||||
"arn:aws:s3:::messenger-attachments/staging/*",
|
||||
"arn:aws:s3:::messenger-attachments/originals/*",
|
||||
"arn:aws:s3:::messenger-attachments/results/*"
|
||||
]
|
||||
},
|
||||
{
|
||||
"Effect": "Allow",
|
||||
"Action": [
|
||||
"s3:PutObject"
|
||||
],
|
||||
"Resource": [
|
||||
"arn:aws:s3:::messenger-attachments/results/*"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
api_addr = "https://openbao:8200"
|
||||
cluster_addr = "https://openbao:8201"
|
||||
storage "raft" {
|
||||
path = "/openbao/data"
|
||||
node_id = "lab7"
|
||||
}
|
||||
listener "tcp" {
|
||||
address = "0.0.0.0:8200"
|
||||
cluster_address = "127.0.0.1:8201"
|
||||
tls_cert_file = "/run/identity/server.crt"
|
||||
tls_key_file = "/run/identity/server.key"
|
||||
tls_min_version = "tls12"
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
FROM busybox:1.37.0-musl AS probe
|
||||
FROM otel/opentelemetry-collector-contrib:0.144.0@sha256:213886eb6407af91b87fa47551c3632be1a6419ff3a5114ef1e6fc364628496f AS collector
|
||||
COPY --from=probe /bin/busybox /lab/busybox
|
||||
FROM grafana/loki:3.6.12@sha256:2483b71b28b15dee230f85512cae2b20c4b5f6e98a6eabe686cbccfa5ea3ba4a AS loki
|
||||
COPY --from=probe /bin/busybox /lab/busybox
|
||||
FROM grafana/tempo:2.10.5@sha256:ee21727732c7a7199cb71c3eee9153bbf23f9b0b87619f0555a0cf21a67f1a33 AS tempo
|
||||
COPY --from=probe /bin/busybox /lab/busybox
|
||||
FROM prom/prometheus:v3.5.5@sha256:332c2f43e7e389d74d3893b55bb02fbbd684208e681eeb604641d5d769c0fe2a AS prometheus
|
||||
FROM grafana/grafana:11.6.14@sha256:ebe075cd4c4520f9d3af2403a1ddc830651ca7d009cbdfdcf21032db574dc3a7 AS grafana
|
||||
@@ -0,0 +1,67 @@
|
||||
extensions:
|
||||
health_check:
|
||||
endpoint: 127.0.0.1:13133
|
||||
receivers:
|
||||
otlp:
|
||||
protocols:
|
||||
http:
|
||||
endpoint: 127.0.0.1:14318
|
||||
processors:
|
||||
memory_limiter:
|
||||
check_interval: 1s
|
||||
limit_mib: 160
|
||||
spike_limit_mib: 40
|
||||
batch:
|
||||
timeout: 1s
|
||||
send_batch_size: 256
|
||||
send_batch_max_size: 256
|
||||
exporters:
|
||||
prometheus:
|
||||
endpoint: 127.0.0.1:19464
|
||||
metric_expiration: 25s
|
||||
enable_open_metrics: true
|
||||
resource_to_telemetry_conversion:
|
||||
enabled: true
|
||||
otlphttp/loki:
|
||||
endpoint: https://loki:3100/otlp
|
||||
tls: &backend_tls
|
||||
ca_file: /run/trust/ca.crt
|
||||
cert_file: /run/identity/client.crt
|
||||
key_file: /run/identity/client.key
|
||||
timeout: 2s
|
||||
sending_queue: &bounded_queue
|
||||
num_consumers: 1
|
||||
queue_size: 16
|
||||
retry_on_failure: &bounded_retry
|
||||
initial_interval: 1s
|
||||
max_interval: 4s
|
||||
max_elapsed_time: 10s
|
||||
otlphttp/tempo:
|
||||
endpoint: https://tempo:4318
|
||||
tls: *backend_tls
|
||||
timeout: 2s
|
||||
sending_queue: *bounded_queue
|
||||
retry_on_failure: *bounded_retry
|
||||
service:
|
||||
extensions: [health_check]
|
||||
telemetry:
|
||||
metrics:
|
||||
readers:
|
||||
- pull:
|
||||
exporter:
|
||||
prometheus:
|
||||
host: 127.0.0.1
|
||||
port: 18888
|
||||
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: [otlphttp/tempo]
|
||||
@@ -0,0 +1,54 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
|
||||
sql() {
|
||||
psql -Xq -v ON_ERROR_STOP=1 -U postgres -d messenger "$@"
|
||||
}
|
||||
|
||||
for role in migrator api_blue publisher worker recovery ops; do
|
||||
if [ "$(sql -At -c "SELECT 1 FROM pg_roles WHERE rolname = '$role'")" = 1 ]; then
|
||||
continue
|
||||
fi
|
||||
credential=$(cat "/run/identity/$role")
|
||||
case "$credential" in
|
||||
*[!a-f0-9]*|'') printf 'Invalid credential file for %s\n' "$role" >&2; exit 1 ;;
|
||||
esac
|
||||
if ! {
|
||||
printf '%s\n' 'BEGIN;' "SET LOCAL password_encryption = 'scram-sha-256';" \
|
||||
"SET LOCAL log_statement = 'none';" "SET LOCAL log_min_error_statement = 'panic';" \
|
||||
'SELECT pg_advisory_xact_lock(70701);'
|
||||
printf "SELECT format('CREATE ROLE %%I LOGIN PASSWORD %%L', '%s', '%s') WHERE NOT EXISTS (SELECT FROM pg_roles WHERE rolname = '%s')\n" "$role" "$credential" "$role"
|
||||
printf '%s\n' '\gexec' 'COMMIT;'
|
||||
} | sql >/dev/null 2>&1; then
|
||||
printf 'Could not create PostgreSQL role %s\n' "$role" >&2
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
sql >/dev/null <<'SQL'
|
||||
BEGIN;
|
||||
SELECT pg_advisory_xact_lock(70701);
|
||||
DO $roles$
|
||||
BEGIN
|
||||
IF NOT EXISTS (SELECT FROM pg_roles WHERE rolname = 'api_runtime') THEN
|
||||
CREATE ROLE api_runtime NOLOGIN;
|
||||
END IF;
|
||||
IF NOT EXISTS (SELECT FROM pg_roles WHERE rolname = 'api_green') THEN
|
||||
CREATE ROLE api_green LOGIN;
|
||||
END IF;
|
||||
IF EXISTS (
|
||||
SELECT FROM pg_roles
|
||||
WHERE (rolname IN ('api_blue', 'api_green') AND NOT rolcanlogin)
|
||||
OR (rolname = 'api_runtime' AND rolcanlogin)
|
||||
) THEN
|
||||
RAISE EXCEPTION 'Existing API roles have incompatible LOGIN settings; manual reconciliation required';
|
||||
END IF;
|
||||
END
|
||||
$roles$;
|
||||
GRANT api_runtime TO api_blue, api_green;
|
||||
REVOKE ALL ON DATABASE messenger FROM PUBLIC;
|
||||
GRANT CONNECT ON DATABASE messenger TO migrator, api_runtime, publisher, worker, recovery, ops;
|
||||
REVOKE CREATE ON SCHEMA public FROM PUBLIC;
|
||||
GRANT CREATE, USAGE ON SCHEMA public TO migrator;
|
||||
COMMIT;
|
||||
SQL
|
||||
@@ -0,0 +1,6 @@
|
||||
local all postgres peer
|
||||
local all all reject
|
||||
hostssl messenger all 0.0.0.0/0 scram-sha-256
|
||||
hostssl messenger all ::/0 scram-sha-256
|
||||
host all all 0.0.0.0/0 reject
|
||||
host all all ::/0 reject
|
||||
@@ -0,0 +1,13 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
install -m 0600 -o postgres -g postgres /run/identity/server.key /run/postgres-tls/server.key
|
||||
install -m 0644 -o postgres -g postgres /run/identity/server.crt /run/postgres-tls/server.crt
|
||||
# Execute the bind-mounted script through sh. Docker Desktop may mount it noexec.
|
||||
printf '%s\n' '#!/bin/sh' 'exec /bin/sh /lab/init-roles.sh' \
|
||||
> /docker-entrypoint-initdb.d/10-roles.sh
|
||||
chmod 0755 /docker-entrypoint-initdb.d/10-roles.sh
|
||||
exec docker-entrypoint.sh postgres -c ssl=on \
|
||||
-c ssl_cert_file=/run/postgres-tls/server.crt \
|
||||
-c ssl_key_file=/run/postgres-tls/server.key \
|
||||
-c ssl_min_protocol_version=TLSv1.2 \
|
||||
-c hba_file=/lab/pg_hba.conf -c password_encryption=scram-sha-256
|
||||
@@ -0,0 +1,28 @@
|
||||
global:
|
||||
scrape_interval: 5s
|
||||
evaluation_interval: 5s
|
||||
rule_files: [/etc/prometheus/rules.yaml]
|
||||
scrape_configs:
|
||||
- job_name: application-otlp
|
||||
scheme: https
|
||||
tls_config: &scrape_tls
|
||||
ca_file: /run/trust/ca.crt
|
||||
cert_file: /run/identity/client.crt
|
||||
key_file: /run/identity/client.key
|
||||
scrape_protocols: [OpenMetricsText1.0.0, PrometheusText0.0.4]
|
||||
static_configs:
|
||||
- targets: [otel-collector:9464]
|
||||
- job_name: collector
|
||||
scheme: https
|
||||
tls_config: *scrape_tls
|
||||
static_configs:
|
||||
- targets: [otel-collector:8888]
|
||||
- job_name: ingress
|
||||
scheme: https
|
||||
tls_config: *scrape_tls
|
||||
metrics_path: /metrics
|
||||
static_configs:
|
||||
- targets: [lb:8404]
|
||||
- job_name: prometheus
|
||||
static_configs:
|
||||
- targets: [127.0.0.1:19090]
|
||||
@@ -0,0 +1,117 @@
|
||||
groups:
|
||||
- name: messenger-sli
|
||||
rules:
|
||||
- record: lab:sli_api_total:30s
|
||||
expr: sum(increase(haproxy_frontend_http_responses_total{proxy="public"}[30s]))
|
||||
- record: lab:sli_api_bad:30s
|
||||
expr: sum(increase(haproxy_frontend_http_responses_total{proxy="public",code="5xx"}[30s])) or 0 * sum(increase(haproxy_frontend_http_responses_total{proxy="public"}[30s]))
|
||||
- record: lab:sli_ready_total:30s
|
||||
expr: sum(lab_ready_cohort{window="30s",outcome="total"}) and on() (time() - max(lab_queue_sample_timestamp_seconds) < 15)
|
||||
- record: lab:sli_ready_bad:30s
|
||||
expr: sum(lab_ready_cohort{window="30s",outcome="bad"}) and on() (time() - max(lab_queue_sample_timestamp_seconds) < 15)
|
||||
- record: lab:burn_api:30s
|
||||
expr: (lab:sli_api_bad:30s / lab:sli_api_total:30s / 0.01) and (lab:sli_api_total:30s > 0)
|
||||
- record: lab:burn_ready:30s
|
||||
expr: (lab:sli_ready_bad:30s / lab:sli_ready_total:30s / 0.05) and (lab:sli_ready_total:30s > 0)
|
||||
- record: lab:sli_api_total:2m
|
||||
expr: sum(increase(haproxy_frontend_http_responses_total{proxy="public"}[2m]))
|
||||
- record: lab:sli_api_bad:2m
|
||||
expr: sum(increase(haproxy_frontend_http_responses_total{proxy="public",code="5xx"}[2m])) or 0 * sum(increase(haproxy_frontend_http_responses_total{proxy="public"}[2m]))
|
||||
- record: lab:sli_ready_total:2m
|
||||
expr: sum(lab_ready_cohort{window="2m",outcome="total"}) and on() (time() - max(lab_queue_sample_timestamp_seconds) < 15)
|
||||
- record: lab:sli_ready_bad:2m
|
||||
expr: sum(lab_ready_cohort{window="2m",outcome="bad"}) and on() (time() - max(lab_queue_sample_timestamp_seconds) < 15)
|
||||
- record: lab:burn_api:2m
|
||||
expr: (lab:sli_api_bad:2m / lab:sli_api_total:2m / 0.01) and (lab:sli_api_total:2m > 0)
|
||||
- record: lab:burn_ready:2m
|
||||
expr: (lab:sli_ready_bad:2m / lab:sli_ready_total:2m / 0.05) and (lab:sli_ready_total:2m > 0)
|
||||
- record: lab:sli_api_total:5m
|
||||
expr: sum(increase(haproxy_frontend_http_responses_total{proxy="public"}[5m]))
|
||||
- record: lab:sli_api_bad:5m
|
||||
expr: sum(increase(haproxy_frontend_http_responses_total{proxy="public",code="5xx"}[5m])) or 0 * sum(increase(haproxy_frontend_http_responses_total{proxy="public"}[5m]))
|
||||
- record: lab:sli_ready_total:5m
|
||||
expr: sum(lab_ready_cohort{window="5m",outcome="total"}) and on() (time() - max(lab_queue_sample_timestamp_seconds) < 15)
|
||||
- record: lab:sli_ready_bad:5m
|
||||
expr: sum(lab_ready_cohort{window="5m",outcome="bad"}) and on() (time() - max(lab_queue_sample_timestamp_seconds) < 15)
|
||||
- record: lab:burn_api:5m
|
||||
expr: (lab:sli_api_bad:5m / lab:sli_api_total:5m / 0.01) and (lab:sli_api_total:5m > 0)
|
||||
- record: lab:burn_ready:5m
|
||||
expr: (lab:sli_ready_bad:5m / lab:sli_ready_total:5m / 0.05) and (lab:sli_ready_total:5m > 0)
|
||||
- record: lab:sli_api_total:1h
|
||||
expr: sum(increase(haproxy_frontend_http_responses_total{proxy="public"}[1h]))
|
||||
- record: lab:sli_api_bad:1h
|
||||
expr: sum(increase(haproxy_frontend_http_responses_total{proxy="public",code="5xx"}[1h])) or 0 * sum(increase(haproxy_frontend_http_responses_total{proxy="public"}[1h]))
|
||||
- record: lab:sli_ready_total:1h
|
||||
expr: sum(lab_ready_cohort{window="1h",outcome="total"}) and on() (time() - max(lab_queue_sample_timestamp_seconds) < 15)
|
||||
- record: lab:sli_ready_bad:1h
|
||||
expr: sum(lab_ready_cohort{window="1h",outcome="bad"}) and on() (time() - max(lab_queue_sample_timestamp_seconds) < 15)
|
||||
- record: lab:burn_api:1h
|
||||
expr: (lab:sli_api_bad:1h / lab:sli_api_total:1h / 0.01) and (lab:sli_api_total:1h > 0)
|
||||
- record: lab:burn_ready:1h
|
||||
expr: (lab:sli_ready_bad:1h / lab:sli_ready_total:1h / 0.05) and (lab:sli_ready_total:1h > 0)
|
||||
- name: messenger-alerts
|
||||
rules:
|
||||
- alert: HighHTTPErrorRate
|
||||
expr: (lab:sli_api_bad:30s / lab:sli_api_total:30s > 0.10) and (lab:sli_api_total:30s >= 5)
|
||||
for: 10s
|
||||
labels:
|
||||
severity: warning
|
||||
annotations:
|
||||
description: "More than 10% ingress 5xx over 30s with at least five responses."
|
||||
runbook_url: "infra/runbooks.md#api"
|
||||
- alert: QueueLag
|
||||
expr: (max(lab_oldest_job_age_seconds) > 15) and on() (time() - max(lab_queue_sample_timestamp_seconds) < 15)
|
||||
for: 10s
|
||||
labels:
|
||||
severity: warning
|
||||
annotations:
|
||||
description: "Oldest unfinished image job has been older than 15s for 10s."
|
||||
runbook_url: "infra/runbooks.md#queue"
|
||||
- alert: APIBurnFast
|
||||
expr: (lab:burn_api:30s > 12) and (lab:burn_api:2m > 12) and (lab:sli_api_total:30s >= 8) and (lab:sli_api_total:2m >= 20)
|
||||
for: 10s
|
||||
labels:
|
||||
severity: critical
|
||||
annotations:
|
||||
description: "12x budget burn across both 30s and 2m."
|
||||
runbook_url: "infra/runbooks.md#api"
|
||||
- alert: APIBurnSlow
|
||||
expr: (lab:burn_api:2m > 4) and (lab:burn_api:5m > 4) and (lab:sli_api_total:2m >= 8) and (lab:sli_api_total:5m >= 20)
|
||||
for: 15s
|
||||
labels:
|
||||
severity: warning
|
||||
annotations:
|
||||
description: "4x budget burn across both 2m and 5m."
|
||||
runbook_url: "infra/runbooks.md#api"
|
||||
- alert: ReadyBurnFast
|
||||
expr: (lab:burn_ready:30s > 12) and (lab:burn_ready:2m > 12) and (lab:sli_ready_total:30s >= 4) and (lab:sli_ready_total:2m >= 10)
|
||||
for: 10s
|
||||
labels:
|
||||
severity: critical
|
||||
annotations:
|
||||
description: "12x budget burn across both 30s and 2m."
|
||||
runbook_url: "infra/runbooks.md#queue"
|
||||
- alert: ReadyBurnSlow
|
||||
expr: (lab:burn_ready:2m > 4) and (lab:burn_ready:5m > 4) and (lab:sli_ready_total:2m >= 4) and (lab:sli_ready_total:5m >= 10)
|
||||
for: 15s
|
||||
labels:
|
||||
severity: warning
|
||||
annotations:
|
||||
description: "4x budget burn across both 2m and 5m."
|
||||
runbook_url: "infra/runbooks.md#queue"
|
||||
- alert: TelemetryExportLoss
|
||||
expr: sum by (exporter) (increase(otelcol_exporter_send_failed_spans_total[30s])) > 0
|
||||
for: 5s
|
||||
labels:
|
||||
severity: warning
|
||||
annotations:
|
||||
description: "Collector could not export one or more trace spans over 30s."
|
||||
runbook_url: "infra/runbooks.md#telemetry"
|
||||
- alert: TelemetryBacklogUnavailable
|
||||
expr: (time() - max(lab_queue_sample_timestamp_seconds) > 15) or absent(lab_queue_sample_timestamp_seconds)
|
||||
for: 15s
|
||||
labels:
|
||||
severity: warning
|
||||
annotations:
|
||||
description: "No fresh PostgreSQL queue sample."
|
||||
runbook_url: "infra/runbooks.md#queue"
|
||||
@@ -0,0 +1,83 @@
|
||||
{
|
||||
"users": [
|
||||
{
|
||||
"name": "publisher",
|
||||
"password_hash": "",
|
||||
"hashing_algorithm": "rabbit_password_hashing_sha256",
|
||||
"tags": []
|
||||
},
|
||||
{
|
||||
"name": "worker",
|
||||
"password_hash": "",
|
||||
"hashing_algorithm": "rabbit_password_hashing_sha256",
|
||||
"tags": []
|
||||
},
|
||||
{
|
||||
"name": "ops-redeliver",
|
||||
"password_hash": "",
|
||||
"hashing_algorithm": "rabbit_password_hashing_sha256",
|
||||
"tags": []
|
||||
}
|
||||
],
|
||||
"vhosts": [
|
||||
{
|
||||
"name": "messenger"
|
||||
}
|
||||
],
|
||||
"permissions": [
|
||||
{
|
||||
"user": "publisher",
|
||||
"vhost": "messenger",
|
||||
"configure": "^$",
|
||||
"write": "^attachments$",
|
||||
"read": "^$"
|
||||
},
|
||||
{
|
||||
"user": "worker",
|
||||
"vhost": "messenger",
|
||||
"configure": "^$",
|
||||
"write": "^$",
|
||||
"read": "^attachment[.]process[.]v1$"
|
||||
},
|
||||
{
|
||||
"user": "ops-redeliver",
|
||||
"vhost": "messenger",
|
||||
"configure": "^$",
|
||||
"write": "^attachments$",
|
||||
"read": "^$"
|
||||
}
|
||||
],
|
||||
"exchanges": [
|
||||
{
|
||||
"name": "attachments",
|
||||
"vhost": "messenger",
|
||||
"type": "direct",
|
||||
"durable": true,
|
||||
"auto_delete": false,
|
||||
"internal": false,
|
||||
"arguments": {}
|
||||
}
|
||||
],
|
||||
"queues": [
|
||||
{
|
||||
"name": "attachment.process.v1",
|
||||
"vhost": "messenger",
|
||||
"durable": true,
|
||||
"auto_delete": false,
|
||||
"arguments": {
|
||||
"x-queue-type": "quorum",
|
||||
"x-delivery-limit": -1
|
||||
}
|
||||
}
|
||||
],
|
||||
"bindings": [
|
||||
{
|
||||
"source": "attachments",
|
||||
"destination": "attachment.process.v1",
|
||||
"destination_type": "queue",
|
||||
"vhost": "messenger",
|
||||
"routing_key": "attachment.process.v1",
|
||||
"arguments": {}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
[rabbitmq_auth_mechanism_ssl].
|
||||
@@ -0,0 +1,11 @@
|
||||
listeners.tcp = none
|
||||
listeners.ssl.default = 5671
|
||||
ssl_options.cacertfile = /run/trust/ca.crt
|
||||
ssl_options.certfile = /run/identity/server.crt
|
||||
ssl_options.keyfile = /run/identity/server.key
|
||||
ssl_options.verify = verify_peer
|
||||
ssl_options.fail_if_no_peer_cert = true
|
||||
ssl_cert_login_from = common_name
|
||||
auth_mechanisms.1 = EXTERNAL
|
||||
definitions.import_backend = local_filesystem
|
||||
definitions.local.path = /lab/definitions.json
|
||||
@@ -0,0 +1,121 @@
|
||||
# Runbook лабораторной 6
|
||||
|
||||
Открыть дашборд **Lab 6 → Messenger · Lab 6**, выбрать последние 15 минут и обновление 5 секунд. Состояния правил доступны в Prometheus API через Grafana
|
||||
`/api/datasources/proxy/uid/prometheus/api/v1/alerts`. Активное правило имеет состояние
|
||||
`pending` или `firing`. После resolved оно исчезает из ответа. Историю firing также
|
||||
можно увидеть через `ALERTS{alertstate="firing"}` в Explore → Prometheus.
|
||||
|
||||
## API
|
||||
|
||||
- Проверить публичную долю 5xx и отдельную долю 5xx API. Входная метрика включает
|
||||
собственные 503 HAProxy, например при отсутствии готовых реплик.
|
||||
- Если реплики готовы, открыть **Пулы API · ожидание** и отфильтровать ошибки в Explore → Loki
|
||||
запросом `{service_name="messenger-api"} | json | status=503`.
|
||||
- Если у клиента есть `X-Request-Id`, добавить `| request_id="<значение>"`. Открыть ссылку **Trace**.
|
||||
Долгий `postgresql.pool.acquire` при растущем waiting указывает на ожидание пула.
|
||||
Долгий `postgresql.execute` указывает на ожидание в БД. Если оба короткие, смотреть
|
||||
дочерние операции и время, оставшееся в HTTP span.
|
||||
- Проверить PostgreSQL через `./scripts/compose.sh ps postgres`. Для учебного lock
|
||||
дождаться ROLLBACK и повторить запрос. Проверить 200, отсутствие текущих 5xx и
|
||||
исчезновение **HighHTTPErrorRate**, **APIBurnFast**, **APIBurnSlow** после истечения окон.
|
||||
|
||||
## Queue
|
||||
|
||||
- Сравнить **Очередь · queued**, **Старейшая незавершённая работа** и **Worker · занятость и ёмкость**.
|
||||
Рост возраста при исчезнувшей capacity указывает на потерю worker. При полной capacity
|
||||
проверить длительность задач. При свободной capacity проверить broker и publisher.
|
||||
- Проверить `./scripts/compose.sh ps worker publisher broker recovery`.
|
||||
В Explore → Loki открыть `{service_name=~"messenger-worker|messenger-publisher"} | json`.
|
||||
Для одной задачи открыть trace и сравнить интервалы между **publish**, **process** и **job.publish_ready**.
|
||||
- После остановки worker запустить `./scripts/compose.sh start worker`. Проверить
|
||||
ready загруженных файлов и нулевой backlog. У **QueueLag** разрешение связано с
|
||||
фактическим возрастом. **ReadyBurnFast/Slow** могут остаться активными до выхода
|
||||
пропущенных дедлайнов из окна.
|
||||
- **TelemetryBacklogUnavailable** означает, что PostgreSQL или процесс recovery не
|
||||
обновляют выборку. Проверить их состояние. В этот период SLI ready неизвестен.
|
||||
|
||||
## Telemetry
|
||||
|
||||
- При **TelemetryExportLoss** проверить **Collector · очередь экспорта**,
|
||||
**Collector · потери на экспорте** и RSS. По label `exporter` определить backend.
|
||||
- Выполнить `./scripts/compose.sh ps tempo loki otel-collector` и локально
|
||||
проверить `./scripts/compose.sh logs --tail 30 otel-collector`.
|
||||
- Вернуть остановленный backend через `./scripts/compose.sh start tempo` или
|
||||
`./scripts/compose.sh start loki`. Создать новое вложение, проверить наличие
|
||||
новой трассы и исчезновение alert. Прежние отброшенные пакеты не восстанавливаются.
|
||||
|
||||
## Лабораторная 7 — переход на OpenBao v2
|
||||
|
||||
Compose заменит контейнер `openbao` на том же сетевом имени и порту. Сервис
|
||||
и `volume-init` будут монтировать `mtusi2026lab7_openbao_data_v2`.
|
||||
Старый `mtusi2026lab7_openbao_data` останется в Docker без подключения к новой
|
||||
конфигурации. Из корня проекта перед запуском проверьте наличие старого тома и
|
||||
действительность PostgreSQL credentials, которыми наполняется новый KV.
|
||||
|
||||
```sh
|
||||
export LAB7_STATE=/private/tmp/mtusi2026lab7-501
|
||||
export LAB7_API_DB_ROLE=api_blue
|
||||
./scripts/compose.sh config -q
|
||||
docker volume inspect --format '{{.Name}}' mtusi2026lab7_openbao_data
|
||||
./scripts/compose.sh exec -T postgres sh -ec '
|
||||
for role in "$1" publisher worker recovery; do
|
||||
if ! PGPASSWORD="$(cat "/run/identity/$role")" PGSSLMODE=verify-full \
|
||||
PGSSLROOTCERT=/run/trust/ca.crt PGGSSENCMODE=disable \
|
||||
psql -XAt -h postgres -U "$role" -d messenger -c "SELECT 1" >/dev/null 2>&1; then
|
||||
printf "PostgreSQL credential check failed for %s\n" "$role" >&2
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
' sh "$LAB7_API_DB_ROLE"
|
||||
```
|
||||
|
||||
При сбое проверки остановитесь до запуска OpenBao. Если активной ролью после
|
||||
ротации стала `api_green` и её действующий пароль есть в защищённом
|
||||
`$LAB7_STATE/postgres/api_green`, установите `LAB7_API_DB_ROLE=api_green` и
|
||||
повторите проверку. Если действующий пароль был только в старом KV,
|
||||
потребуется отдельно согласовать смену PostgreSQL credential.
|
||||
|
||||
После успешной проверки выполните команды по очереди. Остановитесь при ошибке.
|
||||
|
||||
```sh
|
||||
./scripts/bootstrap.sh --openbao-only
|
||||
python3 scripts/bao.py status
|
||||
./scripts/compose.sh exec -T openbao bao status
|
||||
docker volume inspect --format '{{.Name}}' mtusi2026lab7_openbao_data mtusi2026lab7_openbao_data_v2
|
||||
./scripts/compose.sh up -d --wait --wait-timeout 120
|
||||
```
|
||||
|
||||
Операторский файл нового экземпляра — `$LAB7_STATE/operator/openbao-v2.json`.
|
||||
Создайте защищённую резервную копию вне временного каталога. Не выводите
|
||||
содержимое файла. При таймауте или ошибке сохранения проверьте
|
||||
`python3 scripts/bao.py status` и сохраните операторские файлы, включая
|
||||
`.pending` и `.init-attempted`. Маркер блокирует новый запрос инициализации,
|
||||
даже если сервер пока отвечает `initialized=False`. Если итоговый файл
|
||||
сохранён и проверен, повторный bootstrap продолжит распечатывание и создание
|
||||
отсутствующих настроек. При отсутствии итогового файла требуется ручная
|
||||
проверка сохранённого ответа. Не удаляйте маркер для автоматического повтора.
|
||||
|
||||
## Проверки уровня 4 и ротация
|
||||
|
||||
Используйте отдельный Compose-проект и команды из [REPORT.md](../REPORT.md).
|
||||
Порт изолированного OpenBao передаётся операторским командам через
|
||||
`LAB7_OPENBAO_URL`; HTTPS и локальный CA обязательны.
|
||||
|
||||
- Для ротации PostgreSQL выполните `python3 scripts/rotate-db.py`. Скрипт проверяет старую
|
||||
генерацию, создаёт пароль на неактивной роли, проверяет вход с TLS,
|
||||
публикует через KV CAS и ждёт обе реплики и завершение старых подключений.
|
||||
При неоднозначном результате CAS или ошибке переключения сначала проверьте
|
||||
опубликованную роль и доступность реплик. `--retire-previous` проверяет
|
||||
действующую генерацию и удаляет только пароль другой роли. Поддерживается
|
||||
один оператор на локальный LAB7_STATE. В рабочем проекте требуется
|
||||
предварительное согласование смены credentials.
|
||||
- Для ротации leaf выполните `python3 scripts/rotate-leaf.py`. Сначала установите конфигурацию
|
||||
HAProxy master-worker. Скрипт проверяет CA/SAN, атомарно переключает PEM,
|
||||
выполняет graceful reload без ослабления mTLS, проверяет замену и только
|
||||
затем отзывает старый leaf и загружает CRL в обе реплики. До отзыва сбой
|
||||
возвращает предыдущий PEM. После отзыва сохраняется новый PEM; при частичном
|
||||
применении CRL проверьте новый leaf и повторите reload оставшейся реплики.
|
||||
- Для сканирования установите в отдельном окружении `pip-audit==2.9.0` и запустите
|
||||
`SCAN_OUTPUT=/absolute/report-dir PIP_AUDIT=/path/to/pip-audit sh scripts/security-scan.sh`
|
||||
после сборки образов. Ненулевой код означает находки или незавершённый скан;
|
||||
различайте их по JSON и журналу сканера.
|
||||
@@ -0,0 +1,22 @@
|
||||
server:
|
||||
http_listen_address: 127.0.0.1
|
||||
http_listen_port: 13200
|
||||
grpc_listen_address: 127.0.0.1
|
||||
distributor:
|
||||
receivers:
|
||||
otlp:
|
||||
protocols:
|
||||
http:
|
||||
endpoint: 127.0.0.1:14318
|
||||
ingester:
|
||||
max_block_duration: 1m
|
||||
compactor:
|
||||
compaction:
|
||||
block_retention: 72h
|
||||
storage:
|
||||
trace:
|
||||
backend: local
|
||||
wal:
|
||||
path: /var/tempo/wal
|
||||
local:
|
||||
path: /var/tempo/blocks
|
||||
@@ -0,0 +1,17 @@
|
||||
global
|
||||
tune.ssl.cachesize 0
|
||||
|
||||
defaults
|
||||
mode http
|
||||
timeout connect 1s
|
||||
timeout client 60s
|
||||
timeout server 60s
|
||||
retries 0
|
||||
|
||||
frontend api
|
||||
bind :8444 ssl crt /run/identity/server.pem ca-file /run/trust/ca.crt crl-file /run/trust/ca.crl verify required no-tls-tickets ssl-min-ver TLSv1.2
|
||||
http-request deny unless { ssl_c_s_dn(cn) -m str lb-to-api }
|
||||
default_backend uvicorn
|
||||
|
||||
backend uvicorn
|
||||
server local unix@/run/api/api.sock
|
||||
@@ -0,0 +1,16 @@
|
||||
defaults
|
||||
mode http
|
||||
timeout connect 2s
|
||||
timeout client 30s
|
||||
timeout server 30s
|
||||
retries 0
|
||||
|
||||
frontend listener-3100
|
||||
bind :3100 ssl crt /run/identity/server.pem ca-file /run/trust/ca.crt verify required ssl-min-ver TLSv1.2
|
||||
http-request allow if { ssl_c_s_dn(cn) -m str collector-export } { method POST } { path /otlp/v1/logs }
|
||||
http-request allow if { ssl_c_s_dn(cn) -m str grafana-query } { path_beg /loki/api/v1/ } !{ path /loki/api/v1/push /loki/api/v1/delete }
|
||||
http-request deny
|
||||
default_backend local-3100
|
||||
|
||||
backend local-3100
|
||||
server localhost 127.0.0.1:13100
|
||||
@@ -0,0 +1,30 @@
|
||||
defaults
|
||||
mode http
|
||||
timeout connect 2s
|
||||
timeout client 30s
|
||||
timeout server 30s
|
||||
retries 0
|
||||
|
||||
frontend listener-4318
|
||||
bind :4318 ssl crt /run/identity/server.pem ca-file /run/trust/ca.crt verify required ssl-min-ver TLSv1.2
|
||||
http-request deny unless { ssl_c_s_dn(cn) -m str api-a api-b publisher worker recovery } { method POST } { path /v1/metrics /v1/logs /v1/traces }
|
||||
default_backend local-4318
|
||||
|
||||
backend local-4318
|
||||
server localhost 127.0.0.1:14318
|
||||
|
||||
frontend listener-9464
|
||||
bind :9464 ssl crt /run/identity/server.pem ca-file /run/trust/ca.crt verify required ssl-min-ver TLSv1.2
|
||||
http-request deny unless { ssl_c_s_dn(cn) -m str prometheus-scrape } { path /metrics }
|
||||
default_backend local-9464
|
||||
|
||||
backend local-9464
|
||||
server localhost 127.0.0.1:19464
|
||||
|
||||
frontend listener-8888
|
||||
bind :8888 ssl crt /run/identity/server.pem ca-file /run/trust/ca.crt verify required ssl-min-ver TLSv1.2
|
||||
http-request deny unless { ssl_c_s_dn(cn) -m str prometheus-scrape } { path /metrics }
|
||||
default_backend local-8888
|
||||
|
||||
backend local-8888
|
||||
server localhost 127.0.0.1:18888
|
||||
@@ -0,0 +1,15 @@
|
||||
defaults
|
||||
mode http
|
||||
timeout connect 2s
|
||||
timeout client 30s
|
||||
timeout server 30s
|
||||
retries 0
|
||||
|
||||
frontend listener-9090
|
||||
bind :9090 ssl crt /run/identity/server.pem ca-file /run/trust/ca.crt verify required ssl-min-ver TLSv1.2
|
||||
http-request deny unless { ssl_c_s_dn(cn) -m str grafana-query } { path_beg /api/v1/ }
|
||||
http-request deny if { path_beg /api/v1/admin /api/v1/write /api/v1/otlp }
|
||||
default_backend local-9090
|
||||
|
||||
backend local-9090
|
||||
server localhost 127.0.0.1:19090
|
||||
@@ -0,0 +1,22 @@
|
||||
defaults
|
||||
mode http
|
||||
timeout connect 2s
|
||||
timeout client 30s
|
||||
timeout server 30s
|
||||
retries 0
|
||||
|
||||
frontend listener-4318
|
||||
bind :4318 ssl crt /run/identity/server.pem ca-file /run/trust/ca.crt verify required ssl-min-ver TLSv1.2
|
||||
http-request deny unless { ssl_c_s_dn(cn) -m str collector-export } { method POST } { path /v1/traces }
|
||||
default_backend local-4318
|
||||
|
||||
backend local-4318
|
||||
server localhost 127.0.0.1:14318
|
||||
|
||||
frontend listener-3200
|
||||
bind :3200 ssl crt /run/identity/server.pem ca-file /run/trust/ca.crt verify required ssl-min-ver TLSv1.2
|
||||
http-request deny unless { ssl_c_s_dn(cn) -m str grafana-query } { path_beg /api/ }
|
||||
default_backend local-3200
|
||||
|
||||
backend local-3200
|
||||
server localhost 127.0.0.1:13200
|
||||
Reference in New Issue
Block a user