# =============================================================================
# Kong Monitoring Stack - Prometheus + Grafana
# =============================================================================
# Usage:
#   docker compose -f docker-compose.yml -f docker-compose.monitoring.yml up -d
# =============================================================================

services:
  # ===========================================================================
  # Prometheus - 指标收集
  # ===========================================================================
  prometheus:
    image: prom/prometheus:latest
    container_name: rwa-prometheus
    command:
      - '--config.file=/etc/prometheus/prometheus.yml'
      - '--storage.tsdb.path=/prometheus'
      - '--web.console.libraries=/usr/share/prometheus/console_libraries'
      - '--web.console.templates=/usr/share/prometheus/consoles'
    volumes:
      - ./prometheus.yml:/etc/prometheus/prometheus.yml:ro
      - prometheus_data:/prometheus
    ports:
      - "9099:9090"  # 使用 9099 避免与已有服务冲突
    restart: unless-stopped
    networks:
      - rwa-network

  # ===========================================================================
  # Grafana - 可视化仪表盘
  # ===========================================================================
  grafana:
    image: grafana/grafana:latest
    container_name: rwa-grafana
    environment:
      - GF_SECURITY_ADMIN_USER=admin
      - GF_SECURITY_ADMIN_PASSWORD=${GRAFANA_ADMIN_PASSWORD:-admin123}
      - GF_USERS_ALLOW_SIGN_UP=false
      # 反向代理支持
      - GF_SERVER_ROOT_URL=${GRAFANA_ROOT_URL:-http://localhost:3030}
      - GF_SERVER_SERVE_FROM_SUB_PATH=false
      # Grafana 10+ CORS/跨域配置 - 允许通过反向代理访问
      - GF_SECURITY_ALLOW_EMBEDDING=true
      - GF_SECURITY_COOKIE_SAMESITE=none
      - GF_SECURITY_COOKIE_SECURE=true
      - GF_AUTH_ANONYMOUS_ENABLED=false
    volumes:
      - grafana_data:/var/lib/grafana
      - ./grafana/provisioning:/etc/grafana/provisioning:ro
    ports:
      - "3030:3000"
    depends_on:
      - prometheus
    restart: unless-stopped
    networks:
      - rwa-network

volumes:
  prometheus_data:
    driver: local
  grafana_data:
    driver: local

networks:
  rwa-network:
    external: true
    name: ${NETWORK_NAME:-api-gateway_rwa-network}
