Skip to content

[HealthAPI] Deterministic shard availability key order#138260

Merged
szybia merged 9 commits intoelastic:mainfrom
madalynbartman:HealthAPI-Deterministic-shard-availability-key-order-#138043
Dec 3, 2025
Merged

[HealthAPI] Deterministic shard availability key order#138260
szybia merged 9 commits intoelastic:mainfrom
madalynbartman:HealthAPI-Deterministic-shard-availability-key-order-#138043

Conversation

@madalynbartman
Copy link
Contributor

@madalynbartman madalynbartman commented Nov 18, 2025

This PR replaces HashMap with LinkedHashMap for deterministic ordering.

Tested by running gradlew :server:test --tests "ShardsAvailabilityHealthIndicatorServiceTests" --no-daemon, gradlew :server:test --tests "Health" --no-daemon, and gradlew check --no-daemon.

Closes #138043

@elasticsearchmachine elasticsearchmachine added needs:triage Requires assignment of a team area label external-contributor Pull request authored by a developer outside the Elasticsearch team v9.3.0 labels Nov 18, 2025
@nielsbauman nielsbauman added :Distributed/Health Issues for the health report API >enhancement labels Nov 19, 2025
@elasticsearchmachine elasticsearchmachine added the Team:Data Management (obsolete) DO NOT USE. This team no longer exists. label Nov 19, 2025
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-data-management (Team:Data Management)

@elasticsearchmachine elasticsearchmachine removed the needs:triage Requires assignment of a team area label label Nov 19, 2025
@nielsbauman
Copy link
Contributor

buildkite test this

@nielsbauman nielsbauman self-assigned this Nov 19, 2025
@szybia szybia changed the title Replace HashMap with LinkedHashMap for deterministic ordering Nov 19, 2025
@szybia
Copy link
Contributor

szybia commented Nov 19, 2025

buildkite test this

@szybia
Copy link
Contributor

szybia commented Nov 19, 2025

hi @madalynbartman, thank you for your interest in Elasticsearch!

i have some questions:

  1. from a quick test i'm not sure whether this achieves what we're setting out to do, with your changes when making requests to a local 3 node cluster i still seem to get different order based on which node i hit. i think needs more research why this is happening even with your changes
  2. i would love to see a test added here to test this behavior
@nielsbauman nielsbauman assigned szybia and unassigned nielsbauman Nov 19, 2025
@madalynbartman
Copy link
Contributor Author

@szybia I added some logic to sort projects by ID and indices by name before processing so they come out in a deterministic order then took a page out of your book and tested on a local three node cluster. Please review the latest commit and let me know if I need to adjust something. Appreciate your feedback and patience!

Was your second point asking me to create a unit test for this? I can give it a shot, but to be honest, Im a bit out of my depth there and might need to learn more about the API before doing so.

@szybia
Copy link
Contributor

szybia commented Nov 21, 2025

@madalynbartman hmmm, i still don't quite think your changes do what i believe we want to do here

i tried this out myself and here's what i came up with: https://github.com/elastic/elasticsearch/compare/main...szybia:elasticsearch:deterministic-shards-health?diff=unified&w

if you agree this solves our problem, maybe you can apply something like my changes into this PR

@madalynbartman
Copy link
Contributor Author

@szybia Tried it out and it worked perfectly. I agree with that approach, thanks for walking me through it. Pushed those changes

@madalynbartman madalynbartman force-pushed the HealthAPI-Deterministic-shard-availability-key-order-#138043 branch from 62861bf to 4bc30d6 Compare November 24, 2025 18:24
@madalynbartman
Copy link
Contributor Author

Can I please get another review when you get a chance? @szybia

Copy link
Contributor

@szybia szybia left a comment

Choose a reason for hiding this comment

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

i believe still a few remnants after your initial approach, unless i'm mistaken 🤔 let me know what you think!

@madalynbartman
Copy link
Contributor Author

@szybia agreed! Just need the LinkedHashMap in getDetails(). Reverted the others

@madalynbartman
Copy link
Contributor Author

@szybia Would you mind taking another look when you get a chance?

@szybia szybia requested a review from Copilot December 2, 2025 10:56
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses deterministic ordering of shard availability keys in the Health API by replacing HashMap with LinkedHashMap. The change ensures that health indicator details are returned with a predictable key order, which is important for API consistency and testing.

Key Changes:

  • Modified ShardsAvailabilityHealthIndicatorService to use LinkedHashMap for deterministic key ordering in health indicator details
  • Added comprehensive test coverage to verify the key order matches the expected sequence

Reviewed changes

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

File Description
ShardsAvailabilityHealthIndicatorService.java Refactored getDetails() method to use LinkedHashMap instead of Map.of() for deterministic key ordering
ShardsAvailabilityHealthIndicatorServiceTests.java Added test case to verify deterministic ordering of shard availability keys

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

@samxbr samxbr left a comment

Choose a reason for hiding this comment

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

LGTM, we can merge after the change log is added and CI is passed. Thank you for contributing to Elasticsearch!

@madalynbartman
Copy link
Contributor Author

Added change log

@szybia
Copy link
Contributor

szybia commented Dec 3, 2025

buildkite test this

@szybia szybia enabled auto-merge (squash) December 3, 2025 15:09
@szybia szybia merged commit 5f78985 into elastic:main Dec 3, 2025
36 checks passed
@szybia
Copy link
Contributor

szybia commented Dec 3, 2025

thank you for contributing to Elasticsearch!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

:Distributed/Health Issues for the health report API >enhancement external-contributor Pull request authored by a developer outside the Elasticsearch team Team:Data Management (obsolete) DO NOT USE. This team no longer exists. v9.3.0

6 participants