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 @@ -202,7 +202,7 @@ public static class Status implements Operator.Status {
public static final NamedWriteableRegistry.Entry ENTRY = new NamedWriteableRegistry.Entry(
Operator.Status.class,
"page_mapping_to_iterator",
AbstractPageMappingOperator.Status::new
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was another serialization error

Status::new
);

private final long processNanos;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.elasticsearch.test.rest.TestFeatureService;
import org.elasticsearch.xpack.esql.CsvSpecReader.CsvTestCase;
import org.elasticsearch.xpack.esql.qa.rest.EsqlSpecTestCase;
import org.elasticsearch.xpack.esql.qa.rest.RestEsqlTestCase.Mode;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.ClassRule;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.elasticsearch.xpack.esql.CsvTestsDataLoader;
import org.elasticsearch.xpack.esql.SpecReader;
import org.elasticsearch.xpack.esql.qa.rest.EsqlSpecTestCase;
import org.elasticsearch.xpack.esql.qa.rest.RestEsqlTestCase.Mode;
import org.junit.AfterClass;
import org.junit.ClassRule;
import org.junit.rules.RuleChain;
Expand Down Expand Up @@ -58,7 +59,7 @@
import static org.elasticsearch.xpack.esql.action.EsqlCapabilities.Cap.JOIN_PLANNING_V1;
import static org.elasticsearch.xpack.esql.action.EsqlCapabilities.Cap.METADATA_FIELDS_REMOTE_TEST;
import static org.elasticsearch.xpack.esql.action.EsqlCapabilities.Cap.UNMAPPED_FIELDS;
import static org.elasticsearch.xpack.esql.qa.rest.EsqlSpecTestCase.Mode.SYNC;
import static org.elasticsearch.xpack.esql.qa.rest.RestEsqlTestCase.Mode.SYNC;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@
import org.elasticsearch.test.cluster.ElasticsearchCluster;
import org.elasticsearch.test.rest.ESRestTestCase;
import org.elasticsearch.test.rest.TestFeatureService;
import org.elasticsearch.xpack.esql.AssertWarnings;
import org.elasticsearch.xpack.esql.qa.rest.ProfileLogger;
import org.elasticsearch.xpack.esql.qa.rest.RestEsqlTestCase;
import org.junit.After;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.rules.RuleChain;
import org.junit.rules.TestRule;

Expand Down Expand Up @@ -57,6 +60,9 @@ public class MultiClustersIT extends ESRestTestCase {
@ClassRule
public static TestRule clusterRule = RuleChain.outerRule(remoteCluster).around(localCluster);

@Rule(order = Integer.MIN_VALUE)
public ProfileLogger profileLogger = new ProfileLogger();

private static TestFeatureService remoteFeaturesService;

@Override
Expand Down Expand Up @@ -199,9 +205,9 @@ protected boolean supportsAsync() {

private Map<String, Object> runEsql(RestEsqlTestCase.RequestObjectBuilder requestObject) throws IOException {
if (supportsAsync()) {
return RestEsqlTestCase.runEsqlAsync(requestObject);
return RestEsqlTestCase.runEsqlAsync(requestObject, new AssertWarnings.NoWarnings(), profileLogger);
} else {
return RestEsqlTestCase.runEsqlSync(requestObject);
return RestEsqlTestCase.runEsqlSync(requestObject, new AssertWarnings.NoWarnings(), profileLogger);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.elasticsearch.test.cluster.ElasticsearchCluster;
import org.elasticsearch.xpack.esql.CsvSpecReader.CsvTestCase;
import org.elasticsearch.xpack.esql.qa.rest.EsqlSpecTestCase;
import org.elasticsearch.xpack.esql.qa.rest.RestEsqlTestCase.Mode;
import org.junit.ClassRule;

import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.elasticsearch.xpack.esql.planner.PhysicalSettings;
import org.elasticsearch.xpack.esql.plugin.ComputeService;
import org.elasticsearch.xpack.esql.qa.rest.EsqlSpecTestCase;
import org.elasticsearch.xpack.esql.qa.rest.RestEsqlTestCase.Mode;
import org.junit.Before;
import org.junit.ClassRule;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.elasticsearch.test.TestClustersThreadFilter;
import org.elasticsearch.test.cluster.ElasticsearchCluster;
import org.elasticsearch.xpack.esql.CsvSpecReader;
import org.elasticsearch.xpack.esql.qa.rest.RestEsqlTestCase.Mode;
import org.elasticsearch.xpack.esql.qa.rest.generative.GenerativeForkRestTest;
import org.junit.ClassRule;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@
import org.elasticsearch.test.rest.ESRestTestCase;
import org.elasticsearch.xcontent.XContentType;
import org.elasticsearch.xpack.esql.AssertWarnings;
import org.elasticsearch.xpack.esql.qa.rest.ProfileLogger;
import org.elasticsearch.xpack.esql.qa.rest.RestEsqlTestCase;
import org.hamcrest.Matcher;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Rule;

import java.io.IOException;
import java.util.ArrayList;
Expand Down Expand Up @@ -55,6 +57,9 @@ public class PushQueriesIT extends ESRestTestCase {
@ClassRule
public static ElasticsearchCluster cluster = Clusters.testCluster(spec -> spec.plugin("inference-service-test"));

@Rule(order = Integer.MIN_VALUE)
public ProfileLogger profileLogger = new ProfileLogger();

@ParametersFactory(argumentFormatting = "%1s")
public static List<Object[]> args() {
return Arrays.stream(Type.values()).map(s -> new Object[] { s }).toList();
Expand Down Expand Up @@ -348,7 +353,7 @@ private void testPushQuery(
String replacedQuery = esqlQuery.replaceAll("%value", value).replaceAll("%different_value", differentValue);
RestEsqlTestCase.RequestObjectBuilder builder = requestObjectBuilder().query(replacedQuery + "\n| KEEP test");
builder.profile(true);
Map<String, Object> result = runEsql(builder, new AssertWarnings.NoWarnings(), RestEsqlTestCase.Mode.SYNC);
Map<String, Object> result = runEsql(builder, new AssertWarnings.NoWarnings(), profileLogger, RestEsqlTestCase.Mode.SYNC);
assertResultMap(
result,
getResultMatcher(result).entry(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.elasticsearch.test.TestClustersThreadFilter;
import org.elasticsearch.test.cluster.ElasticsearchCluster;
import org.elasticsearch.xpack.esql.qa.rest.RestEnrichTestCase;
import org.elasticsearch.xpack.esql.qa.rest.RestEsqlTestCase.Mode;
import org.junit.ClassRule;

@ThreadLeakFilters(filters = TestClustersThreadFilter.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@
import org.elasticsearch.test.rest.ESRestTestCase;
import org.elasticsearch.xcontent.XContentType;
import org.elasticsearch.xpack.esql.AssertWarnings;
import org.elasticsearch.xpack.esql.qa.rest.ProfileLogger;
import org.elasticsearch.xpack.esql.qa.rest.RestEsqlTestCase;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Rule;

import java.io.IOException;
import java.util.List;
Expand Down Expand Up @@ -52,6 +54,9 @@ public class StoredFieldsSequentialIT extends ESRestTestCase {
@ClassRule
public static ElasticsearchCluster cluster = Clusters.testCluster();

@Rule(order = Integer.MIN_VALUE)
public ProfileLogger profileLogger = new ProfileLogger();

public void testFetchTen() throws IOException {
testQuery(null, """
FROM test
Expand Down Expand Up @@ -106,7 +111,7 @@ private void testQuery(Double percent, String query, int documentsFound, boolean
setPercent(percent);
RestEsqlTestCase.RequestObjectBuilder builder = requestObjectBuilder().query(query);
builder.profile(true);
Map<String, Object> result = runEsql(builder, new AssertWarnings.NoWarnings(), RestEsqlTestCase.Mode.SYNC);
Map<String, Object> result = runEsql(builder, new AssertWarnings.NoWarnings(), profileLogger, RestEsqlTestCase.Mode.SYNC);
assertMap(
result,
matchesMap().entry("documents_found", documentsFound)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@
import org.elasticsearch.test.TestClustersThreadFilter;
import org.elasticsearch.test.cluster.ElasticsearchCluster;
import org.elasticsearch.test.rest.ESRestTestCase;
import org.elasticsearch.xpack.esql.AssertWarnings;
import org.elasticsearch.xpack.esql.CsvTestsDataLoader;
import org.elasticsearch.xpack.esql.qa.rest.ProfileLogger;
import org.elasticsearch.xpack.esql.qa.rest.RestEsqlTestCase;
import org.junit.ClassRule;
import org.junit.Rule;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
Expand All @@ -36,6 +39,9 @@ public class TSDBRestEsqlIT extends ESRestTestCase {
@ClassRule
public static ElasticsearchCluster cluster = Clusters.testCluster();

@Rule(order = Integer.MIN_VALUE)
public ProfileLogger profileLogger = new ProfileLogger();

@Override
protected String getTestRestCluster() {
return cluster.getHttpAddresses();
Expand Down Expand Up @@ -64,7 +70,7 @@ public void testTimeSeriesQuerying() throws IOException {
RestEsqlTestCase.RequestObjectBuilder builder = RestEsqlTestCase.requestObjectBuilder()
.query("FROM k8s | KEEP k8s.pod.name, @timestamp | SORT @timestamp, k8s.pod.name");
builder.pragmas(Settings.builder().put("time_series", true).build());
Map<String, Object> result = runEsqlSync(builder);
Map<String, Object> result = runEsqlSync(builder, new AssertWarnings.NoWarnings(), profileLogger);
@SuppressWarnings("unchecked")
List<Map<?, ?>> columns = (List<Map<?, ?>>) result.get("columns");
assertEquals(2, columns.size());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,18 @@
import org.elasticsearch.test.rest.ESRestTestCase;
import org.elasticsearch.test.rest.TestFeatureService;
import org.elasticsearch.xcontent.XContentType;
import org.elasticsearch.xpack.esql.AssertWarnings;
import org.elasticsearch.xpack.esql.CsvSpecReader.CsvTestCase;
import org.elasticsearch.xpack.esql.CsvTestUtils;
import org.elasticsearch.xpack.esql.EsqlTestUtils;
import org.elasticsearch.xpack.esql.SpecReader;
import org.elasticsearch.xpack.esql.plugin.EsqlFeatures;
import org.elasticsearch.xpack.esql.qa.rest.RestEsqlTestCase.Mode;
import org.elasticsearch.xpack.esql.qa.rest.RestEsqlTestCase.RequestObjectBuilder;
import org.elasticsearch.xpack.esql.telemetry.TookMetrics;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Rule;

import java.io.IOException;
import java.math.BigDecimal;
Expand Down Expand Up @@ -77,14 +78,15 @@
import static org.elasticsearch.xpack.esql.action.EsqlCapabilities.Cap.RERANK;
import static org.elasticsearch.xpack.esql.action.EsqlCapabilities.Cap.SEMANTIC_TEXT_FIELD_CAPS;
import static org.elasticsearch.xpack.esql.action.EsqlCapabilities.Cap.SOURCE_FIELD_MAPPING;
import static org.hamcrest.Matchers.anyOf;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;
import static org.elasticsearch.xpack.esql.qa.rest.RestEsqlTestCase.assertNotPartial;

// This test can run very long in serverless configurations
@TimeoutSuite(millis = 30 * TimeUnits.MINUTE)
public abstract class EsqlSpecTestCase extends ESRestTestCase {

@Rule(order = Integer.MIN_VALUE)
public ProfileLogger profileLogger = new ProfileLogger();

private static final Logger LOGGER = LogManager.getLogger(EsqlSpecTestCase.class);
private final String fileName;
private final String groupName;
Expand All @@ -95,11 +97,6 @@ public abstract class EsqlSpecTestCase extends ESRestTestCase {
protected final Mode mode;
protected static Boolean supportsTook;

public enum Mode {
SYNC,
ASYNC
}

@ParametersFactory(argumentFormatting = "%2$s.%3$s %7$s")
public static List<Object[]> readScriptSpec() throws Exception {
List<URL> urls = classpathResources("/*.csv-spec");
Expand Down Expand Up @@ -275,7 +272,12 @@ protected final void doTest(String query) throws Throwable {
}

Map<?, ?> prevTooks = supportsTook() ? tooks() : null;
Map<String, Object> answer = runEsql(builder.query(query), testCase.assertWarnings(deduplicateExactWarnings()));
Map<String, Object> answer = RestEsqlTestCase.runEsql(
builder.query(query),
testCase.assertWarnings(deduplicateExactWarnings()),
profileLogger,
mode
);

assertNotPartial(answer);

Expand All @@ -302,14 +304,6 @@ protected final void doTest(String query) throws Throwable {
}
}

static Map<String, Object> assertNotPartial(Map<String, Object> answer) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved this to the other class, with runEsql and assertWarnings

var clusters = answer.get("_clusters");
var reason = "unexpected partial results" + (clusters != null ? ": _clusters=" + clusters : "");
assertThat(reason, answer.get("is_partial"), anyOf(nullValue(), is(false)));

return answer;
}

private Map<?, ?> tooks() throws IOException {
Request request = new Request("GET", "/_xpack/usage");
HttpEntity entity = client().performRequest(request).getEntity();
Expand All @@ -336,14 +330,6 @@ protected boolean deduplicateExactWarnings() {
return false;
}

private Map<String, Object> runEsql(RequestObjectBuilder requestObject, AssertWarnings assertWarnings) throws IOException {
if (mode == Mode.ASYNC) {
return RestEsqlTestCase.runEsqlAsync(requestObject, assertWarnings);
} else {
return RestEsqlTestCase.runEsqlSync(requestObject, assertWarnings);
}
}

protected void assertResults(
ExpectedResults expected,
List<Map<String, String>> actualColumns,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@
import org.elasticsearch.xcontent.XContentBuilder;
import org.elasticsearch.xcontent.XContentType;
import org.elasticsearch.xcontent.json.JsonXContent;
import org.elasticsearch.xpack.esql.AssertWarnings;
import org.elasticsearch.xpack.esql.action.EsqlCapabilities;
import org.elasticsearch.xpack.esql.core.type.DataType;
import org.elasticsearch.xpack.esql.plugin.QueryPragmas;
import org.hamcrest.Matcher;
import org.junit.Rule;

import java.io.IOException;
import java.math.BigDecimal;
Expand Down Expand Up @@ -68,6 +70,9 @@
public abstract class FieldExtractorTestCase extends ESRestTestCase {
private static final Logger logger = LogManager.getLogger(FieldExtractorTestCase.class);

@Rule(order = Integer.MIN_VALUE)
public ProfileLogger profileLogger = new ProfileLogger();

@ParametersFactory(argumentFormatting = "%s")
public static List<Object[]> args() throws Exception {
return List.of(
Expand Down Expand Up @@ -336,7 +341,11 @@ public void testEmptyMapping() throws IOException {
assertThat(err, containsString("Unknown column [missing]"));

// TODO this is broken in main too
// Map<String, Object> result = runEsqlSync(new RestEsqlTestCase.RequestObjectBuilder().query("FROM test* | LIMIT 2"));
// Map<String, Object> result = runEsqlSync(
// new RestEsqlTestCase.RequestObjectBuilder().query("FROM test* | LIMIT 2"),
// new AssertWarnings.NoWarnings(),
// profileLogger
// );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh boy. I think maybe I should look at this one. I wrote this like two years ago.

// assertResultMap(
// result,
// matchesMap().entry("columns", List.of(columnInfo("f", "unsupported"), columnInfo("f.raw", "unsupported")))
Expand Down Expand Up @@ -1777,7 +1786,7 @@ private Map<String, Object> runEsql(String query) throws IOException {
);
request.pragmasOk();
}
return runEsqlSync(request);
return runEsqlSync(request, new AssertWarnings.NoWarnings(), profileLogger);
}

protected abstract void canUsePragmasOk();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

package org.elasticsearch.xpack.esql.qa.rest;

import org.elasticsearch.logging.LogManager;
import org.elasticsearch.logging.Logger;
import org.junit.rules.TestWatcher;
import org.junit.runner.Description;

import java.util.Map;

/**
* A JUnit rule that logs the profile information from an ESQL response if the test fails.
* <p>
* Usage:
* </p>
* <pre>
* {@code
* @Rule(order = Integer.MIN_VALUE)
* public ProfileLogger profileLogger = new ProfileLogger();
*
* public void test() {
* var response = RestEsqlTestCase.runEsql(requestObject, assertWarnings, profileLogger, mode);
* // Or any of the other runEsql methods
* }
* }
* </pre>
*/
public class ProfileLogger extends TestWatcher {
private static final Logger LOGGER = LogManager.getLogger(ProfileLogger.class);

private Object profile;

public void extractProfile(Map<String, Object> jsonResponse, Boolean originalProfileParameter) {
if (jsonResponse.containsKey("profile") == false) {
return;
}

profile = jsonResponse.get("profile");

if (Boolean.TRUE.equals(originalProfileParameter) == false) {
jsonResponse.remove("profile");
}
}

public void clearProfile() {
profile = null;
}

@Override
protected void failed(Throwable e, Description description) {
LOGGER.info("Profile: {}", profile);
}
}
Loading