Instrument durable messenger with OTel, provision Grafana and prove SLO incident detection
This commit is contained in:
+253
@@ -0,0 +1,253 @@
|
||||
name: mtusi-lab6-kraykin
|
||||
x-api: &api
|
||||
logging: {driver: json-file, options: {max-size: 10m, max-file: "3"}}
|
||||
image: mtusi-messenger:lab6
|
||||
build: .
|
||||
environment: &api-env
|
||||
APP_PORT: 8080
|
||||
SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600}
|
||||
DATABASE_URL_FILE: /run/secrets/database_url
|
||||
CACHE_URL_FILE: /run/secrets/cache_url
|
||||
CURSOR_KEY_FILE: /run/secrets/cursor_key
|
||||
S3_ENDPOINT: http://s3:9000
|
||||
S3_BUCKET: messenger-attachments
|
||||
S3_ACCESS_KEY_ID_FILE: /run/secrets/s3_access_key_id
|
||||
S3_SECRET_ACCESS_KEY_FILE: /run/secrets/s3_secret_access_key
|
||||
OTEL_EXPORTER_OTLP_ENDPOINT: http://collector:4318
|
||||
OTEL_EXPORTER_OTLP_PROTOCOL: http/protobuf
|
||||
GOMEMLIMIT: 600MiB
|
||||
DB_POOL_MAX: ${DB_POOL_MAX:-10}
|
||||
secrets: [database_url, cache_url, cursor_key, s3_access_key_id, s3_secret_access_key]
|
||||
cpus: ${API_CPUS:-1}
|
||||
mem_limit: ${API_MEMORY:-768m}
|
||||
stop_grace_period: 8s
|
||||
services:
|
||||
postgres:
|
||||
image: postgres:17.6-alpine
|
||||
environment:
|
||||
POSTGRES_DB: messenger
|
||||
POSTGRES_USER: messenger
|
||||
POSTGRES_PASSWORD_FILE: /run/secrets/postgres_password
|
||||
secrets: [postgres_password]
|
||||
volumes: [postgres_data:/var/lib/postgresql/data]
|
||||
cpus: 2
|
||||
mem_limit: 512m
|
||||
shm_size: 128m
|
||||
healthcheck:
|
||||
test: [CMD-SHELL, 'pg_isready -U messenger -d messenger']
|
||||
interval: 1s
|
||||
timeout: 2s
|
||||
retries: 30
|
||||
valkey:
|
||||
image: valkey/valkey:8.1.3-alpine
|
||||
command: [valkey-server, /run/secrets/valkey_config]
|
||||
secrets: [valkey_config]
|
||||
cpus: 0.5
|
||||
mem_limit: 128m
|
||||
s3:
|
||||
image: quay.io/minio/minio:RELEASE.2025-09-07T16-13-09Z
|
||||
command: [server, /data, --console-address, '127.0.0.1:9001']
|
||||
environment:
|
||||
MINIO_ROOT_USER_FILE: /run/secrets/s3_root_user
|
||||
MINIO_ROOT_PASSWORD_FILE: /run/secrets/s3_root_password
|
||||
secrets: [s3_root_user, s3_root_password]
|
||||
volumes: [s3_data:/data]
|
||||
cpus: 1
|
||||
mem_limit: 512m
|
||||
healthcheck:
|
||||
test: [CMD, curl, -f, http://localhost:9000/minio/health/ready]
|
||||
interval: 1s
|
||||
timeout: 2s
|
||||
retries: 30
|
||||
s3-init:
|
||||
image: minio/mc:RELEASE.2025-08-13T08-35-41Z
|
||||
entrypoint: [/bin/sh, /config/s3-init.sh]
|
||||
volumes: ['./infra:/config:ro']
|
||||
secrets: [s3_root_user, s3_root_password, s3_access_key_id, s3_secret_access_key]
|
||||
depends_on:
|
||||
s3: {condition: service_healthy}
|
||||
cpus: 0.5
|
||||
mem_limit: 128m
|
||||
migrate:
|
||||
<<: *api
|
||||
secrets: [database_url]
|
||||
command: [migrate]
|
||||
depends_on:
|
||||
postgres: {condition: service_healthy}
|
||||
restart: 'no'
|
||||
api:
|
||||
<<: *api
|
||||
deploy:
|
||||
replicas: ${API_REPLICAS:-2}
|
||||
depends_on:
|
||||
s3-init: {condition: service_completed_successfully}
|
||||
migrate: {condition: service_completed_successfully}
|
||||
valkey: {condition: service_started}
|
||||
broker:
|
||||
image: valkey/valkey:8.1.3-alpine
|
||||
command: [valkey-server, /run/secrets/broker_config]
|
||||
secrets: [broker_config, broker_url]
|
||||
volumes: [broker_data:/data]
|
||||
cpus: 1
|
||||
mem_limit: 256m
|
||||
dispatcher:
|
||||
<<: *api
|
||||
command: [dispatcher]
|
||||
secrets: [database_url, broker_url, s3_access_key_id, s3_secret_access_key]
|
||||
healthcheck:
|
||||
test: [CMD-SHELL, 'kill -0 1']
|
||||
interval: 2s
|
||||
timeout: 1s
|
||||
retries: 3
|
||||
environment:
|
||||
<<: *api-env
|
||||
BROKER_URL_FILE: /run/secrets/broker_url
|
||||
DB_POOL_MAX: 2
|
||||
cpus: 0.25
|
||||
mem_limit: 128m
|
||||
depends_on:
|
||||
migrate: {condition: service_completed_successfully}
|
||||
broker: {condition: service_started}
|
||||
restart: unless-stopped
|
||||
worker:
|
||||
<<: *api
|
||||
command: [worker]
|
||||
secrets: [database_url, broker_url, s3_access_key_id, s3_secret_access_key]
|
||||
healthcheck:
|
||||
test: [CMD-SHELL, 'kill -0 1']
|
||||
interval: 2s
|
||||
timeout: 1s
|
||||
retries: 3
|
||||
environment:
|
||||
<<: *api-env
|
||||
BROKER_URL_FILE: /run/secrets/broker_url
|
||||
WORKER_CONCURRENCY: ${WORKER_CONCURRENCY:-1}
|
||||
DB_POOL_MAX: 4
|
||||
GOMEMLIMIT: 768MiB
|
||||
cpus: 1
|
||||
mem_limit: 1024m
|
||||
stop_grace_period: 35s
|
||||
depends_on:
|
||||
migrate: {condition: service_completed_successfully}
|
||||
s3-init: {condition: service_completed_successfully}
|
||||
broker: {condition: service_started}
|
||||
restart: unless-stopped
|
||||
housekeeping:
|
||||
<<: *api
|
||||
command: [housekeeping]
|
||||
secrets: [database_url, broker_url, s3_access_key_id, s3_secret_access_key]
|
||||
healthcheck:
|
||||
test: [CMD-SHELL, 'kill -0 1']
|
||||
interval: 2s
|
||||
timeout: 1s
|
||||
retries: 3
|
||||
environment:
|
||||
<<: *api-env
|
||||
BROKER_URL_FILE: /run/secrets/broker_url
|
||||
DB_POOL_MAX: 2
|
||||
cpus: 0.25
|
||||
mem_limit: 128m
|
||||
depends_on:
|
||||
migrate: {condition: service_completed_successfully}
|
||||
s3-init: {condition: service_completed_successfully}
|
||||
restart: unless-stopped
|
||||
tests:
|
||||
volumes: [go_test_cache:/root/.cache/go-build]
|
||||
image: mtusi-messenger-tests:lab6
|
||||
cpus: 2
|
||||
mem_limit: 1024m
|
||||
profiles: [verify]
|
||||
build:
|
||||
context: .
|
||||
target: tests
|
||||
environment:
|
||||
GOMAXPROCS: "2"
|
||||
GOFLAGS: -p=2
|
||||
DATABASE_TEST_URL_FILE: /run/secrets/database_url
|
||||
secrets: [database_url]
|
||||
depends_on:
|
||||
migrate: {condition: service_completed_successfully}
|
||||
lb:
|
||||
image: haproxy:3.2.6-alpine
|
||||
volumes: ['./infra/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro']
|
||||
ports: ['127.0.0.1:${APP_PORT:-8086}:8080']
|
||||
cpus: 1
|
||||
mem_limit: 128m
|
||||
depends_on:
|
||||
api: {condition: service_healthy}
|
||||
healthcheck:
|
||||
test: [CMD-SHELL, 'wget -q -O /dev/null http://127.0.0.1:8080/health/ready']
|
||||
interval: 2s
|
||||
timeout: 4s
|
||||
retries: 20
|
||||
collector:
|
||||
logging: {driver: json-file, options: {max-size: 10m, max-file: "3"}}
|
||||
image: otel/opentelemetry-collector-contrib:0.128.0
|
||||
command: [--config=/etc/otelcol/config.yaml]
|
||||
volumes: ['./infra/otel/collector.yaml:/etc/otelcol/config.yaml:ro']
|
||||
cpus: 0.5
|
||||
mem_limit: 256m
|
||||
restart: unless-stopped
|
||||
prometheus:
|
||||
image: prom/prometheus:v3.4.1
|
||||
command: [--config.file=/etc/prometheus/prometheus.yaml, --storage.tsdb.retention.time=24h, --storage.tsdb.retention.size=512MB]
|
||||
volumes: ['./infra/prometheus:/etc/prometheus:ro', 'prometheus_data:/prometheus']
|
||||
ports: ['127.0.0.1:${PROMETHEUS_PORT:-9096}:9090']
|
||||
cpus: 0.5
|
||||
mem_limit: 256m
|
||||
restart: unless-stopped
|
||||
loki:
|
||||
image: grafana/loki:3.5.1
|
||||
command: [-config.file=/etc/loki/local-config.yaml]
|
||||
volumes: ['./infra/loki/loki.yaml:/etc/loki/local-config.yaml:ro', 'loki_data:/loki']
|
||||
ports: ['127.0.0.1:${LOKI_PORT:-3106}:3100']
|
||||
cpus: 0.5
|
||||
mem_limit: 256m
|
||||
restart: unless-stopped
|
||||
tempo:
|
||||
image: grafana/tempo:2.8.0
|
||||
command: [-config.file=/etc/tempo.yaml]
|
||||
volumes: ['./infra/tempo/tempo.yaml:/etc/tempo.yaml:ro', 'tempo_data:/var/tempo']
|
||||
ports: ['127.0.0.1:${TEMPO_PORT:-3206}:3200']
|
||||
cpus: 0.5
|
||||
mem_limit: 256m
|
||||
restart: unless-stopped
|
||||
grafana:
|
||||
image: grafana/grafana:12.0.2
|
||||
environment:
|
||||
GF_AUTH_ANONYMOUS_ENABLED: 'true'
|
||||
GF_AUTH_ANONYMOUS_ORG_ROLE: Viewer
|
||||
GF_USERS_ALLOW_SIGN_UP: 'false'
|
||||
GF_SECURITY_ADMIN_USER: admin
|
||||
GF_SECURITY_ADMIN_PASSWORD__FILE: /run/secrets/grafana_password
|
||||
GF_PLUGINS_PREINSTALL_DISABLED: 'true'
|
||||
GF_ANALYTICS_REPORTING_ENABLED: 'false'
|
||||
GF_ANALYTICS_CHECK_FOR_UPDATES: 'false'
|
||||
secrets: [grafana_password]
|
||||
volumes: ['./infra/grafana/provisioning:/etc/grafana/provisioning:ro', './infra/grafana/dashboards:/var/lib/grafana/dashboards:ro', 'grafana_data:/var/lib/grafana']
|
||||
ports: ['127.0.0.1:${GRAFANA_PORT:-3006}:3000']
|
||||
cpus: 0.5
|
||||
mem_limit: 256m
|
||||
restart: unless-stopped
|
||||
secrets:
|
||||
grafana_password: {file: ./secrets/grafana_password}
|
||||
broker_url: {file: ./secrets/broker_url}
|
||||
broker_config: {file: ./secrets/broker_config}
|
||||
s3_root_user: {file: ./secrets/s3_root_user}
|
||||
s3_root_password: {file: ./secrets/s3_root_password}
|
||||
s3_access_key_id: {file: ./secrets/s3_access_key_id}
|
||||
s3_secret_access_key: {file: ./secrets/s3_secret_access_key}
|
||||
postgres_password: {file: ./secrets/postgres_password}
|
||||
database_url: {file: ./secrets/database_url}
|
||||
valkey_config: {file: ./secrets/valkey_config}
|
||||
cache_url: {file: ./secrets/cache_url}
|
||||
cursor_key: {file: ./secrets/cursor_key}
|
||||
volumes:
|
||||
go_test_cache:
|
||||
prometheus_data:
|
||||
loki_data:
|
||||
tempo_data:
|
||||
grafana_data:
|
||||
broker_data:
|
||||
s3_data:
|
||||
postgres_data:
|
||||
Reference in New Issue
Block a user