Skip to content

Fetch node and shard heap metrics in a single call - #158087

Merged
surya-estc merged 8 commits into
elastic:mainfrom
surya-estc:allocation/consolidate_heap_usage_collector_methods
Aug 31, 2026
Merged

Fetch node and shard heap metrics in a single call#158087
surya-estc merged 8 commits into
elastic:mainfrom
surya-estc:allocation/consolidate_heap_usage_collector_methods

Conversation

@surya-estc

@surya-estc surya-estc commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Unifies node and shard heap metric collection so both estimates derive from one stateless memory snapshot.

Changes:

  • Adds a combined heap-usage result and collector API.
  • Snapshots mutable shard metrics before calculating estimates.
  • Updates refresh logic, integrations, and tests.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
server/.../EstimatedHeapUsageCollector.java Unifies collector methods.
server/.../EstimatedHeapUsageStats.java Adds combined immutable result.
server/.../InternalClusterInfoService.java Fetches both estimates together.
server/.../InternalClusterInfoServiceSchedulingTests.java Updates scheduling assertions.
server/.../InternalClusterInfoServiceRefreshTests.java Tests combined refresh handling.
server/.../IndexShardIT.java Updates test collector implementation.
x-pack/.../StatelessHeapUsageReader.java Delegates combined collection.
x-pack/.../StatelessMemoryMetricsService.java Calculates from copied shard metrics.
x-pack/.../StatelessHeapUsageReaderTests.java Tests reader delegation and failures.
Suppressed comments (1)

x-pack/plugin/stateless/src/main/java/org/elasticsearch/xpack/stateless/memory/StatelessMemoryMetricsService.java:690

  • This new public method needs Javadoc under the repository's public-method documentation rule. Document that synchronization captures a field-consistent copy for the combined estimate snapshot; adding @Override also makes its relationship to Object.clone() explicit.
        public synchronized ShardMemoryMetrics clone() {

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

* Computes node and shard heap usage estimates from the same snapshot of shard memory metrics.
*/
public EstimatedHeapUsageStats getEstimatedHeapUsageStats(ClusterState clusterState) {
Map<ShardId, ShardMemoryMetrics> shardMemoryMetricsSnapshot = copyShardMemoryMetrics();

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@surya-estc
surya-estc marked this pull request as ready for review August 29, 2026 00:04
@surya-estc
surya-estc requested a review from nicktindall August 29, 2026 00:04
@surya-estc surya-estc added >non-issue :Distributed/Distributed A catch all label for anything in the Distributed Area. Please avoid if you can. Team:Distributed Meta label for distributed team. labels Aug 29, 2026
@elasticsearchmachine

Copy link
Copy Markdown
Collaborator

Pinging @elastic/es-distributed (Team:Distributed)

@nicktindall nicktindall left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, only minor comments

Map<ShardId, ShardMemoryMetrics> snapshot = new HashMap<>();
shardMemoryMetrics.forEach((shardId, shardMemoryMetric) -> snapshot.put(shardId, shardMemoryMetric.snapshot()));
return snapshot;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm mildly concerned about this. It's right to take the snapshot so we don't get half-updated metrics for any shards, but I asked Claude and it said it'd be a ~12MB allocation for a 100k shard cluster. I don't think that's crazy large, and I imagine a cluster of that size would be on relatively large nodes, so probably not worth worrying about. I think we'll be able to remove it when we implement elastic/elasticsearch-team#4572 in any case. I checked in serverless and it's unlikely to be an issue for any of the existing large projects.

@surya-estc
surya-estc merged commit 22d6425 into elastic:main Aug 31, 2026
39 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

:Distributed/Distributed A catch all label for anything in the Distributed Area. Please avoid if you can. >non-issue Team:Distributed Meta label for distributed team. v9.6.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants