|
@@ -116,6 +116,7 @@ import org.elasticsearch.threadpool.Scheduler;
|
|
|
import org.elasticsearch.threadpool.Scheduler.Cancellable;
|
|
|
import org.elasticsearch.threadpool.ThreadPool;
|
|
|
import org.elasticsearch.threadpool.ThreadPool.Names;
|
|
|
+import org.elasticsearch.tracing.Tracer;
|
|
|
import org.elasticsearch.transport.TransportRequest;
|
|
|
|
|
|
import java.io.IOException;
|
|
@@ -269,6 +270,8 @@ public class SearchService extends AbstractLifecycleComponent implements IndexEv
|
|
|
private final AtomicInteger openScrollContexts = new AtomicInteger();
|
|
|
private final String sessionId = UUIDs.randomBase64UUID();
|
|
|
|
|
|
+ private final Tracer tracer;
|
|
|
+
|
|
|
public SearchService(
|
|
|
ClusterService clusterService,
|
|
|
IndicesService indicesService,
|
|
@@ -279,6 +282,32 @@ public class SearchService extends AbstractLifecycleComponent implements IndexEv
|
|
|
ResponseCollectorService responseCollectorService,
|
|
|
CircuitBreakerService circuitBreakerService,
|
|
|
ExecutorSelector executorSelector
|
|
|
+ ) {
|
|
|
+ this(
|
|
|
+ clusterService,
|
|
|
+ indicesService,
|
|
|
+ threadPool,
|
|
|
+ scriptService,
|
|
|
+ bigArrays,
|
|
|
+ fetchPhase,
|
|
|
+ responseCollectorService,
|
|
|
+ circuitBreakerService,
|
|
|
+ executorSelector,
|
|
|
+ Tracer.NOOP
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ public SearchService(
|
|
|
+ ClusterService clusterService,
|
|
|
+ IndicesService indicesService,
|
|
|
+ ThreadPool threadPool,
|
|
|
+ ScriptService scriptService,
|
|
|
+ BigArrays bigArrays,
|
|
|
+ FetchPhase fetchPhase,
|
|
|
+ ResponseCollectorService responseCollectorService,
|
|
|
+ CircuitBreakerService circuitBreakerService,
|
|
|
+ ExecutorSelector executorSelector,
|
|
|
+ Tracer tracer
|
|
|
) {
|
|
|
Settings settings = clusterService.getSettings();
|
|
|
this.threadPool = threadPool;
|
|
@@ -294,6 +323,7 @@ public class SearchService extends AbstractLifecycleComponent implements IndexEv
|
|
|
circuitBreakerService.getBreaker(CircuitBreaker.REQUEST)
|
|
|
);
|
|
|
this.executorSelector = executorSelector;
|
|
|
+ this.tracer = tracer;
|
|
|
|
|
|
TimeValue keepAliveInterval = KEEPALIVE_INTERVAL_SETTING.get(settings);
|
|
|
setKeepAlives(DEFAULT_KEEPALIVE_SETTING.get(settings), MAX_KEEPALIVE_SETTING.get(settings));
|
|
@@ -440,6 +470,7 @@ public class SearchService extends AbstractLifecycleComponent implements IndexEv
|
|
|
private DfsSearchResult executeDfsPhase(ShardSearchRequest request, SearchShardTask task) throws IOException {
|
|
|
ReaderContext readerContext = createOrGetReaderContext(request);
|
|
|
try (
|
|
|
+ Releasable scope = tracer.withScope("task-" + task.getId());
|
|
|
Releasable ignored = readerContext.markAsUsed(getKeepAlive(request));
|
|
|
SearchContext context = createContext(readerContext, request, task, true)
|
|
|
) {
|
|
@@ -619,9 +650,11 @@ public class SearchService extends AbstractLifecycleComponent implements IndexEv
|
|
|
private SearchPhaseResult executeQueryPhase(ShardSearchRequest request, SearchShardTask task) throws Exception {
|
|
|
final ReaderContext readerContext = createOrGetReaderContext(request);
|
|
|
try (
|
|
|
+ Releasable scope = tracer.withScope("task-" + task.getId());
|
|
|
Releasable ignored = readerContext.markAsUsed(getKeepAlive(request));
|
|
|
SearchContext context = createContext(readerContext, request, task, true)
|
|
|
) {
|
|
|
+ tracer.startTrace("executeQueryPhase", Map.of());
|
|
|
final long afterQueryTime;
|
|
|
try (SearchOperationListenerExecutor executor = new SearchOperationListenerExecutor(context)) {
|
|
|
loadOrExecuteQueryPhase(request, context);
|
|
@@ -629,6 +662,8 @@ public class SearchService extends AbstractLifecycleComponent implements IndexEv
|
|
|
freeReaderContext(readerContext.id());
|
|
|
}
|
|
|
afterQueryTime = executor.success();
|
|
|
+ } finally {
|
|
|
+ tracer.stopTrace();
|
|
|
}
|
|
|
if (request.numberOfShards() == 1) {
|
|
|
return executeFetchPhase(readerContext, context, afterQueryTime);
|
|
@@ -654,7 +689,10 @@ public class SearchService extends AbstractLifecycleComponent implements IndexEv
|
|
|
}
|
|
|
|
|
|
private QueryFetchSearchResult executeFetchPhase(ReaderContext reader, SearchContext context, long afterQueryTime) {
|
|
|
- try (SearchOperationListenerExecutor executor = new SearchOperationListenerExecutor(context, true, afterQueryTime)) {
|
|
|
+ try (
|
|
|
+ Releasable scope = tracer.withScope("task-" + context.getTask().getId());
|
|
|
+ SearchOperationListenerExecutor executor = new SearchOperationListenerExecutor(context, true, afterQueryTime)
|
|
|
+ ) {
|
|
|
shortcutDocIdsToLoad(context);
|
|
|
fetchPhase.execute(context);
|
|
|
if (reader.singleSession()) {
|