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
template:
# Name from extracted data to parse. If key in extract data doesn't exist, an
# entry for it will be created.
source: <string>
# Go template string to use. In additional to normal template
# functions, ToLower, ToUpper, Replace, Trim, TrimLeft, TrimRight,
# TrimPrefix, TrimSuffix, and TrimSpace are available as functions.
template: <string>
Examples
- template:
source: new_key
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!
.
- template:
source: app
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
.
- template:
source: app
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
.
- template:
source: app
template: '{{ Replace .Value "loki" "blokey" 1 }}'
The template here uses Go’s string.Replace
function. 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
.