server:
  http_listen_port: 9080
  grpc_listen_port: 0

positions:
  filename: /tmp/positions.yaml

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

scrape_configs:
  # Scrape Docker container logs
  - job_name: docker
    docker_sd_configs:
      - host: unix:///var/run/docker.sock
        refresh_interval: 5s
        filters:
          - name: network
            values: ["goodgo-net"]
    relabel_configs:
      # Use container name as label
      - source_labels: ['__meta_docker_container_name']
        regex: '/(.*)'
        target_label: 'container'
      # Add service label from container name (strip goodgo- prefix)
      - source_labels: ['__meta_docker_container_name']
        regex: '/goodgo-(.*)'
        target_label: 'service'
      # Add compose service label
      - source_labels: ['__meta_docker_container_label_com_docker_compose_service']
        target_label: 'compose_service'
    pipeline_stages:
      # Try to parse JSON logs (Pino structured output)
      - json:
          expressions:
            level: level
            msg: msg
            context: context
            method: method
            url: url
            statusCode: statusCode
            duration: duration
            correlationId: correlationId
            component: component
            timestamp: time
      # Map Pino numeric levels to labels
      - template:
          source: level
          template: '{{ if eq .Value "10" }}trace{{ else if eq .Value "20" }}debug{{ else if eq .Value "30" }}info{{ else if eq .Value "40" }}warn{{ else if eq .Value "50" }}error{{ else if eq .Value "60" }}fatal{{ else }}{{ .Value }}{{ end }}'
      - labels:
          level:
          context:
          component:
      # Add structured metadata
      - structured_metadata:
          method:
          url:
          statusCode:
          correlationId:
      # Timestamp from Pino output
      - timestamp:
          source: timestamp
          format: RFC3339Nano
          fallback_formats:
            - '2006-01-02T15:04:05.999Z07:00'
          action_on_failure: fudge
