-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Use the last good NodeUsageStatsForThreadPools when a node returns an error #133896
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
640f0da
8c087f4
94d46a0
d072039
1c6e239
8b374dd
c3d3d3c
20fa020
5fdf7d1
6310e24
355f6d9
3decebd
36ab0fa
ff795ac
d5b17ab
ee9acc5
f8b9b4d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,16 +11,22 @@ | |
|
|
||
| import org.elasticsearch.TransportVersion; | ||
| import org.elasticsearch.action.ActionListener; | ||
| import org.elasticsearch.action.FailedNodeException; | ||
| import org.elasticsearch.action.admin.cluster.node.usage.NodeUsageStatsForThreadPoolsAction; | ||
| import org.elasticsearch.action.admin.cluster.node.usage.TransportNodeUsageStatsForThreadPoolsAction; | ||
| import org.elasticsearch.client.internal.Client; | ||
| import org.elasticsearch.cluster.node.DiscoveryNode; | ||
|
|
||
| import java.util.Arrays; | ||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
| import java.util.concurrent.ConcurrentHashMap; | ||
|
|
||
| /** | ||
| * Collects the thread pool usage stats for each node in the cluster. | ||
| * <p> | ||
| * Results are returned as a map of node ID to node usage stats. | ||
| * Results are returned as a map of node ID to node usage stats. Keeps track of the most recent | ||
| * usage stats for each node, which will be returned in the event of a failure response from that node. | ||
| */ | ||
| public class NodeUsageStatsForThreadPoolsCollector { | ||
| public static final NodeUsageStatsForThreadPoolsCollector EMPTY = new NodeUsageStatsForThreadPoolsCollector() { | ||
|
|
@@ -37,6 +43,8 @@ public void collectUsageStats( | |
| "transport_node_usage_stats_for_thread_pools_action" | ||
| ); | ||
|
|
||
| private final Map<String, NodeUsageStatsForThreadPools> lastNodeUsageStatsPerNode = new ConcurrentHashMap<>(); | ||
|
|
||
| /** | ||
| * Collects the thread pool usage stats ({@link NodeUsageStatsForThreadPools}) for each node in the cluster. | ||
| * | ||
|
|
@@ -47,15 +55,39 @@ public void collectUsageStats( | |
| ClusterState clusterState, | ||
| ActionListener<Map<String, NodeUsageStatsForThreadPools>> listener | ||
| ) { | ||
| var dataNodeIds = clusterState.nodes().getDataNodes().values().stream().map(node -> node.getId()).toArray(String[]::new); | ||
| var dataNodeIds = clusterState.nodes().getDataNodes().values().stream().map(DiscoveryNode::getId).toArray(String[]::new); | ||
| // Discard last-seen values for any nodes no longer present in the cluster state | ||
| lastNodeUsageStatsPerNode.keySet().retainAll(Arrays.asList(dataNodeIds)); | ||
| if (clusterState.getMinTransportVersion().supports(TRANSPORT_NODE_USAGE_STATS_FOR_THREAD_POOLS_ACTION)) { | ||
| client.execute( | ||
| TransportNodeUsageStatsForThreadPoolsAction.TYPE, | ||
| new NodeUsageStatsForThreadPoolsAction.Request(dataNodeIds), | ||
| listener.map(response -> response.getAllNodeUsageStatsForThreadPools()) | ||
| listener.map(this::replaceFailuresWithLastSeenValues) | ||
| ); | ||
| } else { | ||
| listener.onResponse(Map.of()); | ||
| } | ||
| } | ||
|
|
||
| private Map<String, NodeUsageStatsForThreadPools> replaceFailuresWithLastSeenValues( | ||
| NodeUsageStatsForThreadPoolsAction.Response response | ||
| ) { | ||
| final Map<String, NodeUsageStatsForThreadPools> returnedUsageStats = response.getAllNodeUsageStatsForThreadPools(); | ||
| // Update the last-seen usage stats | ||
| this.lastNodeUsageStatsPerNode.putAll(returnedUsageStats); | ||
|
|
||
| if (response.hasFailures() == false) { | ||
| return returnedUsageStats; | ||
| } | ||
|
|
||
| // Add in the last-seen usage stats for any nodes that failed to respond | ||
| final Map<String, NodeUsageStatsForThreadPools> cachedValuesForFailed = new HashMap<>(returnedUsageStats); | ||
| for (FailedNodeException failedNodeException : response.failures()) { | ||
| final var nodeUsageStatsForThreadPools = lastNodeUsageStatsPerNode.get(failedNodeException.nodeId()); | ||
|
||
| if (nodeUsageStatsForThreadPools != null) { | ||
| cachedValuesForFailed.put(failedNodeException.nodeId(), nodeUsageStatsForThreadPools); | ||
|
||
| } | ||
| } | ||
|
||
| return cachedValuesForFailed; | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.