-
Notifications
You must be signed in to change notification settings - Fork 25.3k
Create a new monitor for node-level write load #131560
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
Merged
DiannaHohensee
merged 5 commits into
elastic:main
from
DiannaHohensee:2025/07/18/node-thread-pool-monitor
Jul 22, 2025
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a1899a3
Create a new monitor for node-level write load
DiannaHohensee 9bcf8ab
[CI] Auto commit changes from spotless
14454c1
rename class
DiannaHohensee 19460b5
Merge branch 'main' into 2025/07/18/node-thread-pool-monitor
DiannaHohensee 8bd66fe
comment touch up
DiannaHohensee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
88 changes: 88 additions & 0 deletions
88
...ava/org/elasticsearch/cluster/routing/allocation/NodeUsageStatsForThreadPoolsMonitor.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the "Elastic License | ||
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
package org.elasticsearch.cluster.routing.allocation; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.elasticsearch.action.ActionListener; | ||
import org.elasticsearch.cluster.ClusterInfo; | ||
import org.elasticsearch.cluster.ClusterInfoService; | ||
import org.elasticsearch.cluster.ClusterState; | ||
import org.elasticsearch.cluster.routing.RerouteService; | ||
import org.elasticsearch.common.Priority; | ||
import org.elasticsearch.common.settings.ClusterSettings; | ||
import org.elasticsearch.gateway.GatewayService; | ||
|
||
import java.util.function.LongSupplier; | ||
import java.util.function.Supplier; | ||
|
||
/** | ||
* Monitors the node-level thread pool usage across the cluster and initiates (coming soon) a rebalancing round (via | ||
* {@link RerouteService#reroute}) whenever a node crosses the node-level write load thresholds. | ||
* | ||
* TODO (ES-11992): implement | ||
*/ | ||
public class NodeUsageStatsForThreadPoolsMonitor { | ||
private static final Logger logger = LogManager.getLogger(NodeUsageStatsForThreadPoolsMonitor.class); | ||
private final WriteLoadConstraintSettings writeLoadConstraintSettings; | ||
private final Supplier<ClusterState> clusterStateSupplier; | ||
private final LongSupplier currentTimeMillisSupplier; | ||
private final RerouteService rerouteService; | ||
|
||
public NodeUsageStatsForThreadPoolsMonitor( | ||
ClusterSettings clusterSettings, | ||
LongSupplier currentTimeMillisSupplier, | ||
Supplier<ClusterState> clusterStateSupplier, | ||
RerouteService rerouteService | ||
) { | ||
this.writeLoadConstraintSettings = new WriteLoadConstraintSettings(clusterSettings); | ||
this.clusterStateSupplier = clusterStateSupplier; | ||
this.currentTimeMillisSupplier = currentTimeMillisSupplier; | ||
this.rerouteService = rerouteService; | ||
} | ||
|
||
/** | ||
* Receives a copy of the latest {@link ClusterInfo} whenever the {@link ClusterInfoService} collects it. Processes the new | ||
* {@link org.elasticsearch.cluster.NodeUsageStatsForThreadPools} and initiates rebalancing, via reroute, if a node in the cluster | ||
* exceeds thread pool usage thresholds. | ||
*/ | ||
public void onNewInfo(ClusterInfo clusterInfo) { | ||
final ClusterState state = clusterStateSupplier.get(); | ||
if (state.blocks().hasGlobalBlock(GatewayService.STATE_NOT_RECOVERED_BLOCK)) { | ||
logger.debug("skipping monitor as the cluster state is not recovered yet"); | ||
return; | ||
} | ||
|
||
if (writeLoadConstraintSettings.getWriteLoadConstraintEnabled() == WriteLoadConstraintSettings.WriteLoadDeciderStatus.DISABLED) { | ||
logger.trace("skipping monitor because the write load decider is disabled"); | ||
return; | ||
} | ||
|
||
logger.trace("processing new cluster info"); | ||
|
||
boolean reroute = false; | ||
String explanation = ""; | ||
final long currentTimeMillis = currentTimeMillisSupplier.getAsLong(); | ||
|
||
// TODO (ES-11992): implement | ||
|
||
if (reroute) { | ||
logger.debug("rerouting shards: [{}]", explanation); | ||
rerouteService.reroute("disk threshold monitor", Priority.NORMAL, ActionListener.wrap(ignored -> { | ||
final var reroutedClusterState = clusterStateSupplier.get(); | ||
|
||
// TODO (ES-11992): implement | ||
|
||
}, e -> logger.debug("reroute failed", e))); | ||
} else { | ||
logger.trace("no reroute required"); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be more specific, for example WriteLoadMonitor. I think it should monitor write-load in general, which can be a set of different metrics - write-thread-pool utilization, index/shard write load.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, thanks. I've renamed it
WriteLoadConstraintMonitor
, to follow the existing naming pattern we have.NodeUsageStatsForThreadPools
has been used generically for the thread pool usage, even though we only care about write load right now, because we'll presumably have search load in future. But I expect any monitoring added for search in future should go into a separate monitor class for maintainability reasons.