resmoio / kubernetes-event-exporter

Export Kubernetes events to multiple destinations with routing and filtering
Apache License 2.0
789 stars 158 forks source link

'{{ .field }}' syntax does not seem to work with Loki synk #134

Closed yogeek closed 1 year ago

yogeek commented 1 year ago

In Loki receiver configuration, it does not seem possible to use templated values for stream labels like in other sinks.

For example, in Slack sink we can use the templated fields {{ .xxx }}:

receivers:
  - name: "slack"
    slack:
      channel: "@{{ .InvolvedObject.Labels.owner }}"
      message: "{{ .Message }}"
      fields:
        namespace: "{{ .Namespace }}"
        reason: "{{ .Reason }}"
        object: "{{ .Namespace }}"

I tested this config with Loki sink but the {{ .xxx}} part is not rendered before sending to loki :

receivers:
  - name: "loki"
    loki:
      streamLabels:
         source: event-exporter
         container: event-exporter
         namespace: "{{ .InvolvedObject.Namespace }}" # <<<< this does not work

Is it possible to add some of the event fields like the namespace as loki labels please ?

yogeek commented 1 year ago

UPDATE : in fact, after some tests, I discovered that the minimal configuration above works well for the corresponding dashboard

receivers:
      - name: "loki"
        loki:
          url: http://loki-gateway.loki.svc.cluster.local/loki/api/v1/push
          streamLabels:
            source: event-exporter
            container: event-exporter