Skip to content

Commit 4466c0f

Browse files
deshsiddansjcyjed326
committed
Create listener to refresh search thread resource usage (opensearch-project#14832)
Signed-off-by: Siddhant Deshmukh <[email protected]> * [bug fix] fix incorrect coordinator node search resource usages Signed-off-by: Chenyang Ji <[email protected]> * fix bug on serialization when passing task resource usage to coordinator Signed-off-by: Chenyang Ji <[email protected]> * add more unit tests Signed-off-by: Chenyang Ji <[email protected]> * remove query insights plugin related code Signed-off-by: Chenyang Ji <[email protected]> * create per request listener to refresh task resource usage Signed-off-by: Chenyang Ji <[email protected]> * Make new listener API public Signed-off-by: Siddhant Deshmukh <[email protected]> * Add changelog Signed-off-by: Siddhant Deshmukh <[email protected]> * Remove wrong files added Signed-off-by: Siddhant Deshmukh <[email protected]> * Address review comments Signed-off-by: Siddhant Deshmukh <[email protected]> * Build fix Signed-off-by: Siddhant Deshmukh <[email protected]> * Make singleton Signed-off-by: Siddhant Deshmukh <[email protected]> * Address review comments Signed-off-by: Siddhant Deshmukh <[email protected]> * Make sure listener runs before plugin listeners Signed-off-by: Siddhant Deshmukh <[email protected]> * Spotless Signed-off-by: Siddhant Deshmukh <[email protected]> * Minor fix Signed-off-by: Siddhant Deshmukh <[email protected]> --------- Signed-off-by: Chenyang Ji <[email protected]> Signed-off-by: Siddhant Deshmukh <[email protected]> Signed-off-by: Jay Deng <[email protected]> Co-authored-by: Chenyang Ji <[email protected]> Co-authored-by: Jay Deng <[email protected]> (cherry picked from commit 8ff3bcc)
1 parent 36dc24a commit 4466c0f

File tree

3 files changed

+45
-9
lines changed

3 files changed

+45
-9
lines changed

CHANGELOG.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ All notable changes to this project are documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). See the [CONTRIBUTING guide](./CONTRIBUTING.md#Changelog) for instructions on how to add changelog entries.
55

66
## [Unreleased 2.x]
7-
### Added
87
- Add fingerprint ingest processor ([#13724](https://github.com/opensearch-project/OpenSearch/pull/13724))
98
- [Remote Store] Rate limiter for remote store low priority uploads ([#14374](https://github.com/opensearch-project/OpenSearch/pull/14374/))
109
- Apply the date histogram rewrite optimization to range aggregation ([#13865](https://github.com/opensearch-project/OpenSearch/pull/13865))
@@ -25,7 +24,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
2524
- Add SplitResponseProcessor to Search Pipelines (([#14800](https://github.com/opensearch-project/OpenSearch/issues/14800)))
2625
- Optimize TransportNodesAction to not send DiscoveryNodes for NodeStats, NodesInfo and ClusterStats call ([14749](https://github.com/opensearch-project/OpenSearch/pull/14749))
2726
- Reduce logging in DEBUG for MasterService:run ([#14795](https://github.com/opensearch-project/OpenSearch/pull/14795))
28-
- Refactor remote-routing-table service inline with remote state interfaces([#14668](https://github.com/opensearch-project/OpenSearch/pull/14668))
27+
- Enabling term version check on local state for all ClusterManager Read Transport Actions ([#14273](https://github.com/opensearch-project/OpenSearch/pull/14273))
28+
- Add persian_stem filter (([#14847](https://github.com/opensearch-project/OpenSearch/pull/14847)))
29+
- Create listener to refresh search thread resource usage ([#14832](https://github.com/opensearch-project/OpenSearch/pull/14832))
30+
- Add rest, transport layer changes for hot to warm tiering - dedicated setup (([#13980](https://github.com/opensearch-project/OpenSearch/pull/13980))
2931

3032
### Dependencies
3133
- Update to Apache Lucene 9.11.1 ([#14042](https://github.com/opensearch-project/OpenSearch/pull/14042), [#14576](https://github.com/opensearch-project/OpenSearch/pull/14576))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* The OpenSearch Contributors require contributions made to
5+
* this file be licensed under the Apache-2.0 license or a
6+
* compatible open source license.
7+
*/
8+
9+
package org.opensearch.action.search;
10+
11+
import org.opensearch.tasks.TaskResourceTrackingService;
12+
13+
/**
14+
* SearchTaskRequestOperationsListener subscriber for operations on search tasks resource usages.
15+
* Listener ensures to refreshResourceStats on request end capturing the search task resource usage
16+
* upon request completion.
17+
*
18+
*/
19+
public final class SearchTaskRequestOperationsListener extends SearchRequestOperationsListener {
20+
private final TaskResourceTrackingService taskResourceTrackingService;
21+
22+
public SearchTaskRequestOperationsListener(TaskResourceTrackingService taskResourceTrackingService) {
23+
this.taskResourceTrackingService = taskResourceTrackingService;
24+
}
25+
26+
@Override
27+
public void onRequestEnd(SearchPhaseContext context, SearchRequestContext searchRequestContext) {
28+
taskResourceTrackingService.refreshResourceStats(context.getTask());
29+
}
30+
}

server/src/main/java/org/opensearch/node/Node.java

+11-7
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
import org.opensearch.action.search.SearchRequestOperationsListener;
5252
import org.opensearch.action.search.SearchRequestSlowLog;
5353
import org.opensearch.action.search.SearchRequestStats;
54+
import org.opensearch.action.search.SearchTaskRequestOperationsListener;
5455
import org.opensearch.action.search.SearchTransportService;
5556
import org.opensearch.action.support.TransportAction;
5657
import org.opensearch.action.update.UpdateHelper;
@@ -852,8 +853,17 @@ protected Node(
852853
threadPool
853854
);
854855

856+
final TaskResourceTrackingService taskResourceTrackingService = new TaskResourceTrackingService(
857+
settings,
858+
clusterService.getClusterSettings(),
859+
threadPool
860+
);
861+
855862
final SearchRequestStats searchRequestStats = new SearchRequestStats(clusterService.getClusterSettings());
856863
final SearchRequestSlowLog searchRequestSlowLog = new SearchRequestSlowLog(clusterService);
864+
final SearchTaskRequestOperationsListener searchTaskRequestOperationsListener = new SearchTaskRequestOperationsListener(
865+
taskResourceTrackingService
866+
);
857867

858868
remoteStoreStatsTrackerFactory = new RemoteStoreStatsTrackerFactory(clusterService, settings);
859869
CacheModule cacheModule = new CacheModule(pluginsService.filterPlugins(CachePlugin.class), settings);
@@ -982,7 +992,7 @@ protected Node(
982992
final SearchRequestOperationsCompositeListenerFactory searchRequestOperationsCompositeListenerFactory =
983993
new SearchRequestOperationsCompositeListenerFactory(
984994
Stream.concat(
985-
Stream.of(searchRequestStats, searchRequestSlowLog),
995+
Stream.of(searchRequestStats, searchRequestSlowLog, searchTaskRequestOperationsListener),
986996
pluginComponents.stream()
987997
.filter(p -> p instanceof SearchRequestOperationsListener)
988998
.map(p -> (SearchRequestOperationsListener) p)
@@ -1110,12 +1120,6 @@ protected Node(
11101120
// development. Then we can deprecate Getter and Setter for IndexingPressureService in ClusterService (#478).
11111121
clusterService.setIndexingPressureService(indexingPressureService);
11121122

1113-
final TaskResourceTrackingService taskResourceTrackingService = new TaskResourceTrackingService(
1114-
settings,
1115-
clusterService.getClusterSettings(),
1116-
threadPool
1117-
);
1118-
11191123
final SearchBackpressureSettings searchBackpressureSettings = new SearchBackpressureSettings(
11201124
settings,
11211125
clusterService.getClusterSettings()

0 commit comments

Comments
 (0)