Skip to content

Commit 545a38b

Browse files
Remove NodeUsageStatsForThreadPoolsCollector interface and replace with a single class
1 parent d7088a1 commit 545a38b

File tree

4 files changed

+34
-53
lines changed

4 files changed

+34
-53
lines changed

server/src/main/java/org/elasticsearch/cluster/NodeUsageStatsForThreadPoolsCollector.java

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@
99

1010
package org.elasticsearch.cluster;
1111

12+
import org.apache.logging.log4j.LogManager;
13+
import org.apache.logging.log4j.Logger;
14+
import org.elasticsearch.TransportVersions;
1215
import org.elasticsearch.action.ActionListener;
16+
import org.elasticsearch.action.admin.cluster.node.usage.NodeUsageStatsForThreadPoolsAction;
17+
import org.elasticsearch.action.admin.cluster.node.usage.TransportNodeUsageStatsForThreadPoolsAction;
1318
import org.elasticsearch.client.internal.Client;
1419

1520
import java.util.Map;
@@ -19,16 +24,38 @@
1924
* <p>
2025
* Results are returned as a map of node ID to node usage stats.
2126
*/
22-
public interface NodeUsageStatsForThreadPoolsCollector {
27+
public class NodeUsageStatsForThreadPoolsCollector {
2328
/**
24-
* This will be used when there is no NodeUsageLoadCollector available.
29+
* This will be used when there is no NodeUsageStatsForThreadPoolsCollector available.
2530
*/
26-
NodeUsageStatsForThreadPoolsCollector EMPTY = (client, clusterState, listener) -> listener.onResponse(Map.of());
31+
public static final NodeUsageStatsForThreadPoolsCollector EMPTY = new NodeUsageStatsForThreadPoolsCollector() {
32+
public void collectUsageStats(
33+
Client client,
34+
ClusterState clusterState,
35+
ActionListener<Map<String, NodeUsageStatsForThreadPools>> listener
36+
) {
37+
listener.onResponse(Map.of());
38+
}
39+
};
2740

2841
/**
2942
* Collects the thread pool usage stats ({@link NodeUsageStatsForThreadPools}) for each node in the cluster.
3043
*
3144
* @param listener The listener to receive the usage results.
3245
*/
33-
void collectUsageStats(Client client, ClusterState clusterState, ActionListener<Map<String, NodeUsageStatsForThreadPools>> listener);
46+
public void collectUsageStats(
47+
Client client,
48+
ClusterState clusterState,
49+
ActionListener<Map<String, NodeUsageStatsForThreadPools>> listener
50+
) {
51+
if (clusterState.getMinTransportVersion().onOrAfter(TransportVersions.TRANSPORT_NODE_USAGE_STATS_FOR_THREAD_POOLS_ACTION)) {
52+
client.execute(
53+
TransportNodeUsageStatsForThreadPoolsAction.TYPE,
54+
new NodeUsageStatsForThreadPoolsAction.Request(),
55+
listener.map(response -> response.getAllNodeUsageStatsForThreadPools())
56+
);
57+
} else {
58+
listener.onResponse(Map.of());
59+
}
60+
}
3461
}

server/src/main/java/org/elasticsearch/cluster/NodeUsageStatsForThreadPoolsCollectorImpl.java

Lines changed: 0 additions & 42 deletions
This file was deleted.

server/src/main/java/org/elasticsearch/node/NodeServiceProvider.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import org.elasticsearch.cluster.EstimatedHeapUsageCollector;
1616
import org.elasticsearch.cluster.InternalClusterInfoService;
1717
import org.elasticsearch.cluster.NodeUsageStatsForThreadPoolsCollector;
18-
import org.elasticsearch.cluster.NodeUsageStatsForThreadPoolsCollectorImpl;
18+
import org.elasticsearch.cluster.NodeUsageStatsForThreadPoolsCollector;
1919
import org.elasticsearch.cluster.node.DiscoveryNode;
2020
import org.elasticsearch.cluster.service.ClusterService;
2121
import org.elasticsearch.common.breaker.CircuitBreaker;
@@ -81,17 +81,13 @@ ClusterInfoService newClusterInfoService(
8181
EstimatedHeapUsageCollector.class,
8282
() -> EstimatedHeapUsageCollector.EMPTY
8383
);
84-
final NodeUsageStatsForThreadPoolsCollector nodeUsageStatsForThreadPoolsCollector = pluginsService.loadSingletonServiceProvider(
85-
NodeUsageStatsForThreadPoolsCollector.class,
86-
() -> new NodeUsageStatsForThreadPoolsCollectorImpl()
87-
);
8884
final InternalClusterInfoService service = new InternalClusterInfoService(
8985
settings,
9086
clusterService,
9187
threadPool,
9288
client,
9389
estimatedHeapUsageCollector,
94-
nodeUsageStatsForThreadPoolsCollector
90+
new NodeUsageStatsForThreadPoolsCollector()
9591
);
9692
if (DiscoveryNode.isMasterNode(settings)) {
9793
// listen for state changes (this node starts/stops being the elected master, or new nodes are added)

server/src/test/java/org/elasticsearch/cluster/InternalClusterInfoServiceSchedulingTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ protected PrioritizedEsThreadPoolExecutor createThreadPoolExecutor() {
8585
final FakeClusterInfoServiceClient client = new FakeClusterInfoServiceClient(threadPool);
8686
final EstimatedHeapUsageCollector mockEstimatedHeapUsageCollector = spy(new StubEstimatedEstimatedHeapUsageCollector());
8787
final NodeUsageStatsForThreadPoolsCollector nodeUsageStatsForThreadPoolsCollector = spy(
88-
new NodeUsageStatsForThreadPoolsCollectorImpl()
88+
new NodeUsageStatsForThreadPoolsCollector()
8989
);
9090
final InternalClusterInfoService clusterInfoService = new InternalClusterInfoService(
9191
settings,

0 commit comments

Comments
 (0)