Skip to content

Commit 07a8a3e

Browse files
PR fixes
1 parent 76844ec commit 07a8a3e

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

server/src/main/java/org/elasticsearch/action/search/CanMatchPreFilterSearchPhase.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,10 @@ public static SubscribableListener<List<SearchShardIterator>> execute(
152152
listener.addListener(new ActionListener<>() {
153153
@Override
154154
public void onResponse(List<SearchShardIterator> shardsIts) {
155-
// searchResponseMetrics is null for node can-match requests
155+
// we only want to record the phase duration if this call to execute is running on the coordinator node
156+
// as part of the can-match phase or a search request. It will be null if this is the data node round trip can-match
157+
// execution
158+
// or an open PIT request
156159
if (searchResponseMetrics != null) {
157160
searchResponseMetrics.recordSearchPhaseDuration(PHASE_NAME, System.nanoTime() - phaseStartTimeInNanos);
158161
}

server/src/main/java/org/elasticsearch/action/search/TransportOpenPointInTimeAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ public void runNewSearchPhase(
185185
task,
186186
false,
187187
searchService.getCoordinatorRewriteContextProvider(timeProvider::absoluteStartMillis),
188-
searchResponseMetrics
188+
null
189189
)
190190
.addListener(
191191
listener.delegateFailureAndWrap(

server/src/test/java/org/elasticsearch/rest/action/search/SearchPhaseCoordinatorAPMMetricsTests.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ public void testSearchQueryThenFetch() {
8484
"1"
8585
);
8686
assertMeasurements(List.of(QUERY_SEARCH_PHASE_METRIC, FETCH_SEARCH_PHASE_METRIC));
87+
assertNotMeasured(List.of(CAN_MATCH_SEARCH_PHASE_METRIC, DFS_SEARCH_PHASE_METRIC, DFS_QUERY_SEARCH_PHASE_METRIC, OPEN_PIT_SEARCH_PHASE_METRIC));
8788
}
8889

8990
public void testDfsSearch() {
@@ -92,10 +93,12 @@ public void testDfsSearch() {
9293
"1"
9394
);
9495
assertMeasurements(List.of(DFS_SEARCH_PHASE_METRIC, DFS_QUERY_SEARCH_PHASE_METRIC, FETCH_SEARCH_PHASE_METRIC));
96+
assertNotMeasured(List.of(CAN_MATCH_SEARCH_PHASE_METRIC, QUERY_SEARCH_PHASE_METRIC, OPEN_PIT_SEARCH_PHASE_METRIC));
9597
}
9698

9799
public void testPointInTime() {
98100
OpenPointInTimeRequest request = new OpenPointInTimeRequest(indexName).keepAlive(TimeValue.timeValueMinutes(10));
101+
request.indexFilter(simpleQueryStringQuery("doc1"));
99102
OpenPointInTimeResponse response = client().execute(TransportOpenPointInTimeAction.TYPE, request).actionGet();
100103
BytesReference pointInTimeId = response.getPointInTimeId();
101104

@@ -108,6 +111,29 @@ public void testPointInTime() {
108111
"1"
109112
);
110113
assertMeasurements(List.of(OPEN_PIT_SEARCH_PHASE_METRIC, QUERY_SEARCH_PHASE_METRIC, FETCH_SEARCH_PHASE_METRIC));
114+
assertNotMeasured(List.of(CAN_MATCH_SEARCH_PHASE_METRIC, DFS_SEARCH_PHASE_METRIC, DFS_QUERY_SEARCH_PHASE_METRIC));
115+
} finally {
116+
client().execute(TransportClosePointInTimeAction.TYPE, new ClosePointInTimeRequest(pointInTimeId)).actionGet();
117+
}
118+
}
119+
120+
public void testPointInTimeWithPreFiltering() {
121+
OpenPointInTimeRequest request = new OpenPointInTimeRequest(indexName).keepAlive(TimeValue.timeValueMinutes(10));
122+
request.indexFilter(simpleQueryStringQuery("doc1"));
123+
OpenPointInTimeResponse response = client().execute(TransportOpenPointInTimeAction.TYPE, request).actionGet();
124+
BytesReference pointInTimeId = response.getPointInTimeId();
125+
126+
try {
127+
assertSearchHitsWithoutFailures(
128+
client().prepareSearch()
129+
.setPointInTime(new PointInTimeBuilder(pointInTimeId))
130+
.setSize(1)
131+
.setPreFilterShardSize(1)
132+
.setQuery(simpleQueryStringQuery("doc1")),
133+
"1"
134+
);
135+
assertMeasurements(List.of(OPEN_PIT_SEARCH_PHASE_METRIC, CAN_MATCH_SEARCH_PHASE_METRIC, QUERY_SEARCH_PHASE_METRIC, FETCH_SEARCH_PHASE_METRIC));
136+
assertNotMeasured(List.of(DFS_SEARCH_PHASE_METRIC, DFS_QUERY_SEARCH_PHASE_METRIC));
111137
} finally {
112138
client().execute(TransportClosePointInTimeAction.TYPE, new ClosePointInTimeRequest(pointInTimeId)).actionGet();
113139
}
@@ -123,6 +149,7 @@ public void testCanMatchSearch() {
123149
);
124150

125151
assertMeasurements(List.of(CAN_MATCH_SEARCH_PHASE_METRIC, FETCH_SEARCH_PHASE_METRIC, QUERY_SEARCH_PHASE_METRIC));
152+
assertNotMeasured(List.of(DFS_SEARCH_PHASE_METRIC, DFS_QUERY_SEARCH_PHASE_METRIC, OPEN_PIT_SEARCH_PHASE_METRIC));
126153
}
127154

128155
private void resetMeter() {
@@ -133,6 +160,13 @@ private TestTelemetryPlugin getTestTelemetryPlugin() {
133160
return getInstanceFromNode(PluginsService.class).filterPlugins(TestTelemetryPlugin.class).toList().get(0);
134161
}
135162

163+
private void assertNotMeasured(Collection<String> metricNames) {
164+
for (var metricName : metricNames) {
165+
List<Measurement> measurements = getTestTelemetryPlugin().getLongHistogramMeasurement(metricName);
166+
assertThat(measurements, hasSize(0));
167+
}
168+
}
169+
136170
private void assertMeasurements(Collection<String> metricNames) {
137171
for (var metricName : metricNames) {
138172
List<Measurement> measurements = getTestTelemetryPlugin().getLongHistogramMeasurement(metricName);

0 commit comments

Comments
 (0)