template stage

The template stage is a transform stage that lets use manipulate the values inthe extracted map using Go’s templatesyntax.

The template stage is primarily useful for manipulating data from other stagesbefore setting them as labels, such as to replace spaces with underscores orconverting an uppercase string into a lowercase one.

The template stage can also create new keys in the extracted map.

Schema

  1. template:
  2. # Name from extracted data to parse. If key in extract data doesn't exist, an
  3. # entry for it will be created.
  4. source: <string>
  5. # Go template string to use. In additional to normal template
  6. # functions, ToLower, ToUpper, Replace, Trim, TrimLeft, TrimRight,
  7. # TrimPrefix, TrimSuffix, and TrimSpace are available as functions.
  8. template: <string>

Examples

  1. - template:
  2. source: new_key
  3. template: 'hello world!'

Assuming no data has been added to the extracted map yet, this stage will firstadd new_key with a blank value into the extracted map. Then its value will beset to hello world!.

  1. - template:
  2. source: app
  3. template: '{{ .Value }}_some_suffix'

This pipeline takes the value of the app key in the existing extracted map andappends _some_suffix to its value. For example, if the extracted map had akey of app and a value of loki, this stage would modify the value fromloki to loki_some_suffix.

  1. - template:
  2. source: app
  3. template: '{{ ToLower .Value }}'

This pipeline takes the current value of app from the extracted map andconverts its value to be all lowercase. For example, if the extracted mapcontained app with a value of LOKI, this pipeline would change its value toloki.

  1. - template:
  2. source: app
  3. template: '{{ Replace .Value "loki" "blokey" 1 }}'

The template here uses Go’s string.Replacefunction. When the template executes,the entire contents of the app key from the extracted map will have at most1 instance of loki changed to blokey.