From ea40c15fe9d69273281bda41ab3e300087156ec8 Mon Sep 17 00:00:00 2001 From: Guillaume Berche Date: Mon, 3 Oct 2022 18:06:27 +0200 Subject: [PATCH 1/4] Refine documentation for label_replace Illustrate use of named capturing group syntax available from https://github.com/google/re2/wiki/Syntax and their usage in the replacement field Signed-off-by: Guillaume Berche --- docs/querying/functions.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/querying/functions.md b/docs/querying/functions.md index 5f0774136..79502a19c 100644 --- a/docs/querying/functions.md +++ b/docs/querying/functions.md @@ -292,13 +292,13 @@ For each timeseries in `v`, `label_replace(v instant-vector, dst_label string, r 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. +regular expression can be referenced with `$1`, `$2`, etc. Named capturing groups in the regular expression can be referenced with `$name` (where `name` is the capturing group name). If the regular expression doesn't match then the timeseries is returned unchanged. -This example will return timeseries with the values `a:c` at label `service` and `a` at label `foo`: +These two examples will both 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", "(.*):.*") +label_replace(up{job="api-server",service="a:c"}, "foo", "$name", "service", "(?P.*):(?P.*)") ``` ## `ln()` From e6b84ac1e09b1b7774686c6679babf34cf075f84 Mon Sep 17 00:00:00 2001 From: Guillaume Berche Date: Thu, 13 Oct 2022 10:40:52 +0200 Subject: [PATCH 2/4] functions.md doc refinement Removed named capture group example in label_replace Signed-off-by: Guillaume Berche --- docs/querying/functions.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/querying/functions.md b/docs/querying/functions.md index 79502a19c..3658c10c6 100644 --- a/docs/querying/functions.md +++ b/docs/querying/functions.md @@ -294,11 +294,10 @@ matches, the value of the label `dst_label` in the returned timeseries will be t of `replacement`, together with the original labels in the input. Capturing groups in the regular expression can be referenced with `$1`, `$2`, etc. Named capturing groups in the regular expression can be referenced with `$name` (where `name` is the capturing group name). If the regular expression doesn't match then the timeseries is returned unchanged. -These two examples will both return timeseries with the values `a:c` at label `service` and `a` at label `foo`: +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", "(.*):.*") -label_replace(up{job="api-server",service="a:c"}, "foo", "$name", "service", "(?P.*):(?P.*)") ``` ## `ln()` From 60b380da70213975bfd343be64f5b89b03e2c944 Mon Sep 17 00:00:00 2001 From: Guillaume Berche Date: Wed, 12 Jul 2023 09:08:23 +0200 Subject: [PATCH 3/4] Refine functions.md as suggested during review See https://github.com/prometheus/prometheus/pull/11404#issuecomment-1631165746 Signed-off-by: Guillaume Berche --- docs/querying/functions.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/querying/functions.md b/docs/querying/functions.md index 3658c10c6..9b58cc319 100644 --- a/docs/querying/functions.md +++ b/docs/querying/functions.md @@ -289,7 +289,7 @@ 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 value of the label `src_label`. If it +matches the [regular expression](https://github.com/google/re2/wiki/Syntax) `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. Named capturing groups in the regular expression can be referenced with `$name` (where `name` is the capturing group name). If the regular expression doesn't match then the timeseries is returned unchanged. @@ -300,6 +300,10 @@ This example will return timeseries with the values `a:c` at label `service` and label_replace(up{job="api-server",service="a:c"}, "foo", "$1", "service", "(.*):.*") ``` +This second example has the same effect than the first example, and illustrates use of named capturing groups: +``` +label_replace(up{job="api-server",service="a:c"}, "foo", "$name", "service", "(?P.*):(?P.*)") +``` ## `ln()` `ln(v instant-vector)` calculates the natural logarithm for all elements in `v`. From f5fb37dbabf29822ce9ad8461d289ba801d96dab Mon Sep 17 00:00:00 2001 From: Guillaume Berche Date: Wed, 19 Jul 2023 08:27:15 +0200 Subject: [PATCH 4/4] Update functions.md Add missing linefeed as requested by https://github.com/prometheus/prometheus/pull/11404#discussion_r1266625301 Signed-off-by: Guillaume Berche --- docs/querying/functions.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/querying/functions.md b/docs/querying/functions.md index 9b58cc319..bd67dba25 100644 --- a/docs/querying/functions.md +++ b/docs/querying/functions.md @@ -304,6 +304,7 @@ This second example has the same effect than the first example, and illustrates ``` label_replace(up{job="api-server",service="a:c"}, "foo", "$name", "service", "(?P.*):(?P.*)") ``` + ## `ln()` `ln(v instant-vector)` calculates the natural logarithm for all elements in `v`.