Hi team, i have a little problem with merge templating my loki.process block
So.. For first time i grab more logs from my test k8s and i need to parse some words
loki.source.kubernetes "pods" {
targets = discovery.relabel.pod_logs.output
forward_to = [loki.process.cleanless.receiver]
}
loki.process "cleanless" {
forward_to = [loki.process.process_error.receiver]
stage.drop {
older_than = "1h"
drop_counter_reason = "too old"
}
stage.label_drop {
values = [ "job", "service_name", "pod_label_pod_template_generation", "pod_label_controller_revision_hash" ]
}
}
So then i checked for words like “FAILED/failed/FATAL/fatal” and mark them as “level=error” (for Grafana view)
And after i need to find words like “[INFO]/[DEBUG]” and mark them as “level=info”
Template for strings, marks as level=info:
[INFO] 10.10.15.123:32885 - 6242 "AAAA IN test.vz.ru. udp 47 false 1232" NOERROR qr,aa,rd,ra 124 0.000039094s
Template for strings, marks as level=error:
failed to create fsnotify watcher: too many open files
E0317 12:54:57.171829 1 cacher.go:470] cacher (vcdmachines.infrastructure.cluster.x-k8s.io): unexpected ListAndWatch error: failed to list infrastructure.cluster.x-k8s.io/v1alpha4, Kind=VCDMachine: conversion webhook for infrastructure.cluster.x-k8s.io/v1beta2, Kind=VCDMachine failed: Post "https://capvcd-webhook-service.capvcd-system.svc:443/convert?timeout=30s": service "capvcd-webhook-service" not found; reinitializing...
I’m trying to write something like
loki.process "process_error" {
forward_to = [loki.process.process_info.receiver]
stage.regex {
expression = ".*\\s+(?P<msglevel>failed|fatal).*"
}
stage.labels {
values = {
msglevel = "",
}
}
stage.match {
selector = "{msglevel=~\"(failed|fatal)\"}"
stage.static_labels {
values = {
level = "error",
levelcatch = "true",
}
}
}
}
But it’s not work. I’m checked this on regex101, and it seems like everything should work - but not. Maybe problem with brackets, maybe with \\s+
, idk
But if i use regex with .* on start/end and use a word that i need, all lines start catching
And if i listing all words in stage.match with query like selector = "{msglevel=\"fatal\"}"
, this stage is work. The regular expression does not work for me =(
I use simple design like
loki.process "process_error" {
forward_to = [loki.process.process_info.receiver]
stage.regex {
expression = ".*(?P<msglevel>failed|fatal).*"
}
stage.labels {
values = {
msglevel = "",
}
}
stage.match {
selector = "{msglevel=\"failed\"}"
stage.static_labels {
values = {
level = "error",
levelcatch = "true",
}
}
}
stage.match {
selector = "{msglevel=\"fatal\"}"
stage.static_labels {
values = {
level = "error",
levelcatch = "true",
}
}
}
}
but it’s not comfortable. Can anyone help me with explain and help configure this regex please ?