From 8490273bac8f01f37833e7dcb5aacd9fb2b44a67 Mon Sep 17 00:00:00 2001 From: Matthew Smedberg Date: Tue, 27 Apr 2021 10:15:45 -0600 Subject: [PATCH 1/2] docs :: querying :: functions :: label_replace Clarify documentation for label_replace() because of ambiguities between label keys and label values. Signed-off-by: Matthew Smedberg --- docs/querying/functions.md | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/docs/querying/functions.md b/docs/querying/functions.md index 16a440165f..d6496edf78 100644 --- a/docs/querying/functions.md +++ b/docs/querying/functions.md @@ -272,7 +272,7 @@ For each timeseries in `v`, `label_join(v instant-vector, dst_label string, sepa using `separator` and returns the timeseries with the label `dst_label` containing the joined value. There can be any number of `src_labels` in this function. -This example will return a vector with each time series having a `foo` label with the value `a,b,c` added to it: +This example will return a vector with each time series having a `foo` label added to it, with the value `a,b,c`: ``` label_join(up{job="api-server",src1="a",src2="b",src3="c"}, "foo", ",", "src1", "src2", "src3") @@ -280,16 +280,14 @@ label_join(up{job="api-server",src1="a",src2="b",src3="c"}, "foo", ",", "src1", ## `label_replace()` -For each timeseries in `v`, `label_replace(v instant-vector, dst_label string, -replacement string, src_label string, regex string)` matches the regular -expression `regex` against the label `src_label`. If it matches, then the -timeseries is returned with the label `dst_label` replaced by the expansion of -`replacement`. `$1` is replaced with the first matching subgroup, `$2` with the -second etc. If the regular expression doesn't match then the timeseries is -returned unchanged. +For each timeseries in `v`, `label_replace(v instant-vector, dst_label string, replacement string, src_label string, regex string)` +matches the regular expression `regex` against the value of the label `src_label`. If it +matches, the value of the label `dst_label` in the returned timeseries will be the expansion +of `replacement`, together with the original labels in the input. Capturing groups in the +regular expression can be referenced with `$1`, `$2`, etc. If the regular expression doesn't +match then the timeseries is returned unchanged. -This example will return a vector with each time series having a `foo` -label with the value `a` added to it: +This example will return timeseries with the values `a:c` at label `service` and `a` at label `foo`: ``` label_replace(up{job="api-server",service="a:c"}, "foo", "$1", "service", "(.*):.*") From 034cdb0aa47921d79a797726520ff92d015b7b3a Mon Sep 17 00:00:00 2001 From: smedbergM Date: Tue, 15 Jun 2021 13:51:07 -0600 Subject: [PATCH 2/2] Revert change in label_join per @RichiH Signed-off-by: smedbergM --- docs/querying/functions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/querying/functions.md b/docs/querying/functions.md index d6496edf78..848908ca90 100644 --- a/docs/querying/functions.md +++ b/docs/querying/functions.md @@ -272,7 +272,7 @@ For each timeseries in `v`, `label_join(v instant-vector, dst_label string, sepa using `separator` and returns the timeseries with the label `dst_label` containing the joined value. There can be any number of `src_labels` in this function. -This example will return a vector with each time series having a `foo` label added to it, with the value `a,b,c`: +This example will return a vector with each time series having a `foo` label with the value `a,b,c` added to it: ``` label_join(up{job="api-server",src1="a",src2="b",src3="c"}, "foo", ",", "src1", "src2", "src3")