diff --git a/CHANGELOG.md b/CHANGELOG.md index 4ca2bb9f404b1..5a66d8879ea98 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,7 +20,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), - Add matchesPluginSystemIndexPattern to SystemIndexRegistry ([#14750](https://github.com/opensearch-project/OpenSearch/pull/14750)) - Add Plugin interface for loading application based configuration templates (([#14659](https://github.com/opensearch-project/OpenSearch/issues/14659))) - Refactor remote-routing-table service inline with remote state interfaces([#14668](https://github.com/opensearch-project/OpenSearch/pull/14668)) -- Create public listener to refresh search thread resource usage ([#14832](https://github.com/opensearch-project/OpenSearch/pull/14832)) +- Create listener to refresh search thread resource usage ([#14832](https://github.com/opensearch-project/OpenSearch/pull/14832)) ### Dependencies - Bump `org.gradle.test-retry` from 1.5.8 to 1.5.9 ([#13442](https://github.com/opensearch-project/OpenSearch/pull/13442)) diff --git a/server/src/main/java/org/opensearch/tasks/SearchTaskRequestOperationsListener.java b/server/src/main/java/org/opensearch/action/search/SearchTaskRequestOperationsListener.java similarity index 50% rename from server/src/main/java/org/opensearch/tasks/SearchTaskRequestOperationsListener.java rename to server/src/main/java/org/opensearch/action/search/SearchTaskRequestOperationsListener.java index de46ed6a28581..1a8ca2c5c24df 100644 --- a/server/src/main/java/org/opensearch/tasks/SearchTaskRequestOperationsListener.java +++ b/server/src/main/java/org/opensearch/action/search/SearchTaskRequestOperationsListener.java @@ -6,11 +6,9 @@ * compatible open source license. */ -package org.opensearch.tasks; +package org.opensearch.action.search; -import org.opensearch.action.search.SearchPhaseContext; -import org.opensearch.action.search.SearchRequestContext; -import org.opensearch.action.search.SearchRequestOperationsListener; +import org.opensearch.tasks.TaskResourceTrackingService; /** * SearchTaskRequestOperationsListener subscriber for operations on search tasks resource usages. @@ -18,21 +16,13 @@ * upon request completion. * */ -public final class SearchTaskRequestOperationsListener extends SearchRequestOperationsListener { - private static SearchTaskRequestOperationsListener instance; +final class SearchTaskRequestOperationsListener extends SearchRequestOperationsListener { private final TaskResourceTrackingService taskResourceTrackingService; - private SearchTaskRequestOperationsListener(TaskResourceTrackingService taskResourceTrackingService) { + SearchTaskRequestOperationsListener(TaskResourceTrackingService taskResourceTrackingService) { this.taskResourceTrackingService = taskResourceTrackingService; } - public static synchronized SearchTaskRequestOperationsListener getInstance(TaskResourceTrackingService taskResourceTrackingService) { - if (instance == null) { - instance = new SearchTaskRequestOperationsListener(taskResourceTrackingService); - } - return instance; - } - @Override public void onRequestEnd(SearchPhaseContext context, SearchRequestContext searchRequestContext) { taskResourceTrackingService.refreshResourceStats(context.getTask()); diff --git a/server/src/main/java/org/opensearch/action/search/TransportSearchAction.java b/server/src/main/java/org/opensearch/action/search/TransportSearchAction.java index ceab2343091f7..d97d50fc3b7fe 100644 --- a/server/src/main/java/org/opensearch/action/search/TransportSearchAction.java +++ b/server/src/main/java/org/opensearch/action/search/TransportSearchAction.java @@ -86,7 +86,6 @@ import org.opensearch.search.profile.ProfileShardResult; import org.opensearch.search.profile.SearchProfileShardResults; import org.opensearch.tasks.CancellableTask; -import org.opensearch.tasks.SearchTaskRequestOperationsListener; import org.opensearch.tasks.Task; import org.opensearch.tasks.TaskResourceTrackingService; import org.opensearch.telemetry.metrics.MetricsRegistry; @@ -175,6 +174,7 @@ public class TransportSearchAction extends HandledTransportAction buildPerIndexAliasFilter( @@ -435,7 +436,7 @@ private void executeRequest( originalSearchRequest, logger, TraceableSearchRequestOperationsListener.create(tracer, requestSpan), - SearchTaskRequestOperationsListener.getInstance(taskResourceTrackingService) + searchTaskRequestOperationsListener ); SearchRequestContext searchRequestContext = new SearchRequestContext( requestOperationsListeners,