Skip to content

Commit

Permalink
iter
Browse files Browse the repository at this point in the history
  • Loading branch information
piergm committed Dec 9, 2024
1 parent cfd3113 commit ecdd47c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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() {
Expand Down Expand Up @@ -60,7 +62,6 @@ private void setupIndexWithDocs() {

public void testSearchFailingQueryErrorTraceDefault() throws IOException {
hasStackTrace = new AtomicBoolean();
setupMessageListener();
setupIndexWithDocs();

Request searchRequest = new Request("POST", "/_search");
Expand All @@ -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");
Expand All @@ -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");
Expand All @@ -122,7 +121,6 @@ public void testSearchFailingQueryErrorTraceFalse() throws IOException {

public void testMultiSearchFailingQueryErrorTraceDefault() throws IOException {
hasStackTrace = new AtomicBoolean();
setupMessageListener();
setupIndexWithDocs();

XContentType contentType = XContentType.JSON;
Expand All @@ -140,7 +138,6 @@ public void testMultiSearchFailingQueryErrorTraceDefault() throws IOException {

public void testMultiSearchFailingQueryErrorTraceTrue() throws IOException {
hasStackTrace = new AtomicBoolean();
setupMessageListener();
setupIndexWithDocs();

XContentType contentType = XContentType.JSON;
Expand All @@ -159,7 +156,6 @@ public void testMultiSearchFailingQueryErrorTraceTrue() throws IOException {

public void testMultiSearchFailingQueryErrorTraceFalse() throws IOException {
hasStackTrace = new AtomicBoolean();
setupMessageListener();
setupIndexWithDocs();

XContentType contentType = XContentType.JSON;
Expand All @@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -509,10 +510,8 @@ private <T> ActionListener<T> maybeWrapListenerForStackTrace(ActionListener<T> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -34,6 +35,7 @@ protected Collection<Class<? extends Plugin>> nodePlugins() {

private AtomicBoolean hasStackTrace;

@Before
private void setupMessageListener() {
internalCluster().getDataNodeInstances(TransportService.class).forEach(ts -> {
ts.addMessageListener(new TransportMessageListener() {
Expand Down Expand Up @@ -64,7 +66,6 @@ private void setupIndexWithDocs() {

public void testAsyncSearchFailingQueryErrorTraceDefault() throws IOException {
hasStackTrace = new AtomicBoolean();
setupMessageListener();
setupIndexWithDocs();

Request searchRequest = new Request("POST", "/_async_search");
Expand All @@ -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");
Expand All @@ -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");
Expand Down

0 comments on commit ecdd47c

Please sign in to comment.