lab6: observability, otel, grafana, incidents and dashboard
This commit is contained in:
+234
@@ -0,0 +1,234 @@
|
||||
x-api: &api
|
||||
build: .
|
||||
image: mtusi-lab5-votchitseva-api:local
|
||||
environment: &api_env
|
||||
OTEL_SERVICE_NAME: messenger-api
|
||||
OTEL_EXPORTER_OTLP_ENDPOINT: http://otel-collector:4318
|
||||
JOB_MAX_ATTEMPTS: ${JOB_MAX_ATTEMPTS:-5}
|
||||
APP_HOST: 0.0.0.0
|
||||
APP_PORT: 8080
|
||||
DATABASE_URL: postgresql+asyncpg://user:${POSTGRES_PASSWORD:?Copy .env.example to .env}@db:5432/messenger
|
||||
CACHE_URL: redis://redis:6379/0
|
||||
SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600}
|
||||
S3_ENDPOINT: http://s3:8333
|
||||
S3_BUCKET: ${S3_BUCKET:-messenger-attachments}
|
||||
S3_ACCESS_KEY_ID: ${S3_ACCESS_KEY_ID:?Set S3_ACCESS_KEY_ID in .env}
|
||||
S3_SECRET_ACCESS_KEY: ${S3_SECRET_ACCESS_KEY:?Set S3_SECRET_ACCESS_KEY in .env}
|
||||
MAX_UPLOAD_BYTES: ${MAX_UPLOAD_BYTES:-10485760}
|
||||
MAX_IMAGE_PIXELS: ${MAX_IMAGE_PIXELS:-40000000}
|
||||
BROKER_URL: amqp://guest:guest@broker:5672/
|
||||
depends_on:
|
||||
migrate:
|
||||
condition: service_completed_successfully
|
||||
redis:
|
||||
condition: service_healthy
|
||||
s3:
|
||||
condition: service_healthy
|
||||
broker:
|
||||
condition: service_healthy
|
||||
networks: [front, data]
|
||||
cpus: 0.5
|
||||
mem_limit: 384m
|
||||
stop_grace_period: 15s
|
||||
healthcheck:
|
||||
test: ["CMD", "python", "-c", "import urllib.request; urllib.request.urlopen('http://127.0.0.1:8080/health/ready', timeout=4).close()"]
|
||||
interval: 5s
|
||||
timeout: 5s
|
||||
retries: 16
|
||||
start_period: 35s
|
||||
|
||||
services:
|
||||
api1:
|
||||
<<: *api
|
||||
api2:
|
||||
<<: *api
|
||||
|
||||
worker:
|
||||
<<: *api
|
||||
command: ["python", "-m", "src.worker"]
|
||||
environment:
|
||||
<<: *api_env
|
||||
OTEL_SERVICE_NAME: messenger-worker
|
||||
healthcheck:
|
||||
disable: true
|
||||
deploy:
|
||||
replicas: 1
|
||||
|
||||
broker:
|
||||
image: rabbitmq:3.13-alpine
|
||||
hostname: rabbitmq
|
||||
entrypoint: ["/bin/sh", "-c", "rm -f /var/lib/rabbitmq/.erlang.cookie && exec /usr/local/bin/docker-entrypoint.sh rabbitmq-server"]
|
||||
environment:
|
||||
RABBITMQ_DEFAULT_USER: guest
|
||||
RABBITMQ_DEFAULT_PASS: guest
|
||||
volumes:
|
||||
- broker_data:/var/lib/rabbitmq
|
||||
networks: [data]
|
||||
cpus: 0.5
|
||||
mem_limit: 512m
|
||||
healthcheck:
|
||||
test: ["CMD", "rabbitmq-diagnostics", "-q", "check_running"]
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 10
|
||||
start_period: 30s
|
||||
|
||||
s3_config:
|
||||
image: python:3.12.7-slim-bookworm
|
||||
command: ["python", "/bootstrap/generate-s3-config.py"]
|
||||
environment:
|
||||
S3_ROOT_USER: ${S3_ROOT_USER:?Set S3_ROOT_USER in .env}
|
||||
S3_ROOT_PASSWORD: ${S3_ROOT_PASSWORD:?Set S3_ROOT_PASSWORD in .env}
|
||||
S3_ACCESS_KEY_ID: ${S3_ACCESS_KEY_ID:?Set S3_ACCESS_KEY_ID in .env}
|
||||
S3_SECRET_ACCESS_KEY: ${S3_SECRET_ACCESS_KEY:?Set S3_SECRET_ACCESS_KEY in .env}
|
||||
S3_BUCKET: ${S3_BUCKET:-messenger-attachments}
|
||||
volumes:
|
||||
- ./infra/generate-s3-config.py:/bootstrap/generate-s3-config.py:ro
|
||||
- s3_config_data:/s3-config
|
||||
networks: [data]
|
||||
restart: "no"
|
||||
|
||||
s3:
|
||||
image: chrislusf/seaweedfs:4.35
|
||||
command: ["mini", "-dir=/data", "-s3.config=/s3-config/s3.json", "-bucket=messenger-attachments"]
|
||||
volumes:
|
||||
- s3_data:/data
|
||||
- s3_config_data:/s3-config:ro
|
||||
depends_on:
|
||||
s3_config: {condition: service_completed_successfully}
|
||||
networks: [data]
|
||||
restart: unless-stopped
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:8333/status || exit 1"]
|
||||
interval: 2s
|
||||
timeout: 3s
|
||||
retries: 15
|
||||
start_period: 10s
|
||||
|
||||
migrate:
|
||||
build: .
|
||||
image: mtusi-lab5-votchitseva-api:local
|
||||
command: ["python", "-m", "src.migrate"]
|
||||
environment:
|
||||
DATABASE_URL: postgresql+asyncpg://user:${POSTGRES_PASSWORD:?Copy .env.example to .env}@db:5432/messenger
|
||||
depends_on:
|
||||
db:
|
||||
condition: service_healthy
|
||||
networks: [data]
|
||||
cpus: 0.5
|
||||
mem_limit: 256m
|
||||
healthcheck:
|
||||
disable: true
|
||||
|
||||
lb:
|
||||
image: haproxy:3.0.5-alpine
|
||||
ports: ["127.0.0.1:8080:8080"]
|
||||
volumes:
|
||||
- ./infra/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro
|
||||
depends_on:
|
||||
api1:
|
||||
condition: service_healthy
|
||||
api2:
|
||||
condition: service_healthy
|
||||
networks: [front]
|
||||
cpus: 0.25
|
||||
mem_limit: 128m
|
||||
|
||||
db:
|
||||
image: postgres:16.4-alpine
|
||||
environment:
|
||||
POSTGRES_USER: user
|
||||
POSTGRES_DB: messenger
|
||||
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?Copy .env.example to .env}
|
||||
volumes: [pgdata:/var/lib/postgresql/data]
|
||||
networks: [data]
|
||||
cpus: 1.0
|
||||
mem_limit: 512m
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "pg_isready -U user -d messenger"]
|
||||
interval: 2s
|
||||
timeout: 2s
|
||||
retries: 15
|
||||
|
||||
redis:
|
||||
image: redis:7.4.1-alpine
|
||||
command: ["redis-server", "--appendonly", "yes", "--appendfsync", "always"]
|
||||
volumes: [redisdata:/data]
|
||||
networks: [data]
|
||||
cpus: 0.25
|
||||
mem_limit: 128m
|
||||
healthcheck:
|
||||
test: ["CMD", "redis-cli", "ping"]
|
||||
interval: 2s
|
||||
timeout: 2s
|
||||
retries: 15
|
||||
|
||||
otel-collector:
|
||||
image: otel/opentelemetry-collector-contrib:0.138.0
|
||||
command: ["--config=/etc/otelcol/config.yaml"]
|
||||
volumes:
|
||||
- ./infra/otel/collector.yaml:/etc/otelcol/config.yaml:ro
|
||||
networks: [data]
|
||||
restart: unless-stopped
|
||||
mem_limit: 192m
|
||||
|
||||
prometheus:
|
||||
image: prom/prometheus:v3.6.0
|
||||
command: ["--config.file=/etc/prometheus/prometheus.yml", "--storage.tsdb.path=/prometheus", "--storage.tsdb.retention.time=7d", "--web.enable-lifecycle"]
|
||||
volumes:
|
||||
- ./infra/otel/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml:ro
|
||||
- ./infra/otel/prometheus/alerts.yml:/etc/prometheus/alerts.yml:ro
|
||||
- prometheus_data:/prometheus
|
||||
ports: ["127.0.0.1:9090:9090"]
|
||||
networks: [data, front]
|
||||
restart: unless-stopped
|
||||
|
||||
loki:
|
||||
image: grafana/loki:3.5.5
|
||||
user: "0"
|
||||
command: ["-config.file=/etc/loki/config.yaml"]
|
||||
volumes:
|
||||
- ./infra/otel/loki/config.yaml:/etc/loki/config.yaml:ro
|
||||
- loki_data:/loki
|
||||
networks: [data]
|
||||
restart: unless-stopped
|
||||
|
||||
tempo:
|
||||
image: grafana/tempo:2.8.2
|
||||
user: "0"
|
||||
command: ["-config.file=/etc/tempo/config.yaml"]
|
||||
volumes:
|
||||
- ./infra/otel/tempo/config.yaml:/etc/tempo/config.yaml:ro
|
||||
- tempo_data:/var/tempo
|
||||
networks: [data]
|
||||
restart: unless-stopped
|
||||
|
||||
grafana:
|
||||
image: grafana/grafana:12.2.0
|
||||
environment:
|
||||
GF_SECURITY_ADMIN_USER: admin
|
||||
GF_SECURITY_ADMIN_PASSWORD: ${GRAFANA_ADMIN_PASSWORD:-lab6-local-change-me}
|
||||
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
|
||||
ports: ["127.0.0.1:3000:3000"]
|
||||
networks: [data, front]
|
||||
restart: unless-stopped
|
||||
|
||||
networks:
|
||||
front:
|
||||
data:
|
||||
internal: true
|
||||
|
||||
volumes:
|
||||
pgdata:
|
||||
redisdata:
|
||||
s3_data:
|
||||
s3_config_data:
|
||||
prometheus_data:
|
||||
loki_data:
|
||||
tempo_data:
|
||||
grafana_data:
|
||||
broker_data:
|
||||
Reference in New Issue
Block a user