mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-10-13 23:42:32 +00:00
fix(promql): default a stepless subquery to a one-minute step (#9481)
* fix(promql): default a stepless subquery to a one-minute step
`x[5m:]` evaluated the inner expression at the query step, which is 1s
for instant queries. Prometheus uses the evaluation interval, one minute
by default.
Signed-off-by: Dennis Zhuang <killme2008@gmail.com>
* test(promql): cover the default subquery step
Signed-off-by: Dennis Zhuang <killme2008@gmail.com>
* test(promql): cover the default subquery step in a range query
Signed-off-by: Dennis Zhuang <killme2008@gmail.com>
---------
Signed-off-by: Dennis Zhuang <killme2008@gmail.com>
(cherry picked from commit 845fc0af9c)
Signed-off-by: WenyXu <wenymedia@gmail.com>
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
-- A subquery without a step uses the evaluation interval (one minute by
|
||||
-- default in Prometheus), not the query step. Expected results are from Prometheus 3.
|
||||
create table subquery_default_step (
|
||||
ts timestamp time index,
|
||||
val double,
|
||||
host string primary key
|
||||
);
|
||||
|
||||
Affected Rows: 0
|
||||
|
||||
insert into subquery_default_step values
|
||||
(0, 1.0, 'a'),
|
||||
(60000, 1.0, 'a'),
|
||||
(120000, 1.0, 'a'),
|
||||
(180000, 1.0, 'a'),
|
||||
(240000, 1.0, 'a'),
|
||||
(300000, 1.0, 'a');
|
||||
|
||||
Affected Rows: 6
|
||||
|
||||
tql eval (300, 300, '1s') count_over_time(subquery_default_step[5m:]);
|
||||
|
||||
+---------------------+------------------------------------+------+
|
||||
| ts | prom_count_over_time(ts_range,val) | host |
|
||||
+---------------------+------------------------------------+------+
|
||||
| 1970-01-01T00:05:00 | 5.0 | a |
|
||||
+---------------------+------------------------------------+------+
|
||||
|
||||
tql eval (300, 300, '1s') count_over_time(subquery_default_step[5m:30s]);
|
||||
|
||||
+---------------------+------------------------------------+------+
|
||||
| ts | prom_count_over_time(ts_range,val) | host |
|
||||
+---------------------+------------------------------------+------+
|
||||
| 1970-01-01T00:05:00 | 10.0 | a |
|
||||
+---------------------+------------------------------------+------+
|
||||
|
||||
-- The outer range query keeps its own step around the subquery's default step.
|
||||
tql eval (300, 360, '15s') count_over_time(subquery_default_step[5m:]);
|
||||
|
||||
+---------------------+------------------------------------+------+
|
||||
| ts | prom_count_over_time(ts_range,val) | host |
|
||||
+---------------------+------------------------------------+------+
|
||||
| 1970-01-01T00:05:00 | 5.0 | a |
|
||||
| 1970-01-01T00:05:15 | 5.0 | a |
|
||||
| 1970-01-01T00:05:30 | 5.0 | a |
|
||||
| 1970-01-01T00:05:45 | 5.0 | a |
|
||||
| 1970-01-01T00:06:00 | 5.0 | a |
|
||||
+---------------------+------------------------------------+------+
|
||||
|
||||
drop table subquery_default_step;
|
||||
|
||||
Affected Rows: 0
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
-- A subquery without a step uses the evaluation interval (one minute by
|
||||
-- default in Prometheus), not the query step. Expected results are from Prometheus 3.
|
||||
|
||||
create table subquery_default_step (
|
||||
ts timestamp time index,
|
||||
val double,
|
||||
host string primary key
|
||||
);
|
||||
|
||||
insert into subquery_default_step values
|
||||
(0, 1.0, 'a'),
|
||||
(60000, 1.0, 'a'),
|
||||
(120000, 1.0, 'a'),
|
||||
(180000, 1.0, 'a'),
|
||||
(240000, 1.0, 'a'),
|
||||
(300000, 1.0, 'a');
|
||||
|
||||
tql eval (300, 300, '1s') count_over_time(subquery_default_step[5m:]);
|
||||
|
||||
tql eval (300, 300, '1s') count_over_time(subquery_default_step[5m:30s]);
|
||||
|
||||
-- The outer range query keeps its own step around the subquery's default step.
|
||||
tql eval (300, 360, '15s') count_over_time(subquery_default_step[5m:]);
|
||||
|
||||
drop table subquery_default_step;
|
||||
Reference in New Issue
Block a user