fluent / fluent-operator

Operate Fluent Bit and Fluentd in the Kubernetes way - Previously known as FluentBit Operator

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Make namespaced rewrite_tag rule key configurable

alternaivan opened this issue · comments

Is your feature request related to a problem? Yes, read below.

Hi everyone,

Using the namespaced CRs to deploy specific FluentBit configuration deploys the dynamic Filter similar to below.

[Filter]
    Name    rewrite_tag
    Match    kube.*
    Rule    $kubernetes['namespace_name'] ^(test)$ 5236c06addf811b0eaf2fabbd31c89f2.$TAG false

This doesn't work in case you have syslog configured as an output, and need to list the nested objects. Check out this issue for more information.

Looking at the code, we found the below line to be hard-coded.

buf.WriteString(fmt.Sprintf("    Rule    $kubernetes['namespace_name'] ^(%s)$ %x.$TAG false\n", cfg.Namespace, md5.Sum([]byte(cfg.Namespace))))

Source

This setting causes the rewrite_tag filter not to work properly.

Describe the solution you'd like

Some possible solution would be somewhat similar to the one used in this PR.

For example:

apiVersion: fluentbit.fluent.io/v1alpha2
kind: FluentBitConfig
metadata:
  name: fluent-bit-config
  labels:
    app.kubernetes.io/name: fluent-bit
spec:
  filterSelector:
    matchLabels:
      fluentbit.fluent.io/enabled: "true"
  outputSelector:
    matchLabels:
      fluentbit.fluent.io/enabled: "true"
  parserSelector:
    matchLabels:
      fluentbit.fluent.io/enabled: "true"
  service:
    emitterRuleKey: "kubernetes_namespace_name"

Would generate to the below filter.

[Filter]
    Name    rewrite_tag
    Match    kube.*
    Rule    $kubernetes_namespace_name ^(test)$ 5236c06addf811b0eaf2fabbd31c89f2.$TAG false
    Emitter_Name    test

Additional context

Some useful links:

Thanks,
Marjan