|
| 1 | +/* |
| 2 | + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one |
| 3 | + * or more contributor license agreements. Licensed under the Elastic License |
| 4 | + * 2.0; you may not use this file except in compliance with the Elastic License |
| 5 | + * 2.0. |
| 6 | + */ |
| 7 | + |
| 8 | +package org.elasticsearch.xpack.esql.analysis.promql; |
| 9 | + |
| 10 | +import org.elasticsearch.test.ESTestCase; |
| 11 | +import org.elasticsearch.xpack.esql.analysis.Analyzer; |
| 12 | +import org.elasticsearch.xpack.esql.analysis.AnalyzerTestUtils; |
| 13 | +import org.junit.Ignore; |
| 14 | + |
| 15 | +import java.util.List; |
| 16 | + |
| 17 | +import static org.elasticsearch.xpack.esql.EsqlTestUtils.withDefaultLimitWarning; |
| 18 | +import static org.elasticsearch.xpack.esql.analysis.VerifierTests.error; |
| 19 | +import static org.hamcrest.Matchers.equalTo; |
| 20 | + |
| 21 | +public class PromqlVerifierTests extends ESTestCase { |
| 22 | + |
| 23 | + private final Analyzer tsdb = AnalyzerTestUtils.analyzer(AnalyzerTestUtils.tsdbIndexResolution()); |
| 24 | + |
| 25 | + public void testPromqlMissingAcrossSeriesAggregation() { |
| 26 | + assertThat( |
| 27 | + error(""" |
| 28 | + TS test | PROMQL step 5m ( |
| 29 | + rate(network.bytes_in[5m]) |
| 30 | + )""", tsdb), |
| 31 | + equalTo( |
| 32 | + "2:3: within time series aggregate function [rate(network.bytes_in[5m])] can only be used " |
| 33 | + + "inside an across time series aggregate function at this time" |
| 34 | + ) |
| 35 | + ); |
| 36 | + } |
| 37 | + |
| 38 | + public void testPromqlIllegalNameLabelMatcher() { |
| 39 | + assertThat( |
| 40 | + error("TS test | PROMQL step 5m ({__name__=~\"*.foo.*\"})", tsdb), |
| 41 | + equalTo("1:27: regex label selectors on __name__ are not supported at this time [{__name__=~\"*.foo.*\"}]") |
| 42 | + ); |
| 43 | + } |
| 44 | + |
| 45 | + @Ignore |
| 46 | + public void testPromqlSubquery() { |
| 47 | + // TODO doesn't parse |
| 48 | + // line 1:36: Invalid query 'network.bytes_in'[ValueExpressionContext] given; expected Expression but found |
| 49 | + // InstantSelector |
| 50 | + assertThat(error("TS test | PROMQL step 5m (avg(rate(network.bytes_in[5m:])))", tsdb), equalTo("")); |
| 51 | + assertThat(error("TS test | PROMQL step 5m (avg(rate(network.bytes_in[5m:1m])))", tsdb), equalTo("")); |
| 52 | + } |
| 53 | + |
| 54 | + @Ignore |
| 55 | + public void testPromqlArithmetricOperators() { |
| 56 | + // TODO doesn't parse |
| 57 | + // line 1:27: Invalid query '1+1'[ArithmeticBinaryContext] given; expected LogicalPlan but found VectorBinaryArithmetic |
| 58 | + assertThat( |
| 59 | + error("TS test | PROMQL step 5m (1+1)", tsdb), |
| 60 | + equalTo("1:27: arithmetic operators are not supported at this time [foo]") |
| 61 | + ); |
| 62 | + assertThat( |
| 63 | + error("TS test | PROMQL step 5m (foo+1)", tsdb), |
| 64 | + equalTo("1:27: arithmetic operators are not supported at this time [foo]") |
| 65 | + ); |
| 66 | + assertThat( |
| 67 | + error("TS test | PROMQL step 5m (1+foo)", tsdb), |
| 68 | + equalTo("1:27: arithmetic operators are not supported at this time [foo]") |
| 69 | + ); |
| 70 | + assertThat( |
| 71 | + error("TS test | PROMQL step 5m (foo+bar)", tsdb), |
| 72 | + equalTo("1:27: arithmetic operators are not supported at this time [foo]") |
| 73 | + ); |
| 74 | + } |
| 75 | + |
| 76 | + @Ignore |
| 77 | + public void testPromqlVectorMatching() { |
| 78 | + // TODO doesn't parse |
| 79 | + // line 1:27: Invalid query 'method_code_http_errors_rate5m{code="500"}'[ValueExpressionContext] given; expected Expression but |
| 80 | + // found InstantSelector |
| 81 | + assertThat( |
| 82 | + error( |
| 83 | + "TS test | PROMQL step 5m (method_code_http_errors_rate5m{code=\"500\"} / ignoring(code) method_http_requests_rate5m)", |
| 84 | + tsdb |
| 85 | + ), |
| 86 | + equalTo("") |
| 87 | + ); |
| 88 | + assertThat( |
| 89 | + error( |
| 90 | + "TS test | PROMQL step 5m (method_code_http_errors_rate5m / ignoring(code) group_left method_http_requests_rate5m)", |
| 91 | + tsdb |
| 92 | + ), |
| 93 | + equalTo("") |
| 94 | + ); |
| 95 | + } |
| 96 | + |
| 97 | + public void testPromqlModifier() { |
| 98 | + assertThat( |
| 99 | + error("TS test | PROMQL step 5m (foo offset 5m)", tsdb), |
| 100 | + equalTo("1:27: offset modifiers are not supported at this time [foo offset 5m]") |
| 101 | + ); |
| 102 | + /* TODO |
| 103 | + assertThat( |
| 104 | + error("TS test | PROMQL step 5m (foo @ start())", tsdb), |
| 105 | + equalTo("1:27: @ modifiers are not supported at this time [foo @ start()]") |
| 106 | + );*/ |
| 107 | + } |
| 108 | + |
| 109 | + @Ignore |
| 110 | + public void testLogicalSetBinaryOperators() { |
| 111 | + // TODO doesn't parse |
| 112 | + // line 1:27: Invalid query 'foo'[ValueExpressionContext] given; expected Expression but found InstantSelector |
| 113 | + assertThat(error("TS test | PROMQL step 5m (foo and bar)", tsdb), equalTo("")); |
| 114 | + assertThat(error("TS test | PROMQL step 5m (foo or bar)", tsdb), equalTo("")); |
| 115 | + assertThat(error("TS test | PROMQL step 5m (foo unless bar)", tsdb), equalTo("")); |
| 116 | + } |
| 117 | + |
| 118 | + @Override |
| 119 | + protected List<String> filteredWarnings() { |
| 120 | + return withDefaultLimitWarning(super.filteredWarnings()); |
| 121 | + } |
| 122 | +} |
0 commit comments