resmoio / kubernetes-event-exporter

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

Supporting Kubernetes event properties in OpenSearch index format #155

Open jarnfast opened 7 months ago

jarnfast commented 7 months ago

Hi,

in multi-tenant clusters it is possible to configure the kubernetes-event-exporter with multiple rules and receiver so that events for the tenant namespaces end up in dedicated indices in OpenSearch.

The problem is that whenever a tenant is onboarded the kubernetes-event-exporter's configuration needs to be extended with an additional rule and receiver.

If the indexFormat allowed for expansion of event properties this could be achieved with a single rule and receiver. E.g.

receivers:
  - name: "by-namespace"
    opensearch:
      hosts:
        - http://localhost:9200
      indexFormat: "kube-events-{{ .Namespace }}-{2006-01-02}"

This could implemented by passing the *kube.EnhancedEvent to osFormatIndexName method and letting it expand any event properties denoted with {{ .. }} using GetString(event *kube.EnhancedEvent, text string) from tmpl.go before doing the Go time formatting directives - this way it'll be backwards compatible.

This would be similar to the channel behavior in the slack receiver and the layout templates.

If this sounds agreeable I'll gladly attempt to implement this functionality.