Search code examples
fluentd

fluentd - When a specific value can be used as a key but not recoded


In the example below, i can use $ ["kubernetes"]["aaa"]["bbb"] as the key value,

but It cannot be used as a tag value. $ {recode ["kubernetes"]["aaa"]["bbb"]} also doesn't work.

How can I use it as a tag ??

Why is it so different?

  <match **>
    @type rewrite_tag_filter
    <rule>
      key $["kubernetes"]["aaa"]["bbb"]
      pattern ".*"
      tag ${recode["kubernetes"]["aaa"]["bbb"]}
    </rule>
   </match>

Solution

  • If you put your regex pattern within grouping brackets () then entire matching text can be used the first group result.

    Example -
    Expression - (.*)
    Matching Text - Some Text
    Group 1 - Some Text

    So using above, below will be your updated fluentd conf.

    <match **>
     @type rewrite_tag_filter
     <rule>
      key $["kubernetes"]["aaa"]["bbb"]
      pattern "(.*)"
      tag $1
     </rule>
    </match>