Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
Signed-off-by: Siddhant Deshmukh <[email protected]>
  • Loading branch information
deshsidd committed Jul 18, 2024
1 parent 2c3e40a commit 90ac7e5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 17 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,23 @@
* 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.
* Listener ensures to refreshResourceStats on request end capturing the search task resource usage
* 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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -175,6 +174,7 @@ public class TransportSearchAction extends HandledTransportAction<SearchRequest,
private final SearchPipelineService searchPipelineService;
private final SearchRequestOperationsCompositeListenerFactory searchRequestOperationsCompositeListenerFactory;
private final Tracer tracer;
private final SearchTaskRequestOperationsListener searchTaskRequestOperationsListener;

private final MetricsRegistry metricsRegistry;

Expand Down Expand Up @@ -216,6 +216,7 @@ public TransportSearchAction(
this.searchRequestOperationsCompositeListenerFactory = searchRequestOperationsCompositeListenerFactory;
this.tracer = tracer;
this.taskResourceTrackingService = taskResourceTrackingService;
this.searchTaskRequestOperationsListener = new SearchTaskRequestOperationsListener(taskResourceTrackingService);
}

private Map<String, AliasFilter> buildPerIndexAliasFilter(
Expand Down Expand Up @@ -435,7 +436,7 @@ private void executeRequest(
originalSearchRequest,
logger,
TraceableSearchRequestOperationsListener.create(tracer, requestSpan),
SearchTaskRequestOperationsListener.getInstance(taskResourceTrackingService)
searchTaskRequestOperationsListener
);
SearchRequestContext searchRequestContext = new SearchRequestContext(
requestOperationsListeners,
Expand Down

0 comments on commit 90ac7e5

Please sign in to comment.