x-defaults: &defaults
  restart: unless-stopped
  logging:
    driver: json-file
    options:
      max-size: 10m
      max-file: '3'

services:
  collection-agent:
    <<: *defaults
    image: ${GLOBAL_REGISTRY:-}otel/opentelemetry-collector-contrib:${OTEL_COLLECTOR_VERSION:-0.153.0}
    user: '0:0'
    network_mode: host
    environment:
      - OTEL_RESOURCE_ATTRIBUTES=deployment.environment=${DEPLOY_ENV:-production}
      - OTEL_EXPORTER_ENDPOINT=${OTEL_EXPORTER_ENDPOINT:-http://localhost:4318}
    volumes:
      - ./config.yaml:/etc/otelcol-contrib/config.yaml:ro
      - /:/hostfs:ro
      - /var/run/docker.sock:/var/run/docker.sock:ro
    deploy:
      resources:
        limits:
          cpus: ${OTEL_COLLECTOR_CPU_LIMIT:-1.0}
          memory: ${OTEL_COLLECTOR_MEMORY_LIMIT:-2G}
        reservations:
          cpus: ${OTEL_COLLECTOR_CPU_RESERVATION:-0.1}
          memory: ${OTEL_COLLECTOR_MEMORY_RESERVATION:-512M}
    healthcheck:
      test:
        - CMD
        - wget
        - --no-verbose
        - --tries=1
        - --spider
        - 'http://localhost:13133/'
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 30s
