services:
  # OpenTelemetry Collector — receives OTLP/HTTP push from voyage hooks/scripts/otel-export.mjs
  # and forwards metrics to Prometheus via prometheus exporter (scrape endpoint :8889)
  otel-collector:
    image: otel/opentelemetry-collector-contrib:0.115.0
    container_name: voyage-otel-collector
    command: ["--config=/etc/otel-collector-config.yaml"]
    volumes:
      - ./otel-collector-config.yaml:/etc/otel-collector-config.yaml:ro
    ports:
      - "4317:4317"   # OTLP/gRPC (not used by voyage, kept for parity)
      - "4318:4318"   # OTLP/HTTP — voyage sends here when VOYAGE_EXPORT_MODE=otlp
      - "8889:8889"   # Prometheus exporter scrape endpoint
    restart: unless-stopped

  # Node Exporter with textfile collector — scrapes voyage.prom files written by voyage hooks
  # when VOYAGE_EXPORT_MODE=textfile. Volume-mount: ./voyage-textfile/ matches voyage default.
  node-exporter:
    image: prom/node-exporter:v1.10.2
    container_name: voyage-node-exporter
    command:
      - "--path.rootfs=/host"
      - "--collector.textfile.directory=/var/lib/node_exporter/textfile"
      - "--no-collector.arp"
      - "--no-collector.bcache"
    volumes:
      - ./voyage-textfile:/var/lib/node_exporter/textfile:ro
      - /:/host:ro,rslave
    ports:
      - "9100:9100"
    restart: unless-stopped

  # Prometheus — scrapes both node-exporter (textfile) and otel-collector (OTLP-derived)
  prometheus:
    image: prom/prometheus:v3.0.1
    container_name: voyage-prometheus
    command:
      - "--config.file=/etc/prometheus/prometheus.yml"
      - "--storage.tsdb.path=/prometheus"
      - "--storage.tsdb.retention.time=14d"
    volumes:
      - ./prometheus.yml:/etc/prometheus/prometheus.yml:ro
      - prometheus-data:/prometheus
    ports:
      - "9090:9090"
    depends_on:
      - node-exporter
      - otel-collector
    restart: unless-stopped

  # Grafana — preconfigured Prometheus datasource for voyage dashboards
  grafana:
    image: grafana/grafana:11.4.0
    container_name: voyage-grafana
    environment:
      - GF_SECURITY_ADMIN_USER=admin
      - GF_SECURITY_ADMIN_PASSWORD=admin
      - GF_AUTH_ANONYMOUS_ENABLED=true
      - GF_AUTH_ANONYMOUS_ORG_ROLE=Viewer
    volumes:
      - ./grafana-datasource.yml:/etc/grafana/provisioning/datasources/voyage.yml:ro
      - grafana-data:/var/lib/grafana
    ports:
      - "3000:3000"
    depends_on:
      - prometheus
    restart: unless-stopped

volumes:
  prometheus-data:
  grafana-data:
