Hi.
I have a log file with a custom format. The timestamps, per line, in the log file contain just time and no date info. My plan was to use a regex to extract the date information from the filename label, then reformat the timestamp entry. However I can not figure out how access the filename value in the loki.process block.
Here’s the current loki.process block from the config.alloy:
loki.process "timestamp_alignment" {
forward_to = [loki.write.grafana_loki.receiver]
stage.regex {
source = "filename"
expression = `log_(?P<file_year>\d{4})(?P<file_month>\d{2})(?P<file_day>\d{2})`
}
stage.regex {
source = ""
expression = `\[(?P<line_timestamp>\d{2}:\d{2}:\d{2}\.\d{3})`
}
stage.replace {
expression = `\[(?P<line_timestamp>\d{2}:\d{2}:\d{2}\.\d{3})\]`
replace = "file_year" + "-" + "file_month" + "-" + "file_day" + "T" + "line_timestamp"
//replace = "2025-02-26" + "T" + "line_timestamp"
}
//RFC3339: 2006-01-02T15:04:05-07:00
//2006-01-02T15:04:05.000000Z
stage.timestamp {
source = "time"
location = "Africa/Abidjan"
format = "RFC3339"
}
}
Here’s the error I get. Note that line 56 is the start of the above process block:
alloy-1 | Error: /etc/alloy/config.alloy:56:1: Failed to build component: building component: invalid stage config empty source
What am I doing wrong? I can get the value of a label in a loki.relabel block, but not in a loki.process block.
Thank you in advance for your help.