fix: retry enrollment agent-doc write on ES 409 version conflict#7446
Open
ycombinator wants to merge 3 commits into
Open
fix: retry enrollment agent-doc write on ES 409 version conflict#7446ycombinator wants to merge 3 commits into
ycombinator wants to merge 3 commits into
Conversation
…re-read During high-load enrollment (e.g. 100k agents), a primary shard relocation causes in-flight Create operations to fail with a 409 version_conflict_engine_exception. Fleet Server previously propagated this error immediately as HTTP 500. Fix createFleetAgent to retry up to 3 times on version conflict: - Re-read the agent document after each 409 to determine actual state - If the document is absent: the Create wasn't committed; retry - If the document exists with the same access_api_key_id: our Create succeeded before the conflict was reported; return success - If the document exists with different data: a concurrent writer created it; surface the error Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Contributor
|
This pull request does not have a backport label. Could you fix it @ycombinator? 🙏
|
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What is the problem this PR solves?
During high-load enrollment (e.g. 100k agents), a primary shard relocation on
.fleet-agentscauses in-flightCREATEbulk operations to fail with a 409version_conflict_engine_exception. Fleet Server previously had no retry logic for this case and propagated the error directly as HTTP 500 to the enrolling agent.Observed in a 100k-agent scale test: 661 enrollment requests returned 500 over a ~90-second window following a single shard relocation. p50 request duration was 52s, p99 was 69s (Fleet Server held the connection while retrying the raw ES call rather than resolving the conflict).
How does this PR solve the problem?
Modified
createFleetAgentininternal/pkg/api/handleEnroll.goto retry up to three times on a 409 version conflict. Before each retry the function re-reads the agent document from ES to determine what actually happened:access_api_key_idaccess_api_key_idThe
updateFleetAgentpath (re-enrollment of existing agents) already usesretry_on_conflict: 3at the Elasticsearch bulk-API level and is unaffected.How to test this PR locally
Unit tests cover the two new retry paths:
TestEnrollCreateVersionConflict_DocumentNotFound_Retries– 409 on first Create, document absent on re-read → retries and succeedsTestEnrollCreateVersionConflict_DocumentFound_SameAPIKey_Succeeds– 409 on Create, document found with matchingaccess_api_key_id→ returns success without a second writeDesign Checklist
Checklist
./changelog/fragmentsusing the changelog toolRelated issues