server:
  http_listen_port: 9080
  grpc_listen_port: 0

positions:
  filename: /positions/positions.yaml

clients:
  - url: http://loki:3100/loki/api/v1/push

scrape_configs:
  - job_name: docker
    docker_sd_configs:
      - host: unix:///var/run/docker.sock
        refresh_interval: 5s
        filters:
          - name: label
            values: ["com.docker.compose.project=quiz"]
    relabel_configs:
      # Keep only this compose project; the Docker API filter above prevents
      # Promtail from opening non-readable log streams from other stacks.
      - source_labels: ['__meta_docker_container_label_com_docker_compose_project']
        regex: 'quiz'
        action: keep
      # Extract container name as label
      - source_labels: ['__meta_docker_container_name']
        regex: '/?(.*)'
        target_label: container
      # Extract compose service name
      - source_labels: ['__meta_docker_container_label_com_docker_compose_service']
        target_label: service
    pipeline_stages:
      # Docker JSON log wrapper
      - docker: {}
      # Try to parse structured JSON logs from backend/celery
      - match:
          selector: '{service=~"backend|celery"}'
          stages:
            - json:
                expressions:
                  level: levelname
                  logger: name
                  msg: message
                  request_id: request_id
                  method: method
                  path: path
                  status: status
                  duration_ms: duration_ms
                  user: user
            - labels:
                level:
                logger:
