How do you allow for the
keep relabel action halting relabelling for things not kept?
Any targets dropped by the
drop relabel action won't be processed by any following relabel actions. The same applies for
keep, if it's not kept then it's now gone. In practice this means that a list of actions like
- source_labels: [label] regexp: foo action: keep - source_labels: [label] regexp: bar action: keep
will return nothing, as
label cannot be both
bar at the same time.
You could combine the actions using the regex alternation operator:
- source_labels: [label] regexp: foo|bar action: keep
This can however get a little unwieldy when you want to apply more intricate business logic across multiple source labels.
Another approach would be to set a flag when your criteria is met, and use
keep on that:
- source_labels: [label] regexp: foo target_label: __tmp_keep_me replacement: true - source_labels: [label] regexp: bar target_label: __tmp_keep_me replacement: true - source_labels: [__tmp_keep_me] regex: true action: keep
replace action only has an effect if it matches, so if
__tmp_keep_me label ends up with the value
true which a
keep action can then be predicated on. This pattern can be used with any number of actions.
__tmp prefix is reserved for user usage in target relabelling, and it is promised that no future Prometheus feature will use this prefix. As is begins with
__ it will be discarded with all other metadata before determining the final target labels.
Have questions about relabelling? Contact us.