# Agent OS Observability Stack
# 
# Full production-ready observability with:
# - Prometheus (metrics collection)
# - Grafana (dashboards)
# - Jaeger (distributed tracing)
# - AlertManager (alerting)
#
# Usage:
#   cd packages/observability
#   docker-compose up -d
#   
#   Open: http://localhost:3000 (Grafana, admin/admin)
#   Open: http://localhost:16686 (Jaeger)
#   Open: http://localhost:9090 (Prometheus)

version: '3.8'

services:
  # ===========================================================================
  # Prometheus - Metrics Collection
  # ===========================================================================
  prometheus:
    image: prom/prometheus:v2.48.0
    container_name: agent-os-prometheus
    restart: unless-stopped
    ports:
      - "9090:9090"
    volumes:
      - ./prometheus/prometheus.yml:/etc/prometheus/prometheus.yml:ro
      - ./alerts:/etc/prometheus/rules:ro
      - prometheus_data:/prometheus
    command:
      - '--config.file=/etc/prometheus/prometheus.yml'
      - '--storage.tsdb.path=/prometheus'
      - '--storage.tsdb.retention.time=30d'
      - '--web.enable-lifecycle'
      - '--web.enable-admin-api'
    networks:
      - agent-os-network

  # ===========================================================================
  # Grafana - Visualization
  # ===========================================================================
  grafana:
    image: grafana/grafana:10.2.0
    container_name: agent-os-grafana
    restart: unless-stopped
    ports:
      - "3000:3000"
    environment:
      - GF_SECURITY_ADMIN_USER=admin
      - GF_SECURITY_ADMIN_PASSWORD=admin
      - GF_USERS_ALLOW_SIGN_UP=false
      - GF_INSTALL_PLUGINS=grafana-piechart-panel
    volumes:
      - ./grafana/provisioning:/etc/grafana/provisioning:ro
      - ./grafana/dashboards:/var/lib/grafana/dashboards:ro
      - grafana_data:/var/lib/grafana
    depends_on:
      - prometheus
    networks:
      - agent-os-network

  # ===========================================================================
  # Jaeger - Distributed Tracing
  # ===========================================================================
  jaeger:
    image: jaegertracing/all-in-one:1.52
    container_name: agent-os-jaeger
    restart: unless-stopped
    ports:
      - "16686:16686"   # UI
      - "14268:14268"   # HTTP collector
      - "6831:6831/udp" # UDP agent
      - "4317:4317"     # OTLP gRPC
      - "4318:4318"     # OTLP HTTP
    environment:
      - COLLECTOR_OTLP_ENABLED=true
    networks:
      - agent-os-network

  # ===========================================================================
  # AlertManager - Alerting
  # ===========================================================================
  alertmanager:
    image: prom/alertmanager:v0.26.0
    container_name: agent-os-alertmanager
    restart: unless-stopped
    ports:
      - "9093:9093"
    volumes:
      - ./alertmanager/alertmanager.yml:/etc/alertmanager/alertmanager.yml:ro
      - alertmanager_data:/alertmanager
    command:
      - '--config.file=/etc/alertmanager/alertmanager.yml'
      - '--storage.path=/alertmanager'
    networks:
      - agent-os-network

  # ===========================================================================
  # OTEL Collector (Optional - for complex deployments)
  # ===========================================================================
  otel-collector:
    image: otel/opentelemetry-collector-contrib:0.91.0
    container_name: agent-os-otel-collector
    restart: unless-stopped
    ports:
      - "4316:4317"     # OTLP gRPC (different port to avoid Jaeger conflict)
      - "4319:4318"     # OTLP HTTP (different port)
      - "8888:8888"     # Prometheus metrics
    volumes:
      - ./otel/otel-collector-config.yml:/etc/otelcol-contrib/config.yaml:ro
    command: ["--config=/etc/otelcol-contrib/config.yaml"]
    depends_on:
      - prometheus
      - jaeger
    networks:
      - agent-os-network

networks:
  agent-os-network:
    driver: bridge

volumes:
  prometheus_data:
  grafana_data:
  alertmanager_data:
