Skip to content

Commit 502a327

Browse files
committed
Add guard logging and enable debug log levels for test suite
1 parent 4c4e49b commit 502a327

File tree

7 files changed

+52
-0
lines changed

7 files changed

+52
-0
lines changed

x-pack/plugin/async-search/src/internalClusterTest/java/org/elasticsearch/xpack/search/AsyncSearchActionIT.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.elasticsearch.search.query.ThrowingQueryBuilder;
2828
import org.elasticsearch.test.ESIntegTestCase.SuiteScopeTestCase;
2929
import org.elasticsearch.test.TransportVersionUtils;
30+
import org.elasticsearch.test.junit.annotations.TestLogging;
3031
import org.elasticsearch.xpack.core.XPackPlugin;
3132
import org.elasticsearch.xpack.core.search.action.AsyncSearchResponse;
3233
import org.elasticsearch.xpack.core.search.action.AsyncStatusResponse;
@@ -51,6 +52,10 @@
5152
import static org.hamcrest.Matchers.lessThan;
5253
import static org.hamcrest.Matchers.lessThanOrEqualTo;
5354

55+
@TestLogging(
56+
reason = "testing debug log output to identify race condition",
57+
value = "org.elasticsearch.xpack.search.MutableSearchResponse:DEBUG,org.elasticsearch.xpack.search.AsyncSearchTask:DEBUG"
58+
)
5459
@SuiteScopeTestCase
5560
public class AsyncSearchActionIT extends AsyncSearchIntegTestCase {
5661
private static String indexName;

x-pack/plugin/async-search/src/internalClusterTest/java/org/elasticsearch/xpack/search/AsyncSearchErrorTraceIT.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.elasticsearch.search.SearchService;
2020
import org.elasticsearch.test.ESIntegTestCase;
2121
import org.elasticsearch.test.MockLog;
22+
import org.elasticsearch.test.junit.annotations.TestLogging;
2223
import org.elasticsearch.test.transport.MockTransportService;
2324
import org.elasticsearch.xcontent.XContentType;
2425
import org.junit.After;
@@ -30,6 +31,10 @@
3031
import java.util.Map;
3132
import java.util.function.BooleanSupplier;
3233

34+
@TestLogging(
35+
reason = "testing debug log output to identify race condition",
36+
value = "org.elasticsearch.xpack.search.MutableSearchResponse:DEBUG,org.elasticsearch.xpack.search.AsyncSearchTask:DEBUG"
37+
)
3338
public class AsyncSearchErrorTraceIT extends ESIntegTestCase {
3439
private BooleanSupplier transportMessageHasStackTrace;
3540

x-pack/plugin/async-search/src/internalClusterTest/java/org/elasticsearch/xpack/search/CCSUsageTelemetryAsyncSearchIT.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.elasticsearch.tasks.TaskInfo;
2323
import org.elasticsearch.test.AbstractMultiClustersTestCase;
2424
import org.elasticsearch.test.InternalTestCluster;
25+
import org.elasticsearch.test.junit.annotations.TestLogging;
2526
import org.elasticsearch.transport.TransportService;
2627
import org.elasticsearch.usage.UsageService;
2728
import org.elasticsearch.xpack.async.AsyncResultsIndexPlugin;
@@ -50,6 +51,10 @@
5051
import static org.hamcrest.Matchers.equalTo;
5152
import static org.hamcrest.Matchers.greaterThan;
5253

54+
@TestLogging(
55+
reason = "testing debug log output to identify race condition",
56+
value = "org.elasticsearch.xpack.search.MutableSearchResponse:DEBUG,org.elasticsearch.xpack.search.AsyncSearchTask:DEBUG"
57+
)
5358
public class CCSUsageTelemetryAsyncSearchIT extends AbstractMultiClustersTestCase {
5459
private static final String REMOTE1 = "cluster-a";
5560
private static final String REMOTE2 = "cluster-b";

x-pack/plugin/async-search/src/internalClusterTest/java/org/elasticsearch/xpack/search/CrossClusterAsyncSearchIT.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import org.elasticsearch.tasks.TaskInfo;
4545
import org.elasticsearch.test.AbstractMultiClustersTestCase;
4646
import org.elasticsearch.test.InternalTestCluster;
47+
import org.elasticsearch.test.junit.annotations.TestLogging;
4748
import org.elasticsearch.transport.RemoteClusterAware;
4849
import org.elasticsearch.transport.TransportService;
4950
import org.elasticsearch.xcontent.ToXContent;
@@ -82,6 +83,10 @@
8283
import static org.hamcrest.Matchers.matchesRegex;
8384
import static org.hamcrest.Matchers.not;
8485

86+
@TestLogging(
87+
reason = "testing debug log output to identify race condition",
88+
value = "org.elasticsearch.xpack.search.MutableSearchResponse:DEBUG,org.elasticsearch.xpack.search.AsyncSearchTask:DEBUG"
89+
)
8590
public class CrossClusterAsyncSearchIT extends AbstractMultiClustersTestCase {
8691

8792
private static final String REMOTE_CLUSTER = "cluster_a";

x-pack/plugin/async-search/src/internalClusterTest/java/org/elasticsearch/xpack/search/SearchUsageStatsIT.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,16 @@
1616
import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder;
1717
import org.elasticsearch.search.builder.SearchSourceBuilder;
1818
import org.elasticsearch.test.ESIntegTestCase;
19+
import org.elasticsearch.test.junit.annotations.TestLogging;
1920

2021
import java.io.IOException;
2122
import java.util.Collection;
2223
import java.util.List;
2324

25+
@TestLogging(
26+
reason = "testing debug log output to identify race condition",
27+
value = "org.elasticsearch.xpack.search.MutableSearchResponse:DEBUG,org.elasticsearch.xpack.search.AsyncSearchTask:DEBUG"
28+
)
2429
@ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.TEST, numDataNodes = 1)
2530
public class SearchUsageStatsIT extends ESIntegTestCase {
2631

x-pack/plugin/async-search/src/main/java/org/elasticsearch/xpack/search/AsyncSearchTask.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77
package org.elasticsearch.xpack.search;
88

9+
import org.apache.logging.log4j.Logger;
910
import org.apache.lucene.search.TotalHits;
1011
import org.elasticsearch.ElasticsearchException;
1112
import org.elasticsearch.ElasticsearchStatusException;
@@ -23,6 +24,7 @@
2324
import org.elasticsearch.action.search.ShardSearchFailure;
2425
import org.elasticsearch.action.search.TransportSearchAction;
2526
import org.elasticsearch.client.internal.Client;
27+
import org.elasticsearch.common.logging.Loggers;
2628
import org.elasticsearch.core.Releasable;
2729
import org.elasticsearch.core.Releasables;
2830
import org.elasticsearch.core.TimeValue;
@@ -54,6 +56,8 @@
5456
* Task that tracks the progress of a currently running {@link SearchRequest}.
5557
*/
5658
final class AsyncSearchTask extends SearchTask implements AsyncTask, Releasable {
59+
private final Logger logger = Loggers.getLogger(getClass(),"async");
60+
5761
private final AsyncExecutionId searchId;
5862
private final Client client;
5963
private final ThreadPool threadPool;
@@ -381,6 +385,15 @@ public static AsyncStatusResponse getStatusResponse(AsyncSearchTask asyncTask) {
381385

382386
@Override
383387
public void close() {
388+
if (logger.isDebugEnabled()) {
389+
logger.debug(
390+
"AsyncSearchTask.close(): byThread={}, asyncId={}, taskId={}, hasCompleted={}",
391+
Thread.currentThread().getName(),
392+
searchId != null ? searchId.getEncoded() : "<null>",
393+
getId(),
394+
hasCompleted
395+
);
396+
}
384397
Releasables.close(searchResponse);
385398
}
386399

x-pack/plugin/async-search/src/main/java/org/elasticsearch/xpack/search/MutableSearchResponse.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77
package org.elasticsearch.xpack.search;
88

9+
import org.apache.logging.log4j.Logger;
910
import org.apache.lucene.search.TotalHits;
1011
import org.elasticsearch.ElasticsearchException;
1112
import org.elasticsearch.ExceptionsHelper;
@@ -14,6 +15,7 @@
1415
import org.elasticsearch.action.search.SearchResponseMerger;
1516
import org.elasticsearch.action.search.ShardSearchFailure;
1617
import org.elasticsearch.common.Strings;
18+
import org.elasticsearch.common.logging.Loggers;
1719
import org.elasticsearch.common.lucene.Lucene;
1820
import org.elasticsearch.common.util.concurrent.AtomicArray;
1921
import org.elasticsearch.common.util.concurrent.ThreadContext;
@@ -39,6 +41,9 @@
3941
* run concurrently to 1 and ensures that we pause the search progress when an {@link AsyncSearchResponse} is built.
4042
*/
4143
class MutableSearchResponse implements Releasable {
44+
45+
private final Logger logger = Loggers.getLogger(getClass(), "async");
46+
4247
private int totalShards;
4348
private int skippedShards;
4449
private Clusters clusters;
@@ -488,6 +493,15 @@ private String getShardsInResponseMismatchInfo(SearchResponse response, boolean
488493

489494
@Override
490495
public synchronized void close() {
496+
if (logger.isDebugEnabled()) {
497+
logger.debug(
498+
"MutableSearchResponse.close(): byThread={}, finalResponsePresent={}, clusterResponsesCount={},",
499+
Thread.currentThread().getName(),
500+
finalResponse != null,
501+
clusterResponses != null ? clusterResponses.size() : 0
502+
);
503+
}
504+
491505
if (finalResponse != null) {
492506
finalResponse.decRef();
493507
}

0 commit comments

Comments
 (0)