Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakFilters;

import org.apache.http.util.EntityUtils;
import org.elasticsearch.Build;
import org.elasticsearch.client.Request;
import org.elasticsearch.client.Response;
import org.elasticsearch.common.settings.Settings;
Expand All @@ -18,6 +17,7 @@
import org.elasticsearch.test.rest.ESRestTestCase;
import org.elasticsearch.xpack.esql.AssertWarnings;
import org.elasticsearch.xpack.esql.CsvTestsDataLoader;
import org.elasticsearch.xpack.esql.action.EsqlCapabilities;
import org.elasticsearch.xpack.esql.qa.rest.ProfileLogger;
import org.elasticsearch.xpack.esql.qa.rest.RestEsqlTestCase;
import org.junit.ClassRule;
Expand Down Expand Up @@ -48,7 +48,7 @@ protected String getTestRestCluster() {
}

public void testTimeSeriesQuerying() throws IOException {
assumeTrue("time series querying relies on query pragma", Build.current().isSnapshot());
assumeTrue("time series querying relies on query pragma", EsqlCapabilities.Cap.METRICS_COMMAND.isEnabled());
var settings = Settings.builder()
.loadFromStream("tsdb-settings.json", TSDBRestEsqlIT.class.getResourceAsStream("/tsdb-settings.json"), false)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,18 +149,20 @@ public static Iterable<Object[]> parameters() {
new Object[] {
new Test(
"TS time_series_idx | LIMIT 10",
Build.current().isSnapshot() ? Map.ofEntries(Map.entry("TS", 1), Map.entry("LIMIT", 1)) : Collections.emptyMap(),
EsqlCapabilities.Cap.METRICS_COMMAND.isEnabled()
? Map.ofEntries(Map.entry("TS", 1), Map.entry("LIMIT", 1))
: Collections.emptyMap(),
Map.ofEntries(),
Build.current().isSnapshot()
EsqlCapabilities.Cap.METRICS_COMMAND.isEnabled()
) },
new Object[] {
new Test(
"TS time_series_idx | STATS max(id) BY host | LIMIT 10",
Build.current().isSnapshot()
EsqlCapabilities.Cap.METRICS_COMMAND.isEnabled()
? Map.ofEntries(Map.entry("TS", 1), Map.entry("STATS", 1), Map.entry("LIMIT", 1))
: Collections.emptyMap(),
Build.current().isSnapshot() ? Map.ofEntries(Map.entry("MAX", 1)) : Collections.emptyMap(),
Build.current().isSnapshot()
EsqlCapabilities.Cap.METRICS_COMMAND.isEnabled() ? Map.ofEntries(Map.entry("MAX", 1)) : Collections.emptyMap(),
EsqlCapabilities.Cap.METRICS_COMMAND.isEnabled()
) },
new Object[] {
new Test(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

package org.elasticsearch.xpack.esql.action;

import org.elasticsearch.Build;
import org.elasticsearch.common.Randomness;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.ByteSizeValue;
Expand Down Expand Up @@ -38,7 +37,7 @@ public class TimeSeriesIT extends AbstractEsqlIntegTestCase {

@Override
public EsqlQueryResponse run(EsqlQueryRequest request) {
assumeTrue("time series available in snapshot builds only", Build.current().isSnapshot());
assumeTrue("time series available in snapshot builds only", EsqlCapabilities.Cap.METRICS_COMMAND.isEnabled());
return super.run(request);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

package org.elasticsearch.xpack.esql.action;

import org.elasticsearch.Build;
import org.elasticsearch.common.Randomness;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.xpack.esql.EsqlTestUtils;
Expand All @@ -28,7 +27,7 @@ public class TimeSeriesRateIT extends AbstractEsqlIntegTestCase {

@Override
public EsqlQueryResponse run(EsqlQueryRequest request) {
assumeTrue("time series available in snapshot builds only", Build.current().isSnapshot());
assumeTrue("time series available in snapshot builds only", EsqlCapabilities.Cap.METRICS_COMMAND.isEnabled());
return super.run(request);
}

Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugin/esql/src/main/antlr/lexer/From.g4
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ lexer grammar From;
//
FROM : 'from' -> pushMode(FROM_MODE);

DEV_TIME_SERIES : {this.isDevVersion()}? 'ts' -> pushMode(FROM_MODE);
DEV_TIME_SERIES : {this.hasMetricsCommand()}? 'ts' -> pushMode(FROM_MODE);

mode FROM_MODE;
FROM_PIPE : PIPE -> type(PIPE), popMode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@
package org.elasticsearch.xpack.esql.parser;

import org.elasticsearch.Build;
import org.elasticsearch.xpack.esql.action.EsqlCapabilities;

class EsqlConfig {

// versioning information
boolean devVersion = Build.current().isSnapshot();

boolean metricsCommand = EsqlCapabilities.Cap.METRICS_COMMAND.isEnabled();

public boolean isDevVersion() {
return devVersion;
}
Expand All @@ -25,4 +28,12 @@ boolean isReleaseVersion() {
public void setDevVersion(boolean dev) {
this.devVersion = dev;
}

public boolean hasMetricsCommand() {
return metricsCommand;
}

public void setMetricsCommand(boolean metricsCommand) {
this.metricsCommand = metricsCommand;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ boolean isDevVersion() {
return config == null || config.isDevVersion();
}

boolean hasMetricsCommand() {
return config == null || config.hasMetricsCommand();
}

void setEsqlConfig(EsqlConfig config) {
this.config = config;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ private static Tuple<Mode, String> parsePolicyName(EsqlBaseParser.EnrichPolicyNa

@Override
public LogicalPlan visitTimeSeriesCommand(EsqlBaseParser.TimeSeriesCommandContext ctx) {
if (Build.current().isSnapshot() == false) {
if (EsqlCapabilities.Cap.METRICS_COMMAND.isEnabled() == false) {
throw new IllegalArgumentException("TS command currently requires a snapshot build");
}
return visitRelation(source(ctx), IndexMode.TIME_SERIES, ctx.indexPatternAndMetadataFields());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2458,7 +2458,7 @@ public void testNoDenseVectorFailsForMagnitude() {
}

public void testRateRequiresCounterTypes() {
assumeTrue("rate requires snapshot builds", Build.current().isSnapshot());
assumeTrue("rate requires snapshot builds", EsqlCapabilities.Cap.METRICS_COMMAND.isEnabled());
Analyzer analyzer = analyzer(tsdbIndexResolution());
var query = "TS test | STATS avg(rate(network.connections))";
VerificationException error = expectThrows(VerificationException.class, () -> analyze(query, analyzer));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1139,7 +1139,7 @@ public void testAggsResolutionWithUnresolvedGroupings() {
}

public void testNotAllowRateOutsideMetrics() {
assumeTrue("requires snapshot builds", Build.current().isSnapshot());
assumeTrue("requires metric command", EsqlCapabilities.Cap.METRICS_COMMAND.isEnabled());
assertThat(
error("FROM tests | STATS avg(rate(network.bytes_in))", tsdb),
equalTo("1:24: time_series aggregate[rate(network.bytes_in)] can only be used with the TS command")
Expand All @@ -1159,7 +1159,7 @@ public void testNotAllowRateOutsideMetrics() {
}

public void testRateNotEnclosedInAggregate() {
assumeTrue("requires snapshot builds", Build.current().isSnapshot());
assumeTrue("requires metric command", EsqlCapabilities.Cap.METRICS_COMMAND.isEnabled());
assertThat(
error("TS tests | STATS rate(network.bytes_in)", tsdb),
equalTo("1:18: the rate aggregate [rate(network.bytes_in)] can only be used with the TS command and inside another aggregate")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;

import org.apache.lucene.search.IndexSearcher;
import org.elasticsearch.Build;
import org.elasticsearch.common.network.NetworkAddress;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.Fuzziness;
Expand Down Expand Up @@ -2145,7 +2144,7 @@ public void testMultipleKnnQueriesInPrefilters() {
}

public void testParallelizeTimeSeriesPlan() {
assumeTrue("requires snapshot builds", Build.current().isSnapshot());
assumeTrue("requires metrics command", EsqlCapabilities.Cap.METRICS_COMMAND.isEnabled());
var query = "TS k8s | STATS max(rate(network.total_bytes_in)) BY bucket(@timestamp, 1h)";
var optimizer = new TestPlannerOptimizer(config, timeSeriesAnalyzer);
PhysicalPlan plan = optimizer.plan(query);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7289,7 +7289,7 @@ public void testMultipleLookupShadowing() {
}

public void testTranslateMetricsWithoutGrouping() {
assumeTrue("requires snapshot builds", Build.current().isSnapshot());
assumeTrue("requires metrics command", EsqlCapabilities.Cap.METRICS_COMMAND.isEnabled());
var query = "TS k8s | STATS max(rate(network.total_bytes_in))";
var plan = logicalOptimizer.optimize(metricsAnalyzer.analyze(parser.createStatement(query, EsqlTestUtils.TEST_CFG)));
Limit limit = as(plan, Limit.class);
Expand All @@ -7310,7 +7310,7 @@ public void testTranslateMetricsWithoutGrouping() {
}

public void testTranslateMixedAggsWithoutGrouping() {
assumeTrue("requires snapshot builds", Build.current().isSnapshot());
assumeTrue("requires metrics command", EsqlCapabilities.Cap.METRICS_COMMAND.isEnabled());
var query = "TS k8s | STATS max(rate(network.total_bytes_in)), max(network.cost)";
var plan = logicalOptimizer.optimize(metricsAnalyzer.analyze(parser.createStatement(query, EsqlTestUtils.TEST_CFG)));
Limit limit = as(plan, Limit.class);
Expand All @@ -7335,7 +7335,7 @@ public void testTranslateMixedAggsWithoutGrouping() {
}

public void testTranslateMixedAggsWithMathWithoutGrouping() {
assumeTrue("requires snapshot builds", Build.current().isSnapshot());
assumeTrue("requires metrics command", EsqlCapabilities.Cap.METRICS_COMMAND.isEnabled());
var query = "TS k8s | STATS max(rate(network.total_bytes_in)), max(network.cost + 0.2) * 1.1";
var plan = logicalOptimizer.optimize(metricsAnalyzer.analyze(parser.createStatement(query, EsqlTestUtils.TEST_CFG)));
Project project = as(plan, Project.class);
Expand Down Expand Up @@ -7373,7 +7373,7 @@ public void testTranslateMixedAggsWithMathWithoutGrouping() {
}

public void testTranslateMetricsGroupedByOneDimension() {
assumeTrue("requires snapshot builds", Build.current().isSnapshot());
assumeTrue("requires metrics command", EsqlCapabilities.Cap.METRICS_COMMAND.isEnabled());
var query = "TS k8s | STATS sum(rate(network.total_bytes_in)) BY cluster | SORT cluster | LIMIT 10";
var plan = logicalOptimizer.optimize(metricsAnalyzer.analyze(parser.createStatement(query, EsqlTestUtils.TEST_CFG)));
TopN topN = as(plan, TopN.class);
Expand All @@ -7398,7 +7398,7 @@ public void testTranslateMetricsGroupedByOneDimension() {
}

public void testTranslateMetricsGroupedByTwoDimension() {
assumeTrue("requires snapshot builds", Build.current().isSnapshot());
assumeTrue("requires metrics command", EsqlCapabilities.Cap.METRICS_COMMAND.isEnabled());
var query = "TS k8s | STATS avg(rate(network.total_bytes_in)) BY cluster, pod";
var plan = logicalOptimizer.optimize(metricsAnalyzer.analyze(parser.createStatement(query, EsqlTestUtils.TEST_CFG)));
Project project = as(plan, Project.class);
Expand Down Expand Up @@ -7438,7 +7438,7 @@ public void testTranslateMetricsGroupedByTwoDimension() {
}

public void testTranslateMetricsGroupedByTimeBucket() {
assumeTrue("requires snapshot builds", Build.current().isSnapshot());
assumeTrue("requires metrics command", EsqlCapabilities.Cap.METRICS_COMMAND.isEnabled());
var query = "TS k8s | STATS sum(rate(network.total_bytes_in)) BY bucket(@timestamp, 1h)";
var plan = logicalOptimizer.optimize(metricsAnalyzer.analyze(parser.createStatement(query, EsqlTestUtils.TEST_CFG)));
Limit limit = as(plan, Limit.class);
Expand Down Expand Up @@ -7467,7 +7467,7 @@ public void testTranslateMetricsGroupedByTimeBucket() {
}

public void testTranslateMetricsGroupedByTimeBucketAndDimensions() {
assumeTrue("requires snapshot builds", Build.current().isSnapshot());
assumeTrue("requires metrics command", EsqlCapabilities.Cap.METRICS_COMMAND.isEnabled());
var query = """
TS k8s
| STATS avg(rate(network.total_bytes_in)) BY pod, bucket(@timestamp, 5 minute), cluster
Expand Down Expand Up @@ -7509,7 +7509,7 @@ public void testTranslateMetricsGroupedByTimeBucketAndDimensions() {
}

public void testTranslateSumOfTwoRates() {
assumeTrue("requires snapshot builds", Build.current().isSnapshot());
assumeTrue("requires metrics command", EsqlCapabilities.Cap.METRICS_COMMAND.isEnabled());
var query = """
TS k8s
| STATS max(rate(network.total_bytes_in) + rate(network.total_bytes_out)) BY pod, bucket(@timestamp, 5 minute), cluster
Expand All @@ -7530,7 +7530,7 @@ public void testTranslateSumOfTwoRates() {
}

public void testTranslateMixedAggsGroupedByTimeBucketAndDimensions() {
assumeTrue("requires snapshot builds", Build.current().isSnapshot());
assumeTrue("requires metrics command", EsqlCapabilities.Cap.METRICS_COMMAND.isEnabled());
var query = """
TS k8s
| STATS avg(rate(network.total_bytes_in)), avg(network.cost) BY bucket(@timestamp, 5 minute), cluster
Expand Down Expand Up @@ -7582,7 +7582,7 @@ public void testTranslateMixedAggsGroupedByTimeBucketAndDimensions() {
}

public void testAdjustMetricsRateBeforeFinalAgg() {
assumeTrue("requires snapshot builds", Build.current().isSnapshot());
assumeTrue("requires metrics command", EsqlCapabilities.Cap.METRICS_COMMAND.isEnabled());
var query = """
TS k8s
| STATS avg(round(1.05 * rate(network.total_bytes_in))) BY bucket(@timestamp, 1 minute), cluster
Expand Down Expand Up @@ -7640,7 +7640,7 @@ public void testAdjustMetricsRateBeforeFinalAgg() {
}

public void testTranslateMaxOverTime() {
assumeTrue("requires snapshot builds", Build.current().isSnapshot());
assumeTrue("requires metrics command", EsqlCapabilities.Cap.METRICS_COMMAND.isEnabled());
var query = "TS k8s | STATS sum(max_over_time(network.bytes_in)) BY bucket(@timestamp, 1h)";
var plan = logicalOptimizer.optimize(metricsAnalyzer.analyze(parser.createStatement(query, EsqlTestUtils.TEST_CFG)));
Limit limit = as(plan, Limit.class);
Expand Down Expand Up @@ -7669,7 +7669,7 @@ public void testTranslateMaxOverTime() {
}

public void testTranslateAvgOverTime() {
assumeTrue("requires snapshot builds", Build.current().isSnapshot());
assumeTrue("requires metrics command", EsqlCapabilities.Cap.METRICS_COMMAND.isEnabled());
var query = "TS k8s | STATS sum(avg_over_time(network.bytes_in)) BY bucket(@timestamp, 1h)";
var plan = logicalOptimizer.optimize(metricsAnalyzer.analyze(parser.createStatement(query, EsqlTestUtils.TEST_CFG)));
Limit limit = as(plan, Limit.class);
Expand Down Expand Up @@ -7702,7 +7702,7 @@ public void testTranslateAvgOverTime() {
}

public void testMetricsWithoutRate() {
assumeTrue("requires snapshot builds", Build.current().isSnapshot());
assumeTrue("requires metrics command", EsqlCapabilities.Cap.METRICS_COMMAND.isEnabled());
List<String> queries = List.of("""
TS k8s | STATS count(to_long(network.total_bytes_in)) BY bucket(@timestamp, 1 minute)
| LIMIT 10
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ private EsqlParser parser() {

// manually disable dev mode (make it production)
config.setDevVersion(false);
config.setMetricsCommand(false);
return parser;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2378,7 +2378,7 @@ public void testInlineConvertUnsupportedType() {
}

public void testMetricsWithoutStats() {
assumeTrue("requires snapshot build", Build.current().isSnapshot());
assumeTrue("requires metrics command", EsqlCapabilities.Cap.METRICS_COMMAND.isEnabled());

assertStatement("TS foo", unresolvedTSRelation("foo"));
assertStatement("TS foo,bar", unresolvedTSRelation("foo,bar"));
Expand All @@ -2388,7 +2388,7 @@ public void testMetricsWithoutStats() {
}

public void testMetricsIdentifiers() {
assumeTrue("requires snapshot build", Build.current().isSnapshot());
assumeTrue("requires metrics command", EsqlCapabilities.Cap.METRICS_COMMAND.isEnabled());
Map<String, String> patterns = Map.ofEntries(
Map.entry("ts foo,test-*", "foo,test-*"),
Map.entry("ts 123-test@foo_bar+baz1", "123-test@foo_bar+baz1"),
Expand All @@ -2401,7 +2401,7 @@ public void testMetricsIdentifiers() {
}

public void testSimpleMetricsWithStats() {
assumeTrue("requires snapshot build", Build.current().isSnapshot());
assumeTrue("requires metrics command", EsqlCapabilities.Cap.METRICS_COMMAND.isEnabled());
assertStatement(
"TS foo | STATS load=avg(cpu) BY ts",
new TimeSeriesAggregate(
Expand Down Expand Up @@ -2536,7 +2536,7 @@ private LogicalPlan unresolvedTSRelation(String index) {
}

public void testMetricWithGroupKeyAsAgg() {
assumeTrue("requires snapshot build", Build.current().isSnapshot());
assumeTrue("requires metrics command", EsqlCapabilities.Cap.METRICS_COMMAND.isEnabled());
var queries = List.of("TS foo | STATS a BY a");
for (String query : queries) {
expectVerificationError(query, "grouping key [a] already specified in the STATS BY clause");
Expand Down Expand Up @@ -3153,7 +3153,7 @@ public void testValidJoinPattern() {
}

public void testInvalidFromPatterns() {
var sourceCommands = Build.current().isSnapshot() ? new String[] { "FROM", "TS" } : new String[] { "FROM" };
var sourceCommands = EsqlCapabilities.Cap.METRICS_COMMAND.isEnabled() ? new String[] { "FROM", "TS" } : new String[] { "FROM" };
var indexIsBlank = "Blank index specified in index pattern";
var remoteIsEmpty = "remote part is empty";
var invalidDoubleColonUsage = "invalid usage of :: separator";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

package org.elasticsearch.xpack.esql.session;

import org.elasticsearch.Build;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.xpack.esql.EsqlTestUtils;
import org.elasticsearch.xpack.esql.action.EsqlCapabilities;
Expand Down Expand Up @@ -1607,7 +1606,7 @@ public void testEnrichOnDefaultField() {

public void testMetrics() {
var query = "TS k8s | STATS bytes=sum(rate(network.total_bytes_in)), sum(rate(network.total_cost)) BY cluster";
if (Build.current().isSnapshot() == false) {
if (EsqlCapabilities.Cap.METRICS_COMMAND.isEnabled() == false) {
var e = expectThrows(ParsingException.class, () -> parser.createStatement(query, EsqlTestUtils.TEST_CFG));
assertThat(e.getMessage(), containsString("line 1:1: mismatched input 'TS' expecting {"));
return;
Expand Down