fluent-operator icon indicating copy to clipboard operation
fluent-operator copied to clipboard

Make namespaced rewrite_tag rule key configurable

Open alternaivan opened this issue 1 year ago • 0 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:

  • https://docs.fluentbit.io/manual/pipeline/filters/rewrite-tag#key
  • https://github.com/fluent/fluent-operator/pull/1085
  • https://github.com/fluent/fluent-bit/issues/5467
  • https://github.com/fluent/fluent-operator/blob/release-2.7/controllers/fluentbitconfig_controller.go#L312

Thanks, Marjan

alternaivan avatar Mar 20 '24 14:03 alternaivan