docs: add regex section in querying basics

Signed-off-by: Kateryna Pavlova <kathrinett@gmail.com>
This commit is contained in:
Kateryna Pavlova 2024-11-24 22:03:04 +01:00
parent bc008f1b0e
commit d6e43b89f4
3 changed files with 9 additions and 9 deletions

View file

@ -178,7 +178,7 @@ against regular expressions. The following label matching operators exist:
* `=~`: Select labels that regex-match the provided string.
* `!~`: Select labels that do not regex-match the provided string.
Regex matches are fully anchored. A match of `env=~"foo"` is treated as `env=~"^foo$"`.
[Regex](#regular-expressions) matches are fully anchored. A match of `env=~"foo"` is treated as `env=~"^foo$"`.
For example, this selects all `http_requests_total` time series for `staging`,
`testing`, and `development` environments and HTTP methods other than `GET`.
@ -241,9 +241,6 @@ A workaround for this restriction is to use the `__name__` label:
{__name__="on"} # Good!
All regular expressions in Prometheus use [RE2
syntax](https://github.com/google/re2/wiki/Syntax).
### Range Vector Selectors
Range vector literals work like instant vector literals, except that they
@ -365,6 +362,12 @@ PromQL supports line comments that start with `#`. Example:
# This is a comment
## Regular expressions
All regular expressions in Prometheus use [RE2 syntax](https://github.com/google/re2/wiki/Syntax).
Regex matches are always fully anchored.
## Gotchas
### Staleness

View file

@ -25,14 +25,11 @@ for the same vector, making it a [range vector](../basics/#range-vector-selector
Note that an expression resulting in a range vector cannot be graphed directly,
but viewed in the tabular ("Console") view of the expression browser.
Using regular expressions, you could select time series only for jobs whose
Using [regular expressions](./basics.md#regular-expressions), you could select time series only for jobs whose
name match a certain pattern, in this case, all jobs that end with `server`:
http_requests_total{job=~".*server"}
All regular expressions in Prometheus use [RE2
syntax](https://github.com/google/re2/wiki/Syntax).
To select all HTTP status codes except 4xx ones, you could run:
http_requests_total{status!~"4.."}

View file

@ -598,7 +598,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](https://github.com/google/re2/wiki/Syntax) `regex` against the value of the label `src_label`. If it
matches the [regular expression](./basics.md#regular-expressions) `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.