Skip to content

Commit 5d963c8

Browse files
committed
Always collect available metrics in top queries service
Signed-off-by: Chenyang Ji <cyji@amazon.com>
1 parent 56d456c commit 5d963c8

File tree

1 file changed

+16
-26
lines changed

1 file changed

+16
-26
lines changed

src/main/java/org/opensearch/plugin/insights/core/listener/QueryInsightsListener.java

+16-26
Original file line numberDiff line numberDiff line change
@@ -220,10 +220,6 @@ public void onRequestFailure(final SearchPhaseContext context, final SearchReque
220220
constructSearchQueryRecord(context, searchRequestContext);
221221
}
222222

223-
private boolean shouldCollect(MetricType metricType) {
224-
return queryInsightsService.isSearchQueryMetricsFeatureEnabled() || queryInsightsService.isCollectionEnabled(metricType);
225-
}
226-
227223
private void constructSearchQueryRecord(final SearchPhaseContext context, final SearchRequestContext searchRequestContext) {
228224
SearchTask searchTask = context.getTask();
229225
List<TaskResourceInfo> tasksResourceUsages = searchRequestContext.getPhaseResourceUsage();
@@ -240,28 +236,22 @@ private void constructSearchQueryRecord(final SearchPhaseContext context, final
240236
final SearchRequest request = context.getRequest();
241237
try {
242238
Map<MetricType, Measurement> measurements = new HashMap<>();
243-
if (shouldCollect(MetricType.LATENCY)) {
244-
measurements.put(
245-
MetricType.LATENCY,
246-
new Measurement(TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - searchRequestContext.getAbsoluteStartNanos()))
247-
);
248-
}
249-
if (shouldCollect(MetricType.CPU)) {
250-
measurements.put(
251-
MetricType.CPU,
252-
new Measurement(
253-
tasksResourceUsages.stream().map(a -> a.getTaskResourceUsage().getCpuTimeInNanos()).mapToLong(Long::longValue).sum()
254-
)
255-
);
256-
}
257-
if (shouldCollect(MetricType.MEMORY)) {
258-
measurements.put(
259-
MetricType.MEMORY,
260-
new Measurement(
261-
tasksResourceUsages.stream().map(a -> a.getTaskResourceUsage().getMemoryInBytes()).mapToLong(Long::longValue).sum()
262-
)
263-
);
264-
}
239+
measurements.put(
240+
MetricType.LATENCY,
241+
new Measurement(TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - searchRequestContext.getAbsoluteStartNanos()))
242+
);
243+
measurements.put(
244+
MetricType.CPU,
245+
new Measurement(
246+
tasksResourceUsages.stream().map(a -> a.getTaskResourceUsage().getCpuTimeInNanos()).mapToLong(Long::longValue).sum()
247+
)
248+
);
249+
measurements.put(
250+
MetricType.MEMORY,
251+
new Measurement(
252+
tasksResourceUsages.stream().map(a -> a.getTaskResourceUsage().getMemoryInBytes()).mapToLong(Long::longValue).sum()
253+
)
254+
);
265255

266256
Map<Attribute, Object> attributes = new HashMap<>();
267257
attributes.put(Attribute.SEARCH_TYPE, request.searchType().toString().toLowerCase(Locale.ROOT));

0 commit comments

Comments
 (0)