Merge pull request #15445 from rynkat/update-docs-anchored-regex

docs: make it clearer that regexps are always fully anchored
This commit is contained in:
Björn Rabenstein 2024-11-27 20:52:29 +01:00 committed by GitHub
commit 5ceb603615
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 11 additions and 11 deletions

View file

@ -37,7 +37,7 @@ Depending on the use-case (e.g. when graphing vs. displaying the output of an
expression), only some of these types are legal as the result of a
user-specified expression.
For [instant queries](api.md#instant-queries), any of the above data types are allowed as the root of the expression.
[Range queries](api.md/#range-queries) only support scalar-typed and instant-vector-typed expressions.
[Range queries](api.md#range-queries) only support scalar-typed and instant-vector-typed expressions.
_Notes about the experimental native histograms:_
@ -152,7 +152,7 @@ The value returned will be that of the most recent sample at or before the
query's evaluation timestamp (in the case of an
[instant query](api.md#instant-queries))
or the current step within the query (in the case of a
[range query](api.md/#range-queries)).
[range query](api.md#range-queries)).
The [`@` modifier](#modifier) allows overriding the timestamp relative to which
the selection takes place. Time series are only returned if their most recent sample is less than the [lookback period](#staleness) ago.
@ -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.