-
Notifications
You must be signed in to change notification settings - Fork 25.5k
Search query phase coordinator duration APM metric. #136059
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
base: main
Are you sure you want to change the base?
Changes from 5 commits
9239f46
70b59c1
0ff47ab
5973b2c
58d237e
182b619
f52cedf
60640d9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ | |
import org.elasticsearch.client.internal.Client; | ||
import org.elasticsearch.cluster.ClusterState; | ||
import org.elasticsearch.common.io.stream.NamedWriteableRegistry; | ||
import org.elasticsearch.index.search.stats.CoordinatorSearchPhaseAPMMetrics; | ||
import org.elasticsearch.search.SearchPhaseResult; | ||
import org.elasticsearch.search.SearchShardTarget; | ||
import org.elasticsearch.search.dfs.DfsSearchResult; | ||
|
@@ -47,7 +48,8 @@ final class SearchDfsQueryThenFetchAsyncAction extends AbstractSearchAsyncAction | |
ClusterState clusterState, | ||
SearchTask task, | ||
SearchResponse.Clusters clusters, | ||
Client client | ||
Client client, | ||
CoordinatorSearchPhaseAPMMetrics coordinatorSearchPhaseAPMMetrics | ||
) { | ||
super( | ||
"dfs", | ||
|
@@ -66,7 +68,8 @@ final class SearchDfsQueryThenFetchAsyncAction extends AbstractSearchAsyncAction | |
task, | ||
new ArraySearchPhaseResults<>(shardsIts.size()), | ||
request.getMaxConcurrentShardRequests(), | ||
clusters | ||
clusters, | ||
coordinatorSearchPhaseAPMMetrics | ||
|
||
); | ||
this.queryPhaseResultConsumer = queryPhaseResultConsumer; | ||
addReleasable(queryPhaseResultConsumer); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,7 @@ | |
import org.elasticsearch.core.RefCounted; | ||
import org.elasticsearch.core.SimpleRefCounted; | ||
import org.elasticsearch.core.TimeValue; | ||
import org.elasticsearch.index.search.stats.CoordinatorSearchPhaseAPMMetrics; | ||
import org.elasticsearch.index.shard.ShardId; | ||
import org.elasticsearch.search.SearchPhaseResult; | ||
import org.elasticsearch.search.SearchService; | ||
|
@@ -92,6 +93,7 @@ public class SearchQueryThenFetchAsyncAction extends AbstractSearchAsyncAction<S | |
private volatile BottomSortValuesCollector bottomSortCollector; | ||
private final Client client; | ||
private final boolean batchQueryPhase; | ||
private long phaseStartTimeNanos; | ||
|
||
SearchQueryThenFetchAsyncAction( | ||
Logger logger, | ||
|
@@ -110,7 +112,8 @@ public class SearchQueryThenFetchAsyncAction extends AbstractSearchAsyncAction<S | |
SearchTask task, | ||
SearchResponse.Clusters clusters, | ||
Client client, | ||
boolean batchQueryPhase | ||
boolean batchQueryPhase, | ||
CoordinatorSearchPhaseAPMMetrics coordinatorSearchPhaseAPMMetrics | ||
) { | ||
super( | ||
"query", | ||
|
@@ -129,7 +132,8 @@ public class SearchQueryThenFetchAsyncAction extends AbstractSearchAsyncAction<S | |
task, | ||
resultConsumer, | ||
request.getMaxConcurrentShardRequests(), | ||
clusters | ||
clusters, | ||
coordinatorSearchPhaseAPMMetrics | ||
); | ||
this.topDocsSize = getTopDocsSize(request); | ||
this.trackTotalHitsUpTo = request.resolveTrackTotalHitsUpTo(); | ||
|
@@ -421,6 +425,7 @@ private static boolean isPartOfPIT( | |
|
||
@Override | ||
protected void doRun(Map<SearchShardIterator, Integer> shardIndexMap) { | ||
phaseStartTimeNanos = System.nanoTime(); | ||
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. This could be potentially streamlined into the 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. My other PR attempted the "generic" path as well. There is some weirdness around the PIT creation and queries that caused a lot of issues in CI but I think I have an idea of where the issue was. I'll try and move this code into the I'll have to check if that helps fetch other subsequent phases. The issue with them is that they don't subclass off of 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. I see what you mean. I'd limit the change to tracking the two variations of query phase and perhaps open point in time. The 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. To be clear, does "dfs" cover both the "DFS roundtrip" and the DFS specific query implementation (i.e. basically timing |
||
if (this.batchQueryPhase == false) { | ||
super.doRun(shardIndexMap); | ||
return; | ||
|
@@ -564,6 +569,12 @@ private void onNodeQueryFailure(Exception e, NodeQueryRequest request, CanMatchP | |
} | ||
} | ||
|
||
@Override | ||
protected void recordPhaseLatency() { | ||
final long tookInNanos = System.nanoTime() - phaseStartTimeNanos; | ||
coordinatorSearchPhaseAPMMetrics.onQueryPhaseDone(tookInNanos); | ||
} | ||
|
||
public static final String NODE_SEARCH_ACTION_NAME = "indices:data/read/search[query][n]"; | ||
|
||
static void registerNodeSearchAction( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* 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", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
package org.elasticsearch.index.search.stats; | ||
|
||
import org.elasticsearch.telemetry.metric.LongHistogram; | ||
import org.elasticsearch.telemetry.metric.MeterRegistry; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
/** | ||
* Coordinator level APM metrics for search phases. Records phase execution times as histograms. | ||
*/ | ||
public class CoordinatorSearchPhaseAPMMetrics { | ||
chrisparrinello marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
public static final CoordinatorSearchPhaseAPMMetrics NOOP = new CoordinatorSearchPhaseAPMMetrics(MeterRegistry.NOOP); | ||
|
||
public static final String QUERY_SEARCH_PHASE_METRIC = "es.search.coordinator.phases.query.duration.histogram"; | ||
private final LongHistogram queryPhaseMetric; | ||
|
||
public CoordinatorSearchPhaseAPMMetrics(MeterRegistry meterRegistry) { | ||
this.queryPhaseMetric = meterRegistry.registerLongHistogram( | ||
QUERY_SEARCH_PHASE_METRIC, | ||
"Query search phase execution times at the coordinator level, expressed as a histogram", | ||
"ms" | ||
); | ||
} | ||
|
||
public void onQueryPhaseDone(long tookInNanos) { | ||
recordPhaseLatency(queryPhaseMetric, tookInNanos); | ||
} | ||
|
||
protected void recordPhaseLatency(LongHistogram histogramMetric, long tookInNanos) { | ||
chrisparrinello marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
histogramMetric.record(TimeUnit.NANOSECONDS.toMillis(tookInNanos)); | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.