prometheus/promql/promqltest/testdata
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
..
aggregators.test promql: make avg aggregation more precise and less expensive 2024-07-10 19:20:24 +02:00
at_modifier.test Allow durations for number rule 2024-07-10 15:50:22 +02:00
collision.test test: move test files into new promqltest package 2024-05-08 13:42:55 +01:00
functions.test Fall back to comparing by label set when sorting by label desc 2024-08-11 21:44:03 +02:00
histograms.test Update from review comments. 2024-08-13 15:26:07 +02:00
limit.test feat: add limitk() and limit_ratio() operators (#12503) 2024-07-03 22:18:57 +02:00
literals.test test: move test files into new promqltest package 2024-05-08 13:42:55 +01:00
name_label_dropping.test PromQL engine: Delay deletion of __name__ label to the end of the query evaluation (#14477) 2024-08-29 15:50:39 +02:00
native_histograms.test convert TestNativeHistogram_Sum_Count_Add_AvgOperator into testing framework 2024-08-21 09:24:50 +08:00
operators.test test: move test files into new promqltest package 2024-05-08 13:42:55 +01:00
range_queries.test Convert range query test cases to test scripting language 2024-06-17 16:43:01 +10:00
selectors.test test: move test files into new promqltest package 2024-05-08 13:42:55 +01:00
staleness.test Allow number literals as duration 2024-07-10 15:49:30 +02:00
subquery.test Allow number literals as duration 2024-07-10 15:49:30 +02:00
trig_functions.test test: move test files into new promqltest package 2024-05-08 13:42:55 +01:00