-
Notifications
You must be signed in to change notification settings - Fork 25.4k
ESQL: Log profile on test error #131474
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
ESQL: Log profile on test error #131474
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
8ccae75
ESQL: Log profile on test error
ivancea 221253c
[CI] Auto commit changes from spotless
53a5eb2
Reorganized class
ivancea 4fe71c9
Remove old code
ivancea 632cd91
Pass ProfileLogger as a parameter
ivancea 0eae933
Add profile logging to non-csv tests
ivancea b284c41
Removed overloads without ProfileLogger, and implemented it on other …
ivancea 1875cd9
Reuse Mode enum
ivancea 15a2b82
Fixes
ivancea bbf63d0
Fixed tests imports
ivancea a459940
Merge branch 'main' into show-profile-on-test-error
ivancea 2020c36
Merge branch 'main' into show-profile-on-test-error
ivancea 16a425e
Merge branch 'main' into show-profile-on-test-error
ivancea 5cb6845
Fixed PageMappingToIteratorStatus deserialization
ivancea f02f5ae
Added capability to avoid testing profile on older versions
ivancea a1405dd
Merge branch 'main' into show-profile-on-test-error
ivancea 95e1344
Fixed Generative tests after merge
ivancea 969a3ff
Merge branch 'main' into show-profile-on-test-error
ivancea fdacb05
Merge branch 'main' into show-profile-on-test-error
ivancea File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -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; | ||
|
@@ -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"); | ||
|
@@ -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); | ||
|
||
|
@@ -302,14 +304,6 @@ protected final void doTest(String query) throws Throwable { | |
} | ||
} | ||
|
||
static Map<String, Object> assertNotPartial(Map<String, Object> answer) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(); | ||
|
@@ -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, | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -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( | ||
|
@@ -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 | ||
// ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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"))) | ||
|
@@ -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(); | ||
|
59 changes: 59 additions & 0 deletions
59
...ugin/esql/qa/server/src/main/java/org/elasticsearch/xpack/esql/qa/rest/ProfileLogger.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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