Skip to content

Commit 7c0b8f0

Browse files
authored
Add the ability to specify processing stages per loki destination (#1186)
Provide an integration test that shows how to use them Signed-off-by: Pete Wall <[email protected]>
1 parent 6bd1f7d commit 7c0b8f0

File tree

14 files changed

+3951
-1
lines changed

14 files changed

+3951
-1
lines changed

charts/k8s-monitoring/destinations/loki-values.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ extraLabels: {}
4343
# @section -- General
4444
extraLabelsFrom: {}
4545

46+
# -- Stage blocks to be evaluated before delivering to the Loki destination. See
47+
# ([docs](https://grafana.com/docs/alloy/latest/reference/components/loki/loki.process/#blocks)) for more information.
48+
# @section -- General
49+
logProcessingStages: ""
50+
4651
auth:
4752
# -- The type of authentication to do.
4853
# Options are "none" (default), "basic", "bearerToken", "oauth2".

charts/k8s-monitoring/docs/destinations/loki.md

+1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ This defines the options for defining a destination for logs that use the Loki p
5757
| extraHeadersFrom | object | `{}` | Extra headers to be set when sending data through a dynamic reference. All values are treated as raw strings and not quoted. |
5858
| extraLabels | object | `{}` | Custom labels to be added to all logs and events. All values are treated as strings and automatically quoted. |
5959
| extraLabelsFrom | object | `{}` | Custom labels to be added to all logs and events through a dynamic reference. All values are treated as raw strings and not quoted. |
60+
| logProcessingStages | string | `""` | Stage blocks to be evaluated before delivering to the Loki destination. See ([docs](https://grafana.com/docs/alloy/latest/reference/components/loki/loki.process/#blocks)) for more information. |
6061
| name | string | `""` | The name for this Loki destination. |
6162
| proxyURL | string | `""` | The Proxy URL for the Loki destination. |
6263
| tenantId | string | `""` | The tenant ID for the Loki destination. |

charts/k8s-monitoring/schema-mods/definitions/loki-destination.schema.json

+3
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@
9898
"extraLabelsFrom": {
9999
"type": "object"
100100
},
101+
"logProcessingStages": {
102+
"type": "string"
103+
},
101104
"name": {
102105
"type": "string"
103106
},

charts/k8s-monitoring/templates/destinations/_destination_loki.tpl

+14-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,15 @@
22
{{- $defaultValues := "destinations/loki-values.yaml" | .Files.Get | fromYaml }}
33
{{- with merge .destination $defaultValues }}
44
otelcol.exporter.loki {{ include "helper.alloy_name" .name | quote }} {
5+
forward_to = [{{ include "destinations.loki.alloy.loki.logs.target" . }}]
6+
}
7+
{{- if .logProcessingStages }}
8+
9+
loki.process {{ include "helper.alloy_name" .name | quote }} {
10+
{{ .logProcessingStages | indent 2 }}
511
forward_to = [loki.write.{{ include "helper.alloy_name" .name }}.receiver]
612
}
13+
{{- end }}
714

815
loki.write {{ include "helper.alloy_name" .name | quote }} {
916
endpoint {
@@ -122,7 +129,13 @@ loki.write {{ include "helper.alloy_name" .name | quote }} {
122129
- tls.key
123130
{{- end -}}
124131

125-
{{- define "destinations.loki.alloy.loki.logs.target" }}loki.write.{{ include "helper.alloy_name" .name }}.receiver{{ end -}}
132+
{{- define "destinations.loki.alloy.loki.logs.target" }}
133+
{{- if .logProcessingStages -}}
134+
loki.process.{{ include "helper.alloy_name" .name }}.receiver
135+
{{- else -}}
136+
loki.write.{{ include "helper.alloy_name" .name }}.receiver
137+
{{- end -}}
138+
{{- end -}}
126139
{{- define "destinations.loki.alloy.otlp.logs.target" }}otelcol.exporter.loki.{{ include "helper.alloy_name" .name }}.input{{ end -}}
127140

128141
{{- define "destinations.loki.supports_metrics" }}false{{ end -}}

0 commit comments

Comments
 (0)