forked from mtusi2026/mtusi2026lab6
Перенесён минимум lab5 без изменения API и добавлена наблюдаемость: - OTel SDK в API и worker: traces, metrics, logs по OTLP; W3C trace context API -> outbox -> RabbitMQ -> worker (producer/consumer spans, retry в той же трассе); - OTel Collector (memory_limiter, scrub, batch, ограниченные очереди, профиль tail sampling), Prometheus, Loki, Tempo, Grafana с provisioning, dashboard и 6 alert rules с runbooks; - проверки: наблюдаемость и приватность, инциденты A/B/C, насыщение worker, переполнение очереди exporter, эксперимент трека 1 (4 конфигурации x 3 прогона); - CI job со сборкой и запуском стенда; REPORT.md с доказательствами в evidence/.
461 lines
13 KiB
YAML
461 lines
13 KiB
YAML
name: mtusi-lab6
|
|
|
|
# OpenTelemetry SDK settings shared by the API replicas and the worker (track 1 overrides them from the shell).
|
|
x-otel-env: &otel-env
|
|
OTEL_SDK_DISABLED: ${OTEL_SDK_DISABLED:-false}
|
|
OTEL_TRACES_SAMPLER_ARG: ${OTEL_TRACES_SAMPLER_ARG:-1.0}
|
|
OTEL_EXPORTER_OTLP_ENDPOINT: http://otel-collector:4318
|
|
OTEL_EXPORTER_OTLP_PROTOCOL: http/protobuf
|
|
OTEL_EXPORTER_OTLP_TIMEOUT: "5"
|
|
OTEL_RESOURCE_ATTRIBUTES: deployment.environment.name=lab
|
|
OTEL_SEMCONV_STABILITY_OPT_IN: http
|
|
OTEL_METRIC_EXPORT_INTERVAL: ${OTEL_METRIC_EXPORT_INTERVAL:-10000}
|
|
OTEL_BSP_MAX_QUEUE_SIZE: "2048"
|
|
OTEL_BSP_SCHEDULE_DELAY: "2000"
|
|
OTEL_BLRP_MAX_QUEUE_SIZE: "2048"
|
|
SERVICE_VERSION: "1.6.0"
|
|
|
|
x-api: &api-defaults
|
|
build:
|
|
context: .
|
|
image: mtusi-messenger:lab6
|
|
env_file:
|
|
- .env
|
|
secrets:
|
|
- database_url
|
|
- cache_url
|
|
- s3_access_key_id
|
|
- s3_secret_access_key
|
|
- broker_url
|
|
depends_on:
|
|
rabbitmq:
|
|
condition: service_healthy
|
|
postgres:
|
|
condition: service_healthy
|
|
valkey:
|
|
condition: service_healthy
|
|
minio-init:
|
|
condition: service_completed_successfully
|
|
migrate:
|
|
condition: service_completed_successfully
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
cpus: "0.50"
|
|
memory: 512M
|
|
healthcheck:
|
|
test: ["CMD-SHELL", "python -c \"import urllib.request,sys; sys.exit(0 if urllib.request.urlopen('http://127.0.0.1:8080/health/ready', timeout=2).status == 200 else 1)\""]
|
|
interval: 5s
|
|
timeout: 3s
|
|
retries: 3
|
|
start_period: 15s
|
|
restart: unless-stopped
|
|
|
|
services:
|
|
nginx:
|
|
image: nginx:1.27.3-alpine
|
|
command: ["/bin/sh", "/opt/nginx-health.sh"]
|
|
environment:
|
|
API_UPSTREAMS: ${API_UPSTREAMS:-api-1 api-2}
|
|
HEALTH_INTERVAL: "1"
|
|
HEALTH_FALL: "2"
|
|
HEALTH_RISE: "2"
|
|
ports:
|
|
- "127.0.0.1:8080:8080"
|
|
volumes:
|
|
- ./infra/nginx.conf:/etc/nginx/nginx.conf:ro
|
|
- ./infra/nginx-health.sh:/opt/nginx-health.sh:ro
|
|
depends_on:
|
|
api-1:
|
|
condition: service_healthy
|
|
api-2:
|
|
condition: service_healthy
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
cpus: "0.25"
|
|
memory: 64M
|
|
healthcheck:
|
|
test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:8080/health/live || exit 1"]
|
|
interval: 5s
|
|
timeout: 3s
|
|
retries: 3
|
|
start_period: 5s
|
|
restart: unless-stopped
|
|
|
|
api-1:
|
|
<<: *api-defaults
|
|
environment:
|
|
<<: *otel-env
|
|
INSTANCE_ID: api-1
|
|
DATABASE_URL_FILE: /run/secrets/database_url
|
|
CACHE_URL_FILE: /run/secrets/cache_url
|
|
S3_ACCESS_KEY_ID_FILE: /run/secrets/s3_access_key_id
|
|
S3_SECRET_ACCESS_KEY_FILE: /run/secrets/s3_secret_access_key
|
|
S3_ENDPOINT: http://minio:9000
|
|
BROKER_URL_FILE: /run/secrets/broker_url
|
|
MAX_PENDING_JOBS: ${MAX_PENDING_JOBS:-200}
|
|
|
|
api-2:
|
|
<<: *api-defaults
|
|
environment:
|
|
<<: *otel-env
|
|
INSTANCE_ID: api-2
|
|
DATABASE_URL_FILE: /run/secrets/database_url
|
|
CACHE_URL_FILE: /run/secrets/cache_url
|
|
S3_ACCESS_KEY_ID_FILE: /run/secrets/s3_access_key_id
|
|
S3_SECRET_ACCESS_KEY_FILE: /run/secrets/s3_secret_access_key
|
|
S3_ENDPOINT: http://minio:9000
|
|
BROKER_URL_FILE: /run/secrets/broker_url
|
|
MAX_PENDING_JOBS: ${MAX_PENDING_JOBS:-200}
|
|
|
|
worker:
|
|
build:
|
|
context: .
|
|
image: mtusi-messenger:lab6
|
|
command: ["python", "-m", "app.worker"]
|
|
env_file:
|
|
- .env
|
|
environment:
|
|
<<: *otel-env
|
|
DATABASE_URL_FILE: /run/secrets/database_url
|
|
S3_ACCESS_KEY_ID_FILE: /run/secrets/s3_access_key_id
|
|
S3_SECRET_ACCESS_KEY_FILE: /run/secrets/s3_secret_access_key
|
|
BROKER_URL_FILE: /run/secrets/broker_url
|
|
S3_ENDPOINT: http://minio:9000
|
|
CACHE_URL_FILE: ""
|
|
INSTANCE_ID: ""
|
|
DB_POOL_MAX: "6"
|
|
# Overridable from the shell for the track-1 experiment (shell env wins over .env interpolation).
|
|
WORKER_CONCURRENCY: ${WORKER_CONCURRENCY:-2}
|
|
WORKER_PREFETCH: ${WORKER_PREFETCH:-2}
|
|
secrets:
|
|
- database_url
|
|
- s3_access_key_id
|
|
- s3_secret_access_key
|
|
- broker_url
|
|
depends_on:
|
|
rabbitmq:
|
|
condition: service_healthy
|
|
postgres:
|
|
condition: service_healthy
|
|
minio-init:
|
|
condition: service_completed_successfully
|
|
migrate:
|
|
condition: service_completed_successfully
|
|
stop_grace_period: 30s
|
|
deploy:
|
|
replicas: ${WORKER_REPLICAS:-2}
|
|
resources:
|
|
limits:
|
|
cpus: "${WORKER_CPUS:-2.00}"
|
|
memory: 1536M
|
|
healthcheck:
|
|
test: ["CMD-SHELL", "python -c \"import os,sys,time; sys.exit(0 if time.time()-os.path.getmtime('/tmp/worker-heartbeat') < 15 else 1)\""]
|
|
interval: 5s
|
|
timeout: 3s
|
|
retries: 3
|
|
start_period: 15s
|
|
restart: unless-stopped
|
|
|
|
rabbitmq:
|
|
image: rabbitmq:4.0.5-alpine@sha256:e045b5166b9188a38eee5c99411709aa1f0ffa2ac75664053e64cb69411f7c32
|
|
hostname: rabbitmq
|
|
entrypoint: ["/bin/sh", "/opt/entrypoint.sh"]
|
|
secrets:
|
|
- rabbitmq_password
|
|
volumes:
|
|
- rabbitmqdata:/var/lib/rabbitmq
|
|
- ./infra/rabbitmq/rabbitmq.conf:/etc/rabbitmq/rabbitmq.conf:ro
|
|
- ./infra/rabbitmq/entrypoint.sh:/opt/entrypoint.sh:ro
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
cpus: "1.00"
|
|
memory: 512M
|
|
healthcheck:
|
|
test: ["CMD", "rabbitmq-diagnostics", "-q", "check_port_connectivity"]
|
|
interval: 5s
|
|
timeout: 10s
|
|
retries: 20
|
|
start_period: 20s
|
|
restart: unless-stopped
|
|
|
|
postgres:
|
|
image: postgres:17.7-alpine@sha256:bb377b7239d2774ac8cc76f481596ce96c5a6b5e9d141f6d0a0ee371a6e7c0f2
|
|
environment:
|
|
POSTGRES_DB: messenger
|
|
POSTGRES_USER: messenger
|
|
POSTGRES_PASSWORD_FILE: /run/secrets/postgres_password
|
|
POSTGRES_INITDB_ARGS: --data-checksums
|
|
command:
|
|
- postgres
|
|
- -c
|
|
- synchronous_commit=on
|
|
- -c
|
|
- shared_buffers=128MB
|
|
- -c
|
|
- work_mem=8MB
|
|
- -c
|
|
- max_connections=50
|
|
- -c
|
|
- track_io_timing=on
|
|
secrets:
|
|
- postgres_password
|
|
volumes:
|
|
- pgdata:/var/lib/postgresql/data
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
cpus: "1.00"
|
|
memory: 512M
|
|
healthcheck:
|
|
test: ["CMD-SHELL", "pg_isready -U messenger -d messenger"]
|
|
interval: 5s
|
|
timeout: 3s
|
|
retries: 20
|
|
start_period: 10s
|
|
restart: unless-stopped
|
|
|
|
valkey:
|
|
image: valkey/valkey:8.1-alpine@sha256:081c2f5cb575efc901aa80ff9cdbd1ec6a301682fd35e1ebb4b0990a4a4a8507
|
|
command:
|
|
- valkey-server
|
|
- --save
|
|
- ""
|
|
- --appendonly
|
|
- "no"
|
|
- --maxmemory
|
|
- 64mb
|
|
- --maxmemory-policy
|
|
- allkeys-lru
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
cpus: "0.25"
|
|
memory: 128M
|
|
healthcheck:
|
|
test: ["CMD", "valkey-cli", "ping"]
|
|
interval: 5s
|
|
timeout: 3s
|
|
retries: 10
|
|
start_period: 5s
|
|
restart: unless-stopped
|
|
|
|
minio:
|
|
image: madlabcg/minio@sha256:ad134b2dd572ae0d989d6807c3e45516cc75a34883a8021db2ff04be5d1d496a
|
|
command: ["server", "/data"]
|
|
environment:
|
|
MINIO_ROOT_USER_FILE: /run/secrets/minio_root_user
|
|
MINIO_ROOT_PASSWORD_FILE: /run/secrets/minio_root_password
|
|
MINIO_BROWSER: "off"
|
|
secrets:
|
|
- minio_root_user
|
|
- minio_root_password
|
|
volumes:
|
|
- miniodata:/data
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
cpus: "0.50"
|
|
memory: 512M
|
|
healthcheck:
|
|
test: ["CMD-SHELL", "mc ready local || exit 1"]
|
|
interval: 5s
|
|
timeout: 3s
|
|
retries: 10
|
|
start_period: 10s
|
|
restart: unless-stopped
|
|
|
|
minio-init:
|
|
image: madlabcg/minio@sha256:ad134b2dd572ae0d989d6807c3e45516cc75a34883a8021db2ff04be5d1d496a
|
|
entrypoint: ["/bin/sh", "/opt/init.sh"]
|
|
environment:
|
|
S3_BUCKET: messenger-attachments
|
|
secrets:
|
|
- minio_root_user
|
|
- minio_root_password
|
|
- s3_access_key_id
|
|
- s3_secret_access_key
|
|
volumes:
|
|
- ./infra/minio/init.sh:/opt/init.sh:ro
|
|
- ./infra/minio/app-policy.json:/etc/minio-policy/app-policy.json:ro
|
|
depends_on:
|
|
minio:
|
|
condition: service_healthy
|
|
restart: "no"
|
|
|
|
migrate:
|
|
build:
|
|
context: .
|
|
image: mtusi-messenger:lab6
|
|
command: ["python", "scripts/migrate.py"]
|
|
environment:
|
|
DATABASE_URL_FILE: /run/secrets/database_url
|
|
secrets:
|
|
- database_url
|
|
depends_on:
|
|
postgres:
|
|
condition: service_healthy
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
cpus: "0.25"
|
|
memory: 128M
|
|
restart: "no"
|
|
|
|
# ------------------------------------------------------------------ observability (lab6)
|
|
otel-collector:
|
|
image: otel/opentelemetry-collector-contrib:0.120.0@sha256:85ac41c2db88d0df9bd6145e608a3cb023f5d8443868adbfbbf66efb51087917
|
|
command:
|
|
- --config=/etc/otelcol/collector.yaml
|
|
- --config=/etc/otelcol/profile-${COLLECTOR_PROFILE:-default}.yaml
|
|
volumes:
|
|
- ./infra/otel/collector.yaml:/etc/otelcol/collector.yaml:ro
|
|
- ./infra/otel/profile-default.yaml:/etc/otelcol/profile-default.yaml:ro
|
|
- ./infra/otel/profile-tail.yaml:/etc/otelcol/profile-tail.yaml:ro
|
|
# OTLP 4317/4318 and self-metrics 8888 stay inside the compose network.
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
cpus: "1.00"
|
|
memory: 256M
|
|
restart: unless-stopped
|
|
|
|
prometheus:
|
|
image: prom/prometheus:v3.2.1@sha256:6927e0919a144aa7616fd0137d4816816d42f6b816de3af269ab065250859a62
|
|
command:
|
|
- --config.file=/etc/prometheus/prometheus.yml
|
|
- --storage.tsdb.path=/prometheus
|
|
- --storage.tsdb.retention.time=15d
|
|
- --web.enable-otlp-receiver
|
|
- --web.enable-lifecycle
|
|
volumes:
|
|
- ./infra/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml:ro
|
|
- ./infra/prometheus/rules:/etc/prometheus/rules:ro
|
|
- promdata:/prometheus
|
|
ports:
|
|
- "127.0.0.1:9090:9090" # query API for evidence scripts (localhost only)
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
cpus: "1.00"
|
|
memory: 512M
|
|
healthcheck:
|
|
test: ["CMD", "wget", "-qO-", "http://127.0.0.1:9090/-/ready"]
|
|
interval: 5s
|
|
timeout: 3s
|
|
retries: 20
|
|
restart: unless-stopped
|
|
|
|
loki:
|
|
image: grafana/loki:3.4.2@sha256:58a6c186ce78ba04d58bfe2a927eff296ba733a430df09645d56cdc158f3ba08
|
|
command: ["-config.file=/etc/loki/loki.yaml"]
|
|
volumes:
|
|
- ./infra/loki/loki.yaml:/etc/loki/loki.yaml:ro
|
|
- lokidata:/loki
|
|
ports:
|
|
- "127.0.0.1:3100:3100"
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
cpus: "1.00"
|
|
memory: 512M
|
|
healthcheck:
|
|
test: ["CMD", "wget", "-qO-", "http://127.0.0.1:3100/ready"]
|
|
interval: 5s
|
|
timeout: 3s
|
|
retries: 30
|
|
start_period: 15s
|
|
restart: unless-stopped
|
|
|
|
tempo:
|
|
image: grafana/tempo:2.7.1@sha256:4443be217c396b065ee34845534199c36fdba4dc619cb96550e228d73fba6e69
|
|
command: ["-config.file=/etc/tempo/tempo.yaml"]
|
|
volumes:
|
|
- ./infra/tempo/tempo.yaml:/etc/tempo/tempo.yaml:ro
|
|
- tempodata:/var/tempo
|
|
ports:
|
|
- "127.0.0.1:3200:3200"
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
cpus: "1.00"
|
|
memory: 1024M
|
|
healthcheck:
|
|
test: ["CMD", "wget", "-qO-", "http://127.0.0.1:3200/ready"]
|
|
interval: 5s
|
|
timeout: 3s
|
|
retries: 30
|
|
start_period: 15s
|
|
restart: unless-stopped
|
|
|
|
grafana:
|
|
image: grafana/grafana:11.5.2@sha256:8b37a2f028f164ce7b9889e1765b9d6ee23fec80f871d156fbf436d6198d32b7
|
|
environment:
|
|
GF_SECURITY_ADMIN_USER: admin
|
|
GF_SECURITY_ADMIN_PASSWORD__FILE: /run/secrets/grafana_admin_password
|
|
GF_USERS_ALLOW_SIGN_UP: "false"
|
|
GF_ANALYTICS_REPORTING_ENABLED: "false"
|
|
GF_ANALYTICS_CHECK_FOR_UPDATES: "false"
|
|
GF_NEWS_NEWS_FEED_ENABLED: "false"
|
|
GF_DASHBOARDS_DEFAULT_HOME_DASHBOARD_PATH: /var/lib/grafana/dashboards/messenger.json
|
|
secrets:
|
|
- grafana_admin_password
|
|
volumes:
|
|
- ./infra/grafana/provisioning:/etc/grafana/provisioning:ro
|
|
- ./infra/grafana/dashboards:/var/lib/grafana/dashboards:ro
|
|
- grafanadata:/var/lib/grafana
|
|
ports:
|
|
- "127.0.0.1:3000:3000"
|
|
depends_on:
|
|
prometheus:
|
|
condition: service_healthy
|
|
loki:
|
|
condition: service_started
|
|
tempo:
|
|
condition: service_started
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
cpus: "0.50"
|
|
memory: 256M
|
|
healthcheck:
|
|
test: ["CMD", "wget", "-qO-", "http://127.0.0.1:3000/api/health"]
|
|
interval: 5s
|
|
timeout: 3s
|
|
retries: 30
|
|
start_period: 15s
|
|
restart: unless-stopped
|
|
|
|
volumes:
|
|
pgdata:
|
|
miniodata:
|
|
rabbitmqdata:
|
|
promdata:
|
|
lokidata:
|
|
tempodata:
|
|
grafanadata:
|
|
|
|
secrets:
|
|
minio_root_user:
|
|
file: ./secrets/minio_root_user
|
|
minio_root_password:
|
|
file: ./secrets/minio_root_password
|
|
postgres_password:
|
|
file: ./secrets/postgres_password
|
|
database_url:
|
|
file: ./secrets/database_url
|
|
cache_url:
|
|
file: ./secrets/cache_url
|
|
s3_access_key_id:
|
|
file: ./secrets/s3_access_key_id
|
|
s3_secret_access_key:
|
|
file: ./secrets/s3_secret_access_key
|
|
broker_url:
|
|
file: ./secrets/broker_url
|
|
rabbitmq_password:
|
|
file: ./secrets/rabbitmq_password
|
|
grafana_admin_password:
|
|
file: ./secrets/grafana_admin_password
|