prometheus/docs
Jorge Creixell e9e3d64b7c
PromQL engine: Delay deletion of __name__ label to the end of the query evaluation (#14477)
PromQL engine: Delay deletion of __name__ label to the end of the query evaluation

  - This change allows optionally preserving the `__name__` label via the `label_replace` and `label_join` functions, and helps prevent the dreaded "vector cannot contain metrics with the same labelset" error.
  - The implementation extends the `Series` and `Sample` structs with a boolean flag indicating whether the `__name__` label should be deleted at the end of the query evaluation.
  - The `label_replace` and `label_join` functions can still access the value of the `__name__` label, even if it has been previously marked for deletion. If  `__name__` is used as target label, it won't be dropped at the end of the query evaluation.
  - Fixes https://github.com/prometheus/prometheus/issues/11397
  - See https://github.com/jcreixell/prometheus/pull/2 for previous discussion, including the decision to create this PR and benchmark it before considering other alternatives (like refactoring `labels.Labels`).
  - See https://github.com/jcreixell/prometheus/pull/1 for an alternative implementation using a special label instead of boolean flags.
  - Note: a feature flag  `promql-delayed-name-removal` has been added as it changes the behavior of some "weird" queries (see https://github.com/prometheus/prometheus/issues/11397#issuecomment-1451998792)

Example (this always fails, as `__name__` is being dropped by `count_over_time`):

```
count_over_time({__name__!=""}[1m])

=> Error executing query: vector cannot contain metrics with the same labelset
```

Before:

```
label_replace(count_over_time({__name__!=""}[1m]), "__name__", "count_$1", "__name__", "(.+)")

=> Error executing query: vector cannot contain metrics with the same labelset
```

After:

```
label_replace(count_over_time({__name__!=""}[1m]), "__name__", "count_$1", "__name__", "(.+)")

=>
count_go_gc_cycles_automatic_gc_cycles_total{instance="localhost:9090", job="prometheus"} 1
count_go_gc_cycles_forced_gc_cycles_total{instance="localhost:9090", job="prometheus"} 1
...
```

Signed-off-by: Jorge Creixell <jcreixell@gmail.com>

---------

Signed-off-by: Jorge Creixell <jcreixell@gmail.com>
Signed-off-by: Björn Rabenstein <github@rabenste.in>
2024-08-29 15:50:39 +02:00
..
command-line PromQL engine: Delay deletion of __name__ label to the end of the query evaluation (#14477) 2024-08-29 15:50:39 +02:00
configuration Merge branch 'release-2.54' into merge-2.54.1-into-main 2024-08-27 12:04:48 +01:00
images Add 2.0 storage docs (#3423) 2017-11-07 22:00:38 +01:00
querying Merge pull request #14655 from suntala/suntala/sort-by-label-enhancement 2024-08-21 12:28:55 +02:00
feature_flags.md PromQL engine: Delay deletion of __name__ label to the end of the query evaluation (#14477) 2024-08-29 15:50:39 +02:00
federation.md docs: Update federation docs for native histograms 2023-01-12 20:43:02 +05:30
getting_started.md Update getting_started.md 2023-05-15 13:18:30 +05:30
http_sd.md Added a failure counter to the HTTP service discovery (#10372) 2022-03-08 14:10:45 +01:00
index.md Update prometheus.io's URL to the latest version (#5270) 2019-02-27 10:39:50 +00:00
installation.md docs: clarify default Docker command line parameters (#14194) 2024-06-10 20:16:02 +02:00
management_api.md /-/{healthy,ready}/ respond to HEAD (#11160) 2022-08-16 21:06:26 +02:00
migration.md Document command line tools 2023-03-13 14:20:55 +01:00
stability.md docs: state that remote write is stable 2023-05-09 10:29:52 +00:00
storage.md Update storage.md to provide right-sizing advice on retention 2024-07-15 12:30:16 -04:00