Set Default Value of Prometheus Label if not set
I had to implement the following behaviour in a prometheus relabel config:
Given two labels A and B. I want to set A to the value of label B, if and only if A is empty/not-set.
First I tried to find a proper action in the prometheus relabel_config,
but I did not find any. Luckily the
replace action only replaces the target label
if the given regex matches. Therefore, the following relabel config has the wanted property:
It works because the values of the
source_labels are joined by the
concatenating the two values, the regex is matched against the concatenated values. The regex above,
only matches if
A is empty. The value of
B will be matched by the first and only group reference.
replace only replaces the value of label
A if it is empty.