## Monitoring stack — Loki + Grafana
## Usage: docker compose -f docker-compose.yml -f docker-compose.monitoring.yml up -d
##
## Grafana: http://localhost:3003 (admin/admin on first login)
## Loki: http://localhost:3100 (internal, used by Grafana)
##
## The app sends logs to Loki via HTTP at http://loki:3100/loki/api/v1/push

services:
  loki:
    image: grafana/loki:3.4.2
    ports:
      - "127.0.0.1:3101:3100"
    command: -config.file=/etc/loki/loki-config.yaml
    volumes:
      - loki-data:/loki
      - ./monitoring/loki-config.yaml:/etc/loki/loki-config.yaml:ro
    restart: unless-stopped
    container_name: pedscribe-loki
    healthcheck:
      test: ["CMD-SHELL", "wget --spider -q http://localhost:3100/ready"]
      interval: 30s
      timeout: 5s
      retries: 3

  grafana:
    image: grafana/grafana:11.6.0
    ports:
      - "127.0.0.1:3003:3000"
    environment:
      - GF_SECURITY_ADMIN_PASSWORD=pedscribe
      - GF_USERS_ALLOW_SIGN_UP=false
      - GF_AUTH_ANONYMOUS_ENABLED=false
    volumes:
      - grafana-data:/var/lib/grafana
      - ./monitoring/grafana-datasource.yaml:/etc/grafana/provisioning/datasources/loki.yaml:ro
      - ./monitoring/grafana-dashboards.yaml:/etc/grafana/provisioning/dashboards/dashboards.yaml:ro
      - ./monitoring/dashboards:/var/lib/grafana/dashboards:ro
    depends_on:
      loki:
        condition: service_healthy
    restart: unless-stopped
    container_name: pedscribe-grafana

  # Override the main app to add Loki env
  pediatric-scribe:
    environment:
      - LOKI_URL=http://loki:3100

volumes:
  loki-data:
  grafana-data:
