diff --git a/qa/smoke-test-http/src/javaRestTest/java/org/elasticsearch/http/ErrorTraceIT.java b/qa/smoke-test-http/src/javaRestTest/java/org/elasticsearch/http/SearchErrorTraceIT.java similarity index 75% rename from qa/smoke-test-http/src/javaRestTest/java/org/elasticsearch/http/ErrorTraceIT.java rename to qa/smoke-test-http/src/javaRestTest/java/org/elasticsearch/http/SearchErrorTraceIT.java index 64efa77fffa37..6f9ab8ccdfdec 100644 --- a/qa/smoke-test-http/src/javaRestTest/java/org/elasticsearch/http/ErrorTraceIT.java +++ b/qa/smoke-test-http/src/javaRestTest/java/org/elasticsearch/http/SearchErrorTraceIT.java @@ -19,6 +19,7 @@ import org.elasticsearch.transport.TransportMessageListener; import org.elasticsearch.transport.TransportService; import org.elasticsearch.xcontent.XContentType; +import org.junit.Before; import java.io.IOException; import java.nio.charset.Charset; @@ -27,9 +28,10 @@ import static org.elasticsearch.index.query.QueryBuilders.simpleQueryStringQuery; -public class ErrorTraceIT extends HttpSmokeTestCase { +public class SearchErrorTraceIT extends HttpSmokeTestCase { private AtomicBoolean hasStackTrace; + @Before private void setupMessageListener() { internalCluster().getDataNodeInstances(TransportService.class).forEach(ts -> { ts.addMessageListener(new TransportMessageListener() { @@ -60,7 +62,6 @@ private void setupIndexWithDocs() { public void testSearchFailingQueryErrorTraceDefault() throws IOException { hasStackTrace = new AtomicBoolean(); - setupMessageListener(); setupIndexWithDocs(); Request searchRequest = new Request("POST", "/_search"); @@ -80,7 +81,6 @@ public void testSearchFailingQueryErrorTraceDefault() throws IOException { public void testSearchFailingQueryErrorTraceTrue() throws IOException { hasStackTrace = new AtomicBoolean(); - setupMessageListener(); setupIndexWithDocs(); Request searchRequest = new Request("POST", "/_search"); @@ -101,7 +101,6 @@ public void testSearchFailingQueryErrorTraceTrue() throws IOException { public void testSearchFailingQueryErrorTraceFalse() throws IOException { hasStackTrace = new AtomicBoolean(); - setupMessageListener(); setupIndexWithDocs(); Request searchRequest = new Request("POST", "/_search"); @@ -122,7 +121,6 @@ public void testSearchFailingQueryErrorTraceFalse() throws IOException { public void testMultiSearchFailingQueryErrorTraceDefault() throws IOException { hasStackTrace = new AtomicBoolean(); - setupMessageListener(); setupIndexWithDocs(); XContentType contentType = XContentType.JSON; @@ -140,7 +138,6 @@ public void testMultiSearchFailingQueryErrorTraceDefault() throws IOException { public void testMultiSearchFailingQueryErrorTraceTrue() throws IOException { hasStackTrace = new AtomicBoolean(); - setupMessageListener(); setupIndexWithDocs(); XContentType contentType = XContentType.JSON; @@ -159,7 +156,6 @@ public void testMultiSearchFailingQueryErrorTraceTrue() throws IOException { public void testMultiSearchFailingQueryErrorTraceFalse() throws IOException { hasStackTrace = new AtomicBoolean(); - setupMessageListener(); setupIndexWithDocs(); XContentType contentType = XContentType.JSON; @@ -176,66 +172,4 @@ public void testMultiSearchFailingQueryErrorTraceFalse() throws IOException { assertFalse(hasStackTrace.get()); } - - public void testAsyncSearchFailingQueryErrorTraceDefault() throws IOException { - hasStackTrace = new AtomicBoolean(); - setupMessageListener(); - setupIndexWithDocs(); - - Request searchRequest = new Request("POST", "/_async_search"); - searchRequest.setJsonEntity(""" - { - "query": { - "simple_query_string" : { - "query": "foo", - "fields": ["field"] - } - } - } - """); - getRestClient().performRequest(searchRequest); - assertFalse(hasStackTrace.get()); - } - - public void testAsyncSearchFailingQueryErrorTraceTrue() throws IOException { - hasStackTrace = new AtomicBoolean(); - setupMessageListener(); - setupIndexWithDocs(); - - Request searchRequest = new Request("POST", "/_async_search"); - searchRequest.setJsonEntity(""" - { - "query": { - "simple_query_string" : { - "query": "foo", - "fields": ["field"] - } - } - } - """); - searchRequest.addParameter("error_trace", "true"); - getRestClient().performRequest(searchRequest); - assertTrue(hasStackTrace.get()); - } - - public void testAsyncSearchFailingQueryErrorTraceFalse() throws IOException { - hasStackTrace = new AtomicBoolean(); - setupMessageListener(); - setupIndexWithDocs(); - - Request searchRequest = new Request("POST", "/_async_search"); - searchRequest.setJsonEntity(""" - { - "query": { - "simple_query_string" : { - "query": "foo", - "fields": ["field"] - } - } - } - """); - searchRequest.addParameter("error_trace", "false"); - getRestClient().performRequest(searchRequest); - assertFalse(hasStackTrace.get()); - } } diff --git a/server/src/main/java/org/elasticsearch/search/SearchService.java b/server/src/main/java/org/elasticsearch/search/SearchService.java index 88a13f8a164d3..d040ed558ce5f 100644 --- a/server/src/main/java/org/elasticsearch/search/SearchService.java +++ b/server/src/main/java/org/elasticsearch/search/SearchService.java @@ -270,6 +270,7 @@ public class SearchService extends AbstractLifecycleComponent implements IndexEv public static final int DEFAULT_SIZE = 10; public static final int DEFAULT_FROM = 0; + private static final StackTraceElement[] EMPTY_STACK_TRACE_ARRAY = new StackTraceElement[0]; private final ThreadPool threadPool; @@ -509,10 +510,8 @@ private ActionListener maybeWrapListenerForStackTrace(ActionListener l String header = threadPool.getThreadContext().getHeaderOrDefault("error_trace", "true"); if (header.equals("false")) { return listener.delegateResponse((l, e) -> { - // e.setStackTrace(new StackTraceElement[0]); - // e.getCause().setStackTrace(new StackTraceElement[0]); ExceptionsHelper.unwrapCausesAndSuppressed(e, err -> { - err.setStackTrace(new StackTraceElement[0]); // use constant + err.setStackTrace(EMPTY_STACK_TRACE_ARRAY); return false; }); l.onFailure(e); diff --git a/x-pack/plugin/async-search/src/internalClusterTest/java/org/elasticsearch/xpack/search/AsyncSearchErrorTraceIT.java b/x-pack/plugin/async-search/src/internalClusterTest/java/org/elasticsearch/xpack/search/AsyncSearchErrorTraceIT.java index 39c9eb8d42d6a..06fc7de8ecc2c 100644 --- a/x-pack/plugin/async-search/src/internalClusterTest/java/org/elasticsearch/xpack/search/AsyncSearchErrorTraceIT.java +++ b/x-pack/plugin/async-search/src/internalClusterTest/java/org/elasticsearch/xpack/search/AsyncSearchErrorTraceIT.java @@ -13,6 +13,7 @@ import org.elasticsearch.test.ESIntegTestCase; import org.elasticsearch.transport.TransportMessageListener; import org.elasticsearch.transport.TransportService; +import org.junit.Before; import java.io.IOException; import java.util.Collection; @@ -34,6 +35,7 @@ protected Collection> nodePlugins() { private AtomicBoolean hasStackTrace; + @Before private void setupMessageListener() { internalCluster().getDataNodeInstances(TransportService.class).forEach(ts -> { ts.addMessageListener(new TransportMessageListener() { @@ -64,7 +66,6 @@ private void setupIndexWithDocs() { public void testAsyncSearchFailingQueryErrorTraceDefault() throws IOException { hasStackTrace = new AtomicBoolean(); - setupMessageListener(); setupIndexWithDocs(); Request searchRequest = new Request("POST", "/_async_search"); @@ -84,7 +85,6 @@ public void testAsyncSearchFailingQueryErrorTraceDefault() throws IOException { public void testAsyncSearchFailingQueryErrorTraceTrue() throws IOException { hasStackTrace = new AtomicBoolean(); - setupMessageListener(); setupIndexWithDocs(); Request searchRequest = new Request("POST", "/_async_search"); @@ -105,7 +105,6 @@ public void testAsyncSearchFailingQueryErrorTraceTrue() throws IOException { public void testAsyncSearchFailingQueryErrorTraceFalse() throws IOException { hasStackTrace = new AtomicBoolean(); - setupMessageListener(); setupIndexWithDocs(); Request searchRequest = new Request("POST", "/_async_search");