Loki stage.template functions are not available
fhqwhgadss opened this issue · 4 comments
fhqwhgadss commented
I find myself unable to use the custom functions in Loki stage.template
blocks added through logs.pod_logs.extraStageBlocks
.
Here is my values.yaml
with one of the example usages of stage.template
from the docs:
cluster:
name: "k8s-monitor"
platform: ""
externalServices:
loki:
host: "http://loki-loki-distributed-gateway"
protocol: "loki"
queryEndpoint: /loki/api/v1/query
writeEndpoint: /loki/api/v1/push
authMode: none
logs:
enabled: true
pod_logs:
enabled: true
extraStageBlocks: |
stage.template {
source = "app"
template = "{{ ToLower .Value }}_some_suffix"
}
metrics:
enabled: false
configValidator:
enabled: true
test:
enabled: true
prometheus-operator-crds:
enabled: false
When deploying, the config validator fails with the following output:
Error: UPGRADE FAILED: template: k8s-monitoring/templates/hooks/validate-configuration.yaml:123:8:
executing "k8s-monitoring/templates/hooks/validate-configuration.yaml" at <include "alloyConfig" .>:
error calling include: template: k8s-monitoring/templates/_configs.tpl:92:8: executing "alloyConfig" at <include "alloy.config.logs.pod_logs_processor" .>:
error calling include: template: k8s-monitoring/templates/alloy_config/_pod_logs_processor.alloy.txt:53:3:
executing "alloy.config.logs.pod_logs_processor" at <tpl .Values.logs.pod_logs.extraStageBlocks $>:
error calling tpl: error during tpl function execution for "stage.template {\n source = \"app\"\n template = \"{{ ToLower .Value }}_some_suffix\"\n}\n":
parse error at (k8s-monitoring/templates/hooks/validate-configuration.yaml:3): function "ToLower" not defined
petewall commented
The issue is that the extraStageBlocks are first evaluated by Helm, which things you're adding a Helm template directive.
It's ugly, but try this:
logs:
enabled: true
pod_logs:
enabled: true
extraStageBlocks: |
stage.template {
source = "app"
template = "{{ "{{" }} ToLower .Value }}_some_suffix"
}
petewall commented
Or, put the whole think inside a Helm template string:
The issue is that the extraStageBlocks are first evaluated by Helm, which things you're adding a Helm template directive.
It's ugly, but try this:
logs:
enabled: true
pod_logs:
enabled: true
extraStageBlocks: |
stage.template {
source = "app"
template = {{ "{{ ToLower .Value }}_some_suffix" | quote }}
}
fhqwhgadss commented
Or, put the whole think inside a Helm template string:
The issue is that the extraStageBlocks are first evaluated by Helm, which things you're adding a Helm template directive. It's ugly, but try this: logs: enabled: true pod_logs: enabled: true extraStageBlocks: | stage.template { source = "app" template = {{ "{{ ToLower .Value }}_some_suffix" | quote }} }
That does the trick, thank you!
petewall commented
Glad it's working!