loki.relabel
The loki.relabel component rewrites the label set of each log entry passed to its receiver by applying one or more relabeling rules and forwards the results to the list of receivers in the component’s arguments.
If no labels remain after the relabeling rules are applied, then the log entries are dropped.
The most common use of loki.relabel is to filter log entries or standardize the label set that’s passed to one or more downstream receivers.
The rule blocks are applied to the label set of each log entry in order of their appearance in the configuration file.
The configured rules can be retrieved by calling the function in the rules export field.
If you’re looking for a way to process the log entry contents, use the loki.process component instead.
You can specify multiple loki.relabel components by giving them different labels.
Usage
loki.relabel "<LABEL>" {
forward_to = <RECEIVER_LIST>
rule {
...
}
...
}Arguments
You can use the following arguments with loki.relabel:
Blocks
You can use the following block with loki.relabel:
rule
The rule block contains the definition of any relabeling rules that can be applied to an input log.
The transformations are applied in top-down order if more than one rule block is defined.
You can use the following arguments to configure a rule.
All arguments are optional. Omitted fields take their default values.
You can use the following actions:
drop- Drops logs whereregexmatches the string extracted using thesource_labelsandseparator.dropequal- Drop targets for which the concatenatedsource_labelsdo matchtarget_label.hashmod- Hashes the concatenated labels, calculates its modulomodulus, and writes the result to thetarget_label.keep- Keeps logs whereregexmatches the string extracted using thesource_labelsandseparator.keepequal- Drop targets for which the concatenatedsource_labelsdon’t matchtarget_label.labeldrop- Matchesregexagainst all label names. Any labels that match are removed from the log’s label set.labelkeep- Matchesregexagainst all label names. Any labels that don’t match are removed from the log’s label set.labelmap- Matchesregexagainst all label names. Any labels that match are renamed according to the contents of thereplacementfield.lowercase- Setstarget_labelto the lowercase form of the concatenatedsource_labels.replace- Matchesregexto the concatenated labels. If there’s a match, it replaces the content of thetarget_labelusing the contents of thereplacementfield.uppercase- Setstarget_labelto the uppercase form of the concatenatedsource_labels.
Note
The regular expression capture groups can be referred to using either the
$CAPTURE_GROUP_NUMBERor${CAPTURE_GROUP_NUMBER}notation.
Exported fields
The following fields are exported and can be referenced by other components:
Component health
loki.relabel is only reported as unhealthy if given an invalid configuration.
In those cases, exported fields are kept at their last healthy values.
Debug information
loki.relabel doesn’t expose any component-specific debug information.
Debug metrics
loki_relabel_entries_processed(counter): Total number of log entries processed.loki_relabel_entries_written(counter): Total number of log entries forwarded.loki_relabel_cache_misses(counter): Total number of cache misses.loki_relabel_cache_hits(counter): Total number of cache hits.loki_relabel_cache_size(gauge): Total size of relabel cache.
Example
The following example creates a loki.relabel component that only forwards entries whose ’level’ value is set to ’error'.
loki.relabel "keep_error_only" {
forward_to = [loki.write.onprem.receiver]
rule {
action = "keep"
source_labels = ["level"]
regex = "error"
}
}Compatible components
loki.relabel can accept arguments from the following components:
- Components that export Loki
LogsReceiver
loki.relabel has exports that can be consumed by the following components:
- Components that consume Loki
LogsReceiver
Note
Connecting some components may not be sensible or components may require further configuration to make the connection work correctly. Refer to the linked documentation for more details.



