Skip to content

Commit e344cf4

Browse files
authored
PromQL: fix incorrect usage of datetime literals (#138737)
fixes #138636
1 parent 30f327e commit e344cf4

File tree

11 files changed

+29
-18
lines changed

11 files changed

+29
-18
lines changed

x-pack/plugin/esql-core/src/main/java/org/elasticsearch/xpack/esql/core/expression/Literal.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ public static Literal timeDuration(Source source, Duration literal) {
219219
}
220220

221221
public static Literal dateTime(Source source, Instant literal) {
222-
return new Literal(source, literal, DataType.DATETIME);
222+
return new Literal(source, literal.toEpochMilli(), DataType.DATETIME);
223223
}
224224

225225
public static Literal integer(Source source, Integer literal) {

x-pack/plugin/esql/qa/server/src/main/java/org/elasticsearch/xpack/esql/qa/rest/generative/GenerativeForkRestTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ protected void shouldSkipTest(String testName) throws IOException {
6262

6363
assumeFalse(
6464
"Tests using PROMQL are not supported for now",
65-
testCase.requiredCapabilities.contains(PROMQL_PRE_TECH_PREVIEW_V1.capabilityName())
65+
testCase.requiredCapabilities.contains(PROMQL_PRE_TECH_PREVIEW_V2.capabilityName())
6666
);
6767

6868
assumeFalse(

x-pack/plugin/esql/qa/testFixtures/src/main/resources/k8s-timeseries-avg-over-time.csv-spec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ cost:double | time_bucket:datetime
1818
;
1919

2020
avg_over_time_of_double_no_grouping_promql
21-
required_capability: promql_pre_tech_preview_v1
21+
required_capability: promql_pre_tech_preview_v2
2222
TS k8s
2323
| PROMQL step 1m (sum(avg_over_time(network.cost[1m])))
2424
| SORT `sum(avg_over_time(network.cost[1m]))` DESC, step DESC | LIMIT 10;
@@ -47,7 +47,7 @@ cost:double | time_bucket:datetime
4747
;
4848

4949
avg_over_time_of_double_no_grouping_single_bucket_promql
50-
required_capability: promql_pre_tech_preview_v1
50+
required_capability: promql_pre_tech_preview_v2
5151
TS k8s
5252
| PROMQL step 1h (sum(avg_over_time(network.cost[1h])));
5353

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
promql_start_end_step
2+
required_capability: promql_pre_tech_preview_v2
3+
TS k8s
4+
| PROMQL step 5m start "2024-05-10T00:20:00.000Z" end "2024-05-10T00:25:00.000Z" (
5+
sum(avg_over_time(network.cost[5m]))
6+
);
7+
8+
sum(avg_over_time(network.cost[5m])):double | step:date
9+
50.25 | 2024-05-10T00:20:00.000Z
10+
;
11+

x-pack/plugin/esql/qa/testFixtures/src/main/resources/k8s-timeseries.csv-spec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ max(rate(network.total_bytes_in)): double | time_bucket:date
133133
;
134134

135135
oneRateWithPromql
136-
required_capability: promql_pre_tech_preview_v1
136+
required_capability: promql_pre_tech_preview_v2
137137
TS k8s
138138
| PROMQL step 5m (max(rate(network.total_bytes_in[5m])))
139139
| SORT step DESC | LIMIT 2;
@@ -154,7 +154,7 @@ max(rate(network.total_bytes_in)): double | time_bucket:date
154154
;
155155

156156
oneRateWithSingleStepPromql
157-
required_capability: promql_pre_tech_preview_v1
157+
required_capability: promql_pre_tech_preview_v2
158158
TS k8s
159159
| PROMQL step 1h (max(rate(network.total_bytes_in[1h])));
160160

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/action/EsqlCapabilities.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1705,7 +1705,7 @@ public enum Cap {
17051705
* As soon as we move into tech preview, we'll replace this capability with a "EXPONENTIAL_HISTOGRAM_TECH_PREVIEW" one.
17061706
* At this point, we need to add new capabilities for any further changes.
17071707
*/
1708-
PROMQL_PRE_TECH_PREVIEW_V1(Build.current().isSnapshot()),
1708+
PROMQL_PRE_TECH_PREVIEW_V2(Build.current().isSnapshot()),
17091709

17101710
/**
17111711
* KNN function adds support for k and visit_percentage options

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/action/PromqlFeatures.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ private PromqlFeatures() {
2121
* Exists to provide a single point of change and minimize noise when upgrading capability versions.
2222
*/
2323
public static boolean isEnabled() {
24-
return EsqlCapabilities.Cap.TS_COMMAND_V0.isEnabled() && EsqlCapabilities.Cap.PROMQL_PRE_TECH_PREVIEW_V1.isEnabled();
24+
return EsqlCapabilities.Cap.TS_COMMAND_V0.isEnabled() && EsqlCapabilities.Cap.PROMQL_PRE_TECH_PREVIEW_V2.isEnabled();
2525
}
2626
}

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/CsvTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ public final void test() throws Throwable {
301301
);
302302
assumeFalse(
303303
"can't load metrics in csv tests",
304-
testCase.requiredCapabilities.contains(EsqlCapabilities.Cap.PROMQL_PRE_TECH_PREVIEW_V1.capabilityName())
304+
testCase.requiredCapabilities.contains(EsqlCapabilities.Cap.PROMQL_PRE_TECH_PREVIEW_V2.capabilityName())
305305
);
306306
assumeFalse(
307307
"can't use QSTR function in csv tests",
@@ -365,7 +365,7 @@ public final void test() throws Throwable {
365365
);
366366
assumeFalse(
367367
"can't use PromQL in csv tests",
368-
testCase.requiredCapabilities.contains(EsqlCapabilities.Cap.PROMQL_PRE_TECH_PREVIEW_V1.capabilityName())
368+
testCase.requiredCapabilities.contains(EsqlCapabilities.Cap.PROMQL_PRE_TECH_PREVIEW_V2.capabilityName())
369369
);
370370

371371
if (Build.current().isSnapshot()) {

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/parser/promql/PromqlParamsTests.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ public static void checkPromqlEnabled() {
3939

4040
public void testValidRangeQuery() {
4141
PromqlCommand promql = parse("TS test | PROMQL start \"2025-10-31T00:00:00Z\" end \"2025-10-31T01:00:00Z\" step 1m (avg(foo))");
42-
assertThat(promql.start().value(), equalTo(Instant.parse("2025-10-31T00:00:00Z")));
43-
assertThat(promql.end().value(), equalTo(Instant.parse("2025-10-31T01:00:00Z")));
42+
assertThat(promql.start().value(), equalTo(Instant.parse("2025-10-31T00:00:00Z").toEpochMilli()));
43+
assertThat(promql.end().value(), equalTo(Instant.parse("2025-10-31T01:00:00Z").toEpochMilli()));
4444
assertThat(promql.step().value(), equalTo(Duration.ofMinutes(1)));
4545
assertThat(promql.isRangeQuery(), equalTo(true));
4646
assertThat(promql.isInstantQuery(), equalTo(false));
@@ -60,8 +60,8 @@ public void testValidRangeQueryParams() {
6060
),
6161
PromqlCommand.class
6262
);
63-
assertThat(promql.start().value(), equalTo(Instant.parse("2025-10-31T00:00:00Z")));
64-
assertThat(promql.end().value(), equalTo(Instant.parse("2025-10-31T01:00:00Z")));
63+
assertThat(promql.start().value(), equalTo(Instant.parse("2025-10-31T00:00:00Z").toEpochMilli()));
64+
assertThat(promql.end().value(), equalTo(Instant.parse("2025-10-31T01:00:00Z").toEpochMilli()));
6565
assertThat(promql.step().value(), equalTo(Duration.ofMinutes(1)));
6666
assertThat(promql.isRangeQuery(), equalTo(true));
6767
assertThat(promql.isInstantQuery(), equalTo(false));
@@ -78,8 +78,8 @@ public void testValidRangeQueryOnlyStep() {
7878

7979
public void testValidInstantQuery() {
8080
PromqlCommand promql = parse("TS test | PROMQL time \"2025-10-31T00:00:00Z\" (avg(foo))");
81-
assertThat(promql.start().value(), equalTo(Instant.parse("2025-10-31T00:00:00Z")));
82-
assertThat(promql.end().value(), equalTo(Instant.parse("2025-10-31T00:00:00Z")));
81+
assertThat(promql.start().value(), equalTo(Instant.parse("2025-10-31T00:00:00Z").toEpochMilli()));
82+
assertThat(promql.end().value(), equalTo(Instant.parse("2025-10-31T00:00:00Z").toEpochMilli()));
8383
assertThat(promql.step().value(), nullValue());
8484
assertThat(promql.isInstantQuery(), equalTo(true));
8585
assertThat(promql.isRangeQuery(), equalTo(false));

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/telemetry/VerifierMetricsTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -816,7 +816,7 @@ public void testBinaryPlanAfterSubqueryInFromCommand() {
816816

817817
@AwaitsFix(bugUrl = "unresolved @timestamp field")
818818
public void testPromql() {
819-
assumeTrue("PromQL required", EsqlCapabilities.Cap.PROMQL_PRE_TECH_PREVIEW_V1.isEnabled());
819+
assumeTrue("PromQL required", EsqlCapabilities.Cap.PROMQL_PRE_TECH_PREVIEW_V2.isEnabled());
820820
Counters c = esql("""
821821
TS metrics
822822
| PROMQL step 5m (sum(salary))""");

0 commit comments

Comments
 (0)