# Grafana Datasources Provisioning
# Auto-configures Prometheus and Loki connections

apiVersion: 1

datasources:
  # Prometheus - Metrics
  - name: Prometheus
    uid: prometheus
    type: prometheus
    access: proxy
    url: http://prometheus:9090
    isDefault: true
    editable: false
    jsonData:
      timeInterval: "15s"
      httpMethod: POST

  # Loki - Logs
  - name: Loki
    uid: loki
    type: loki
    access: proxy
    url: http://loki:3100
    editable: false
    jsonData:
      maxLines: 1000
      derivedFields:
        # Link correlation_id to traces
        - name: correlation_id
          matcherRegex: '"correlation_id":"([^"]+)"'
          url: '/explore?orgId=1&left=["now-1h","now","Loki",{"expr":"{correlation_id=\"$${__value.raw}\"}"}]'
          datasourceUid: loki
          urlDisplayLabel: "View correlated logs"

  # Alertmanager
  - name: Alertmanager
    uid: alertmanager
    type: alertmanager
    access: proxy
    url: http://alertmanager:9093
    editable: false
    jsonData:
      implementation: prometheus
