выполение на 5
Skeleton contracts / contracts (pull_request) Canceled after 0s

This commit is contained in:
kaktuz20000
2026-11-04 19:22:35 +03:00
parent 20afc2c790
commit 5a6fcff3ef
90 changed files with 8848 additions and 130 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
# Инфраструктура студента
Здесь разместите конфигурации выбранных сервисов; основную топологию — в корневом compose.yaml/stack.yaml. `compose.example.yaml` — только worksheet ролей и намеренно не запускается. `contracts/infrastructure.json` задаёт минимальные роли, не готовые образы/пароли.
Конфигурации выбранных сервисов находятся здесь; основная топология — в корневом `compose.yaml`. `compose.example.yaml` — только worksheet ролей и намеренно не запускается. `contracts/infrastructure.json` задаёт минимальные роли, не готовые образы/пароли. Текущие OpenBao policies/bootstrap описаны в `openbao/`; OTel provisioning перенесён из lab6 в `otel/`.
В REPORT.md сопоставьте роль → service name → версия/digest → health/readiness → volume → сеть/порт → способ передачи credentials. Приведите bootstrap (schema, bucket, broker topology, а с lab6 provisioning) и безопасное повторение этих команд.
+11 -4
View File
@@ -1,7 +1,14 @@
# OpenBao — реализовать конфигурацию и политики
# OpenBao service configuration and bootstrap
Добавьте non-dev конфигурацию listener/storage/TLS, API/worker policies, bootstrap и rotation scripts. Credentials и unseal material создаются локально; здесь нет готового root token или private key.
`config.hcl` configures a TLS listener and persistent file storage; Compose runs OpenBao outside dev mode. `bootstrap-openbao.py` provisions KV v2 secrets and per-process AppRoles after operator init/unseal.
Решение должно показать реальную сервисную аутентификацию и получение нужного secret по ограниченной policy; просто работающий контейнер OpenBao не засчитывается. На 3 статический KV secret допустим. На 4 покажите expiry/renewal/rotation и allow/deny. Путь KV v2 data/metadata и ACL должен соответствовать фактическому mount; не копируйте широкое `path "*"` для приложения.
The API, worker, publisher, migrator and reconciler use separate AppRole credentials and policies. Each policy can read only its own `secret/data/messenger/<service>` KV v2 path. Service tokens have a 15-minute TTL and a one-hour maximum TTL; AppRole SecretIDs expire after 24 hours. Application code never receives the operator root token.
Документируйте шаги оператора init/unseal и восстановление после restart. Скрипт не должен печатать tokens/shares или хранить их в Git. См. contracts/trust-matrix.md и REPORT.md.
Operator workflow:
1. Generate local keys and bootstrap secrets with the scripts documented in the root README.
2. Start the `openbao` service, run `bao operator init`, and unseal it using the operator-held shares. Keep the initial root token outside the repository.
3. Run `python3 scripts/bootstrap-openbao.py --root-token-file <operator-only-file>`. It writes non-root AppRole IDs/SecretIDs under ignored `secrets/openbao/`; values are not printed.
4. Start application services. On a normal restart, the file backend retains OpenBao state and the operator unseals it if required. If a service SecretID expires, provision a replacement and restart that service.
The script provisions distinct paths and identities; secret values originate from local bootstrap files and are not committed. Root token and unseal shares must never be mounted into application containers.
+3
View File
@@ -0,0 +1,3 @@
path "secret/data/messenger/api" {
capabilities = ["read"]
}
+15
View File
@@ -0,0 +1,15 @@
ui = false
api_addr = "https://openbao:8200"
cluster_addr = "https://openbao:8201"
storage "file" {
path = "/openbao/data"
}
listener "tcp" {
address = "0.0.0.0:8200"
cluster_address = "0.0.0.0:8201"
tls_cert_file = "/run/secrets/openbao_tls_cert"
tls_key_file = "/run/secrets/openbao_tls_key"
tls_min_version = "tls12"
}
+3
View File
@@ -0,0 +1,3 @@
path "secret/data/messenger/worker" {
capabilities = ["read"]
}
+42
View File
@@ -0,0 +1,42 @@
groups:
- name: messenger-slo
interval: 10s
rules:
- record: messenger:api_5xx_ratio:rate5m
expr: |
(sum(rate(messenger_http_requests_total{status_class="5xx",http_route!~"/health/.*"}[5m])) or vector(0))
/
clamp_min(sum(rate(messenger_http_requests_total{http_route!~"/health/.*"}[5m])), 1e-9)
- record: messenger:api_availability:ratio7d
expr: |
1 -
(sum(increase(messenger_http_requests_total{status_class="5xx",http_route!~"/health/.*"}[7d])) or vector(0))
/
clamp_min(sum(increase(messenger_http_requests_total{http_route!~"/health/.*"}[7d])), 1)
- alert: MessengerApiErrorBudgetBurn
expr: messenger:api_5xx_ratio:rate5m > 0.01
for: 2m
labels:
severity: warning
annotations:
summary: API error budget burn exceeds the 1% short-window budget
description: The rolling 5-minute business API 5xx ratio is above 1%.
runbook: Check API traces for the failing route, then inspect correlated logs and DB/S3 spans.
- alert: MessengerQueueLag
expr: max(messenger_queue_oldest_age_seconds) > 60 and max(messenger_queue_depth) > 0
for: 2m
labels:
severity: warning
annotations:
summary: Oldest attachment job has waited for more than 60 seconds
description: Inspect worker availability, RabbitMQ health, and the worker trace for the oldest job.
runbook: Check queue depth and age, worker consuming logs, broker, then recover the worker and confirm resolved state.
- alert: MessengerDatabasePoolSaturation
expr: max(messenger_db_pool_requests_waiting) > 0
for: 2m
labels:
severity: warning
annotations:
summary: Requests are waiting for a database connection
description: Compare DB waiters with request traces and PostgreSQL health.
runbook: Inspect DB spans and pool use; verify database health and connection limits.
+80
View File
@@ -0,0 +1,80 @@
receivers:
otlp:
protocols:
grpc:
endpoint: 0.0.0.0:4317
tls:
cert_file: /run/secrets/otel_collector_tls_cert
key_file: /run/secrets/otel_collector_tls_key
client_ca_file: /run/secrets/ca_crt
http:
endpoint: 0.0.0.0:4318
tls:
cert_file: /run/secrets/otel_collector_tls_cert
key_file: /run/secrets/otel_collector_tls_key
client_ca_file: /run/secrets/ca_crt
processors:
memory_limiter:
check_interval: 1s
limit_mib: 384
spike_limit_mib: 96
batch:
timeout: 1s
send_batch_size: 512
send_batch_max_size: 1024
exporters:
prometheus:
endpoint: 0.0.0.0:9464
tls:
cert_file: /run/secrets/otel_collector_tls_cert
key_file: /run/secrets/otel_collector_tls_key
client_ca_file: /run/secrets/ca_crt
send_timestamps: true
resource_to_telemetry_conversion:
enabled: true
otlp_grpc/tempo:
endpoint: tempo:4317
tls:
ca_file: /run/secrets/ca_crt
sending_queue:
enabled: true
queue_size: 256
num_consumers: 2
retry_on_failure:
enabled: true
initial_interval: 1s
max_interval: 5s
max_elapsed_time: 30s
otlp_http/loki:
endpoint: https://loki:3100/otlp
tls:
ca_file: /run/secrets/ca_crt
sending_queue:
enabled: true
queue_size: 256
num_consumers: 2
retry_on_failure:
enabled: true
initial_interval: 1s
max_interval: 5s
max_elapsed_time: 30s
service:
telemetry:
logs:
level: warn
pipelines:
metrics:
receivers: [otlp]
processors: [memory_limiter, batch]
exporters: [prometheus]
logs:
receivers: [otlp]
processors: [memory_limiter, batch]
exporters: [otlp_http/loki]
traces:
receivers: [otlp]
processors: [memory_limiter, batch]
exporters: [otlp_grpc/tempo]
@@ -0,0 +1,174 @@
{
"annotations": {
"list": [
{
"builtIn": 1,
"datasource": {"type": "grafana", "uid": "-- Grafana --"},
"enable": true,
"hide": true,
"iconColor": "rgba(0, 211, 255, 1)",
"name": "Annotations & Alerts",
"type": "dashboard"
}
]
},
"editable": false,
"graphTooltip": 1,
"panels": [
{
"datasource": {"type": "prometheus", "uid": "prometheus"},
"fieldConfig": {"defaults": {"unit": "reqps"}, "overrides": []},
"gridPos": {"h": 7, "w": 12, "x": 0, "y": 0},
"id": 1,
"options": {"legend": {"displayMode": "list", "placement": "bottom"}, "tooltip": {"mode": "multi"}},
"targets": [{"expr": "sum by (http_route) (rate(messenger_http_requests_total{http_route!~\"/health/.*\"}[5m]))", "legendFormat": "{{http_route}}", "refId": "A"}],
"title": "API requests per second",
"type": "timeseries"
},
{
"datasource": {"type": "prometheus", "uid": "prometheus"},
"fieldConfig": {"defaults": {"unit": "percentunit", "min": 0, "max": 1}, "overrides": []},
"gridPos": {"h": 7, "w": 12, "x": 12, "y": 0},
"id": 2,
"options": {"legend": {"displayMode": "list", "placement": "bottom"}, "tooltip": {"mode": "multi"}},
"targets": [{"expr": "sum(rate(messenger_http_requests_total{status_class=\"5xx\",http_route!~\"/health/.*\"}[5m])) / clamp_min(sum(rate(messenger_http_requests_total{http_route!~\"/health/.*\"}[5m])), 1e-9)", "legendFormat": "5xx / business requests", "refId": "A"}],
"title": "Business API 5xx ratio (5m)",
"type": "timeseries"
},
{
"datasource": {"type": "prometheus", "uid": "prometheus"},
"fieldConfig": {"defaults": {"unit": "s"}, "overrides": []},
"gridPos": {"h": 8, "w": 12, "x": 0, "y": 7},
"id": 3,
"options": {"legend": {"displayMode": "list", "placement": "bottom"}, "tooltip": {"mode": "multi"}},
"targets": [
{"expr": "histogram_quantile(0.50, sum by (le) (rate(messenger_http_duration_seconds_bucket{http_route!~\"/health/.*\"}[5m])))", "legendFormat": "p50", "refId": "A"},
{"expr": "histogram_quantile(0.95, sum by (le) (rate(messenger_http_duration_seconds_bucket{http_route!~\"/health/.*\"}[5m])))", "legendFormat": "p95", "refId": "B"},
{"expr": "histogram_quantile(0.99, sum by (le) (rate(messenger_http_duration_seconds_bucket{http_route!~\"/health/.*\"}[5m])))", "legendFormat": "p99", "refId": "C"}
],
"title": "API latency percentiles from merged histogram buckets",
"type": "timeseries"
},
{
"datasource": {"type": "prometheus", "uid": "prometheus"},
"fieldConfig": {"defaults": {"unit": "s"}, "overrides": []},
"gridPos": {"h": 8, "w": 12, "x": 12, "y": 7},
"id": 4,
"options": {"legend": {"displayMode": "list", "placement": "bottom"}, "tooltip": {"mode": "multi"}},
"targets": [
{"expr": "histogram_quantile(0.50, sum by (le) (rate(messenger_jobs_duration_seconds_bucket{job_type=\"attachment.process.v1\"}[5m])))", "legendFormat": "p50", "refId": "A"},
{"expr": "histogram_quantile(0.95, sum by (le) (rate(messenger_jobs_duration_seconds_bucket{job_type=\"attachment.process.v1\"}[5m])))", "legendFormat": "p95", "refId": "B"},
{"expr": "histogram_quantile(0.99, sum by (le) (rate(messenger_jobs_duration_seconds_bucket{job_type=\"attachment.process.v1\"}[5m])))", "legendFormat": "p99", "refId": "C"}
],
"title": "Worker job duration percentiles from histogram buckets",
"type": "timeseries"
},
{
"datasource": {"type": "prometheus", "uid": "prometheus"},
"fieldConfig": {"defaults": {"unit": "short"}, "overrides": []},
"gridPos": {"h": 7, "w": 8, "x": 0, "y": 15},
"id": 5,
"options": {"legend": {"displayMode": "list", "placement": "bottom"}, "tooltip": {"mode": "multi"}},
"targets": [{"expr": "sum by (outcome) (rate(messenger_jobs_processed_total[5m]))", "legendFormat": "{{outcome}}", "refId": "A"}],
"title": "Jobs processed / failed per second",
"type": "timeseries"
},
{
"datasource": {"type": "prometheus", "uid": "prometheus"},
"fieldConfig": {"defaults": {"unit": "short"}, "overrides": []},
"gridPos": {"h": 7, "w": 8, "x": 8, "y": 15},
"id": 6,
"options": {"legend": {"displayMode": "list", "placement": "bottom"}, "tooltip": {"mode": "multi"}},
"targets": [{"expr": "max(messenger_queue_depth)", "legendFormat": "queued attachments", "refId": "A"}],
"title": "Durable attachment backlog",
"type": "timeseries"
},
{
"datasource": {"type": "prometheus", "uid": "prometheus"},
"fieldConfig": {"defaults": {"unit": "s"}, "overrides": []},
"gridPos": {"h": 7, "w": 8, "x": 16, "y": 15},
"id": 7,
"options": {"legend": {"displayMode": "list", "placement": "bottom"}, "tooltip": {"mode": "multi"}},
"targets": [{"expr": "max(messenger_queue_oldest_age_seconds)", "legendFormat": "oldest queued job", "refId": "A"}],
"title": "Age of oldest queued attachment",
"type": "timeseries"
},
{
"datasource": {"type": "prometheus", "uid": "prometheus"},
"fieldConfig": {"defaults": {"unit": "short"}, "overrides": []},
"gridPos": {"h": 7, "w": 8, "x": 0, "y": 22},
"id": 8,
"options": {"legend": {"displayMode": "list", "placement": "bottom"}, "tooltip": {"mode": "multi"}},
"targets": [{"expr": "max(messenger_db_pool_connections_used)", "legendFormat": "used", "refId": "A"}, {"expr": "max(messenger_db_pool_requests_waiting)", "legendFormat": "waiting", "refId": "B"}],
"title": "Database pool use / waiters",
"type": "timeseries"
},
{
"datasource": {"type": "prometheus", "uid": "prometheus"},
"fieldConfig": {"defaults": {"unit": "percentunit"}, "overrides": []},
"gridPos": {"h": 7, "w": 8, "x": 8, "y": 22},
"id": 9,
"options": {"legend": {"displayMode": "list", "placement": "bottom"}, "tooltip": {"mode": "multi"}},
"targets": [{"expr": "max(messenger_worker_busy) / clamp_min(max(messenger_worker_capacity), 1)", "legendFormat": "busy / capacity", "refId": "A"}],
"title": "Worker saturation",
"type": "timeseries"
},
{
"datasource": {"type": "prometheus", "uid": "prometheus"},
"fieldConfig": {"defaults": {"unit": "bytes"}, "overrides": []},
"gridPos": {"h": 7, "w": 8, "x": 16, "y": 22},
"id": 10,
"options": {"legend": {"displayMode": "list", "placement": "bottom"}, "tooltip": {"mode": "multi"}},
"targets": [{"expr": "max(messenger_process_memory_usage)", "legendFormat": "RSS", "refId": "A"}],
"title": "Process memory",
"type": "timeseries"
},
{
"datasource": {"type": "prometheus", "uid": "prometheus"},
"fieldConfig": {"defaults": {"unit": "percentunit"}, "overrides": []},
"gridPos": {"h": 7, "w": 8, "x": 0, "y": 29},
"id": 11,
"options": {"legend": {"displayMode": "list", "placement": "bottom"}, "tooltip": {"mode": "multi"}},
"targets": [{"expr": "max(messenger_process_cpu_utilization)", "legendFormat": "CPU / core", "refId": "A"}],
"title": "Process CPU utilization",
"type": "timeseries"
},
{
"datasource": {"type": "prometheus", "uid": "prometheus"},
"fieldConfig": {"defaults": {"unit": "s"}, "overrides": []},
"gridPos": {"h": 7, "w": 16, "x": 8, "y": 29},
"id": 12,
"options": {"legend": {"displayMode": "list", "placement": "bottom"}, "tooltip": {"mode": "multi"}},
"targets": [{"expr": "histogram_quantile(0.95, sum by (le) (rate(messenger_attachments_time_to_ready_seconds_bucket[5m])))", "legendFormat": "p95 time to ready", "refId": "A"}],
"title": "Durable acceptance to attachment ready",
"type": "timeseries"
},
{
"datasource": {"type": "loki", "uid": "loki"},
"gridPos": {"h": 8, "w": 24, "x": 0, "y": 36},
"id": 13,
"options": {"dedupStrategy": "none", "enableLogDetails": true, "prettifyLogMessage": true, "showCommonLabels": false, "showLabels": true, "showTime": true, "sortOrder": "Descending", "wrapLogMessage": true},
"targets": [{"expr": "{service_name=~\"messenger-api|messenger-worker\"} | json", "refId": "A"}],
"title": "Structured API / worker logs",
"type": "logs"
},
{
"datasource": {"type": "prometheus", "uid": "prometheus"},
"fieldConfig": {"defaults": {"unit": "percentunit", "min": 0.9, "max": 1}, "overrides": []},
"gridPos": {"h": 7, "w": 12, "x": 0, "y": 44},
"id": 14,
"options": {"legend": {"displayMode": "list", "placement": "bottom"}, "tooltip": {"mode": "single"}},
"targets": [{"expr": "messenger:api_availability:ratio7d", "legendFormat": "7-day availability; objective 99%", "refId": "A"}],
"title": "API SLI: 7-day rolling availability (99% SLO)",
"type": "timeseries"
}
],
"schemaVersion": 39,
"tags": ["messenger", "observability"],
"templating": {"list": []},
"time": {"from": "now-1h", "to": "now"},
"timezone": "browser",
"title": "Messenger observability",
"uid": "messenger-observability",
"version": 1
}
@@ -0,0 +1,11 @@
apiVersion: 1
providers:
- name: Messenger
orgId: 1
folder: Messenger
type: file
disableDeletion: true
editable: false
options:
path: /var/lib/grafana/dashboards
@@ -0,0 +1,39 @@
apiVersion: 1
datasources:
- name: Prometheus
uid: prometheus
type: prometheus
access: proxy
url: https://prometheus:9090
isDefault: true
editable: false
- name: Loki
uid: loki
type: loki
access: proxy
url: https://loki:3100
jsonData:
derivedFields:
- name: TraceID
matcherRegex: '"trace_id":"([a-f0-9]+)"'
url: "$${__value.raw}"
datasourceUid: tempo
editable: false
- name: Tempo
uid: tempo
type: tempo
access: proxy
url: https://tempo:3200
jsonData:
tracesToLogsV2:
datasourceUid: loki
spanStartTimeShift: "-1h"
spanEndTimeShift: "1h"
filterByTraceID: true
filterBySpanID: false
customQuery: true
query: '{$${__tags}} | json | trace_id="$${__trace.traceId}"'
serviceMap:
datasourceUid: prometheus
editable: false
+37
View File
@@ -0,0 +1,37 @@
auth_enabled: false
server:
http_listen_port: 3100
http_tls_config:
cert_file: /run/secrets/loki_tls_cert
key_file: /run/secrets/loki_tls_key
common:
path_prefix: /loki
storage:
filesystem:
chunks_directory: /loki/chunks
rules_directory: /loki/rules
replication_factor: 1
ring:
kvstore:
store: inmemory
schema_config:
configs:
- from: "2024-01-01"
store: tsdb
object_store: filesystem
schema: v13
index:
prefix: index_
period: 24h
limits_config:
allow_structured_metadata: true
retention_period: 168h
compactor:
working_directory: /loki/compactor
retention_enabled: true
delete_request_store: filesystem
+3
View File
@@ -0,0 +1,3 @@
tls_server_config:
cert_file: /run/secrets/prometheus_tls_cert
key_file: /run/secrets/prometheus_tls_key
+20
View File
@@ -0,0 +1,20 @@
global:
scrape_interval: 10s
evaluation_interval: 10s
rule_files:
- /etc/prometheus/alerts.yml
scrape_configs:
- job_name: otel-collector
scheme: https
tls_config:
ca_file: /run/secrets/ca_crt
cert_file: /run/secrets/collector_prometheus_client_cert
key_file: /run/secrets/collector_prometheus_client_key
server_name: otel-collector
static_configs:
- targets: ["otel-collector:9464"]
- job_name: prometheus
static_configs:
- targets: ["localhost:9090"]
+36
View File
@@ -0,0 +1,36 @@
server:
http_listen_port: 3200
http_tls_config:
cert_file: /run/secrets/tempo_tls_cert
key_file: /run/secrets/tempo_tls_key
distributor:
receivers:
otlp:
protocols:
grpc:
endpoint: 0.0.0.0:4317
tls:
cert_file: /run/secrets/tempo_tls_cert
key_file: /run/secrets/tempo_tls_key
http:
endpoint: 0.0.0.0:4318
tls:
cert_file: /run/secrets/tempo_tls_cert
key_file: /run/secrets/tempo_tls_key
ingester:
max_block_duration: 5m
trace_idle_period: 10s
compactor:
compaction:
block_retention: 168h
storage:
trace:
backend: local
wal:
path: /var/tempo/wal
local:
path: /var/tempo/blocks
+3
View File
@@ -0,0 +1,3 @@
local all all trust
hostssl all all all scram-sha-256
hostnossl all all all reject