feat(lab6): complete observability stack with OTel, Grafana provisioning, worker metrics, alert rules, and incident experiments
This commit is contained in:
+267
@@ -0,0 +1,267 @@
|
||||
services:
|
||||
postgres:
|
||||
image: postgres:16.4-alpine
|
||||
environment:
|
||||
POSTGRES_USER: ${POSTGRES_USER}
|
||||
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
|
||||
POSTGRES_DB: ${POSTGRES_DB}
|
||||
volumes:
|
||||
- postgres_data:/var/lib/postgresql/data
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}"]
|
||||
interval: 5s
|
||||
timeout: 5s
|
||||
retries: 5
|
||||
deploy:
|
||||
resources:
|
||||
limits: {cpus: '1.0', memory: 512M}
|
||||
|
||||
redis:
|
||||
image: valkey/valkey:8.0-alpine
|
||||
command: valkey-server --appendonly yes --save 60 1
|
||||
volumes:
|
||||
- redis_data:/data
|
||||
healthcheck:
|
||||
test: ["CMD", "valkey-cli", "ping"]
|
||||
interval: 5s
|
||||
timeout: 5s
|
||||
retries: 5
|
||||
deploy:
|
||||
resources:
|
||||
limits: {cpus: '0.5', memory: 128M}
|
||||
|
||||
s3:
|
||||
image: chrislusf/seaweedfs:3.80
|
||||
command:
|
||||
- server
|
||||
- -dir=/data
|
||||
- -s3
|
||||
- -s3.port=8333
|
||||
- -master.volumeSizeLimitMB=64
|
||||
- -volume.max=100
|
||||
volumes:
|
||||
- s3data:/data
|
||||
healthcheck:
|
||||
test: ["CMD", "wget", "-q", "-O", "/dev/null", "http://127.0.0.1:8333/healthz"]
|
||||
interval: 5s
|
||||
timeout: 5s
|
||||
retries: 10
|
||||
start_period: 60s
|
||||
deploy:
|
||||
resources:
|
||||
limits: {cpus: '1.0', memory: 1G}
|
||||
|
||||
s3-init:
|
||||
image: amazon/aws-cli:2.15.0
|
||||
depends_on:
|
||||
s3:
|
||||
condition: service_healthy
|
||||
environment:
|
||||
- AWS_ACCESS_KEY_ID=admin
|
||||
- AWS_SECRET_ACCESS_KEY=admin
|
||||
- AWS_REGION=${S3_REGION}
|
||||
entrypoint: >
|
||||
/bin/sh -c "
|
||||
aws --endpoint-url http://s3:8333 s3 mb s3://${S3_BUCKET_NAME} 2>/dev/null || echo 'Bucket already exists'
|
||||
aws --endpoint-url http://s3:8333 s3api put-bucket-acl --bucket ${S3_BUCKET_NAME} --acl private
|
||||
echo 'Bucket ${S3_BUCKET_NAME} is ready and private'
|
||||
"
|
||||
restart: "no"
|
||||
|
||||
rabbitmq:
|
||||
image: rabbitmq:3.13-management-alpine
|
||||
hostname: rabbitmq
|
||||
environment:
|
||||
RABBITMQ_DEFAULT_USER: messenger
|
||||
RABBITMQ_DEFAULT_PASS: mq_secret_password
|
||||
RABBITMQ_DEFAULT_VHOST: /
|
||||
volumes:
|
||||
- mqdata:/var/lib/rabbitmq
|
||||
healthcheck:
|
||||
test: ["CMD", "rabbitmq-diagnostics", "-q", "check_port_connectivity"]
|
||||
interval: 5s
|
||||
timeout: 10s
|
||||
retries: 30
|
||||
deploy:
|
||||
resources:
|
||||
limits: {cpus: '1.0', memory: 512M}
|
||||
|
||||
otel-collector:
|
||||
image: otel/opentelemetry-collector-contrib:0.163.2
|
||||
command: ["--config=/etc/otelcol-contrib/collector.yaml"]
|
||||
volumes:
|
||||
- ./infra/otel/collector.yaml:/etc/otelcol-contrib/collector.yaml:ro
|
||||
depends_on:
|
||||
- tempo
|
||||
- loki
|
||||
deploy:
|
||||
resources:
|
||||
limits: {cpus: '0.5', memory: 512M}
|
||||
restart: unless-stopped
|
||||
|
||||
prometheus:
|
||||
image: prom/prometheus:v2.55.1
|
||||
ports: ["127.0.0.1:9090:9090"]
|
||||
command:
|
||||
- --config.file=/etc/prometheus/prometheus.yml
|
||||
- --storage.tsdb.path=/prometheus
|
||||
- --storage.tsdb.retention.time=15d
|
||||
volumes:
|
||||
- ./infra/otel/prometheus.yml:/etc/prometheus/prometheus.yml:ro
|
||||
- ./infra/otel/alerts.yml:/etc/prometheus/alerts.yml:ro
|
||||
- prometheus_data:/prometheus
|
||||
depends_on:
|
||||
- otel-collector
|
||||
deploy:
|
||||
resources:
|
||||
limits: {cpus: '0.5', memory: 512M}
|
||||
restart: unless-stopped
|
||||
|
||||
loki:
|
||||
image: grafana/loki:3.3.2
|
||||
command: ["-config.file=/etc/loki/loki.yml"]
|
||||
volumes:
|
||||
- ./infra/otel/loki.yml:/etc/loki/loki.yml:ro
|
||||
- loki_data:/loki
|
||||
deploy:
|
||||
resources:
|
||||
limits: {cpus: '0.5', memory: 512M}
|
||||
restart: unless-stopped
|
||||
|
||||
tempo:
|
||||
image: grafana/tempo:2.7.1
|
||||
command: ["-config.file=/etc/tempo/tempo.yml"]
|
||||
volumes:
|
||||
- ./infra/otel/tempo.yml:/etc/tempo/tempo.yml:ro
|
||||
- tempo_data:/var/tempo
|
||||
deploy:
|
||||
resources:
|
||||
limits: {cpus: '0.5', memory: 512M}
|
||||
restart: unless-stopped
|
||||
|
||||
grafana:
|
||||
image: grafana/grafana:11.4.0
|
||||
ports:
|
||||
- "127.0.0.1:3000:3000"
|
||||
environment:
|
||||
GF_SECURITY_ADMIN_USER: admin
|
||||
GF_SECURITY_ADMIN_PASSWORD: admin
|
||||
GF_USERS_ALLOW_SIGN_UP: "false"
|
||||
GF_ANALYTICS_REPORTING_ENABLED: "false"
|
||||
volumes:
|
||||
- grafana_data:/var/lib/grafana
|
||||
- ./infra/otel/grafana/provisioning:/etc/grafana/provisioning:ro
|
||||
- ./infra/otel/grafana/dashboards:/var/lib/grafana/dashboards:ro
|
||||
depends_on:
|
||||
- prometheus
|
||||
- loki
|
||||
- tempo
|
||||
deploy:
|
||||
resources:
|
||||
limits: {cpus: '0.5', memory: 512M}
|
||||
restart: unless-stopped
|
||||
|
||||
api:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
environment:
|
||||
- DATABASE_URL=${DATABASE_URL}
|
||||
- REDIS_URL=${REDIS_URL}
|
||||
- SECRET_SESSION_KEY=${SECRET_SESSION_KEY}
|
||||
- SESSION_TTL_SECONDS=${SESSION_TTL_SECONDS}
|
||||
- S3_ENDPOINT=${S3_ENDPOINT}
|
||||
- S3_ACCESS_KEY=${S3_API_ACCESS_KEY:-admin}
|
||||
- S3_SECRET_KEY=${S3_API_SECRET_KEY:-admin}
|
||||
- S3_BUCKET_NAME=${S3_BUCKET_NAME}
|
||||
- S3_REGION=${S3_REGION}
|
||||
- BROKER_URL=${BROKER_URL}
|
||||
- MAX_ACTIVE_JOBS=${MAX_ACTIVE_JOBS}
|
||||
- OTEL_EXPORTER_OTLP_ENDPOINT=${OTEL_EXPORTER_OTLP_ENDPOINT}
|
||||
- OTEL_SERVICE_NAME=messenger-api
|
||||
- OTEL_RESOURCE_ATTRIBUTES=service.version=1.0.0,deployment.environment=lab
|
||||
volumes:
|
||||
- ./alembic/versions:/app/alembic/versions
|
||||
- ./app:/app/app
|
||||
read_only: true
|
||||
tmpfs:
|
||||
- /tmp:size=15M
|
||||
depends_on:
|
||||
postgres:
|
||||
condition: service_healthy
|
||||
redis:
|
||||
condition: service_healthy
|
||||
s3-init:
|
||||
condition: service_completed_successfully
|
||||
rabbitmq:
|
||||
condition: service_healthy
|
||||
otel-collector:
|
||||
condition: service_started
|
||||
stop_grace_period: 30s
|
||||
healthcheck:
|
||||
test: ["CMD", "curl", "-f", "http://localhost:8080/health/live"]
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 3
|
||||
start_period: 10s
|
||||
deploy:
|
||||
resources:
|
||||
limits: {cpus: '0.5', memory: 256M}
|
||||
|
||||
worker:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
command: ["python", "-m", "app.worker"]
|
||||
environment:
|
||||
- DATABASE_URL=${DATABASE_URL}
|
||||
- BROKER_URL=${BROKER_URL}
|
||||
- S3_ENDPOINT=${S3_ENDPOINT}
|
||||
- S3_ACCESS_KEY=${S3_API_ACCESS_KEY:-admin}
|
||||
- S3_SECRET_KEY=${S3_API_SECRET_KEY:-admin}
|
||||
- S3_BUCKET_NAME=${S3_BUCKET_NAME}
|
||||
- WORKER_CONCURRENCY=${WORKER_CONCURRENCY}
|
||||
- JOB_MAX_ATTEMPTS=${JOB_MAX_ATTEMPTS}
|
||||
- JOB_LEASE_SECONDS=${JOB_LEASE_SECONDS}
|
||||
- OTEL_EXPORTER_OTLP_ENDPOINT=${OTEL_EXPORTER_OTLP_ENDPOINT}
|
||||
- OTEL_SERVICE_NAME=messenger-worker
|
||||
- OTEL_RESOURCE_ATTRIBUTES=service.version=1.0.0,deployment.environment=lab
|
||||
volumes:
|
||||
- ./app:/app/app
|
||||
read_only: true
|
||||
tmpfs:
|
||||
- /tmp:size=100M
|
||||
depends_on:
|
||||
postgres:
|
||||
condition: service_healthy
|
||||
rabbitmq:
|
||||
condition: service_healthy
|
||||
s3-init:
|
||||
condition: service_completed_successfully
|
||||
otel-collector:
|
||||
condition: service_started
|
||||
deploy:
|
||||
resources:
|
||||
limits: {cpus: '2.0', memory: 768M}
|
||||
restart: unless-stopped
|
||||
|
||||
nginx:
|
||||
image: nginx:1.25-alpine
|
||||
ports:
|
||||
- "8080:8080"
|
||||
volumes:
|
||||
- ./nginx.conf:/etc/nginx/conf.d/default.conf:ro
|
||||
depends_on:
|
||||
api:
|
||||
condition: service_healthy
|
||||
restart: unless-stopped
|
||||
|
||||
volumes:
|
||||
postgres_data:
|
||||
redis_data:
|
||||
s3data:
|
||||
mqdata:
|
||||
prometheus_data:
|
||||
loki_data:
|
||||
tempo_data:
|
||||
grafana_data:
|
||||
Reference in New Issue
Block a user