# ============================================================
# Promtail - Log-Collector Konfiguration
# ============================================================
# Sammelt Docker Container Logs und sendet sie an Loki.
# ============================================================

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:
  # Docker Container Logs
  - job_name: docker
    docker_sd_configs:
      - host: unix:///var/run/docker.sock
        refresh_interval: 5s
        filters:
          - name: label
            values: ["com.docker.compose.project=insight"]
    relabel_configs:
      # Container-Name als Label
      - source_labels: ['__meta_docker_container_name']
        regex: '/(.*)'
        target_label: container
      # Compose-Service-Name als Label
      - source_labels: ['__meta_docker_container_label_com_docker_compose_service']
        target_label: service
      # Log-Stream (stdout/stderr)
      - source_labels: ['__meta_docker_container_log_stream']
        target_label: stream

    pipeline_stages:
      # JSON-Logs parsen (NestJS)
      - json:
          expressions:
            level: level
            message: message
            timestamp: timestamp
            context: context
      - labels:
          level:
          context:
      - timestamp:
          source: timestamp
          format: RFC3339
