I try to filter logs using the Alloy and the stage.match
using regex.
The log is JSON containing the status field with possible values corresponding to HTTP response codes (200, 302, 400, 502, …).
My configuration
loki.source.file "logs_gitlab_01" {
targets = [
{"__path__" = "/var/log/gitlab/gitlab-rails/production_json.log"},
]
forward_to = [loki.process.logs_gitlab_01.receiver]
}
loki.process "logs_gitlab_01" {
stage.json {
expressions = {
extracted_status = "status",
}
}
stage.labels {
values = {
"status" = "extracted_status",
}
}
stage.match {
selector = "{ `extracted_status=~"2.."`}"
stage.labels {
values = {
"level" = "info",
}
}
}
forward_to = [loki.process.logs_gitlab_00.receiver]
}
I’ve tried escaping the regex in many way and I receive errors - under reloading configuration -
Failed to build component: building component: invalid stage config invalid selector syntax for match stage: parse error at line 1, col 1: syntax error: unexpected IDENTIFIER, expecting {
The current state of the line with regex is not the only one which I tried.
Yes, I read
- Alloy - Loki - how to create a new label based on the regex content from another field in the JSON log line - #3 by dfrazao
- How to escape special characters with Loki's LogQL | Grafana Labs
and many more.
Maybe a solution is obvious but I don’t see it. Thank you in advance for any help.