Browse Source

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 <guillaume.berche@orange.com>
pull/11404/head
Guillaume Berche 2 years ago committed by GitHub
parent
commit
ea40c15fe9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      docs/querying/functions.md

6
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<name>.*):(?P<version>.*)")
```
## `ln()`

Loading…
Cancel
Save