apiVersion: v1
kind: ConfigMap
metadata:
  name: loki-alloy
  namespace: loki
  labels:
    helm.sh/chart: alloy-1.5.2
    app.kubernetes.io/name: alloy
    app.kubernetes.io/instance: loki
    app.kubernetes.io/version: "v1.12.2"
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/part-of: alloy
    app.kubernetes.io/component: config
data:
  config.alloy: |-
    logging {
      level = "debug"
      format = "logfmt"
    }
    discovery.kubernetes "pods" {
      role = "pod"
    }
    discovery.relabel "pods" {
      targets = discovery.kubernetes.pods.targets

      rule {
        source_labels = ["__meta_kubernetes_namespace"]
        target_label = "namespace"
        action = "replace"
      }
      rule {
        source_labels = ["__meta_kubernetes_pod_label_app_kubernetes_io_name"]
        target_label = "app"
        action = "replace"
      }
      rule {
        source_labels = ["__meta_kubernetes_pod_container_name"]
        target_label = "container"
        action = "replace"
      }
      rule {
        source_labels = ["__meta_kubernetes_pod_name"]
        target_label = "pod"
        action = "replace"
      }
    }
    loki.source.kubernetes "pods" {
      targets    = discovery.relabel.pods.output
      forward_to = [loki.process.process.receiver]
    }
    loki.process "process" {
      forward_to = [loki.write.loki.receiver]

      stage.drop {
        older_than          = "1h"
        drop_counter_reason = "too old"
      }
      stage.match {
        selector = "{instance=~\".*\"}"
        stage.json {
          expressions = {
            level = "\"level\"",
          }
        }
        stage.labels {
          values = {
            level = "level",
          }
        }
      }
      stage.label_drop {
        values = [ "service_name" ]
      }
    }
    loki.write "loki" {
      endpoint {
        url = "http://loki-gateway.loki.svc.cluster.local:80/loki/api/v1/push"
      }
    }
