[9.5](backport #7688) fix: ignore missing .fleet-agents index on enrollment _refresh path - #7690
Conversation
…th (#7688) * fix: close enroll search refresh response body after reading error When the pre-enrollment _refresh call returns a non-2xx response, the body was closed before String() was called to format the error message, producing "error reading response body: http: read on closed response body" instead of the actual ES error. Defer the close so String() can read the body first. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix: ignore missing .fleet-agents index on enrollment _refresh On a fresh Serverless project .fleet-agents does not exist when the first enrollment attempt arrives. The pre-enrollment _refresh call introduced in #7662 returned HTTP 404, which caused failQueue to be called and every enrollment to fail permanently — a deadlock where the index is never created because enrollment always fails before the first write lands. Pass ignore_unavailable=true to the refresh request so a missing index is treated as a no-op (HTTP 200, zero shards). The first enrollment proceeds to the msearch, writes the agent document (ES auto-creates .fleet-agents-7 with the correct alias and mappings via the system index descriptor), and subsequent retries with the same enrollment_id deduplicate correctly. Also fix the body-close ordering introduced in #7662: Body.Close() was called before String() in the error path, hiding the real ES error behind "read on closed response body". Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fixup: address review feedback — close refresh body immediately, add missing-index integration test, remove unneeded changelog Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com> (cherry picked from commit 9ab9134)
This comment has been minimized.
This comment has been minimized.
TL;DRThis build failed in two places: the benchmark step still lacks first-failure context (same limitation as the prior detective note), and the new E2E failure is in long-running Remediation
Investigation detailsRoot CauseThe failing PR (
No E2E test code was modified in this PR, and the E2E failures occurred in tests with known high runtime variance:
Related flaky tracking exists for this suite's OpAMP path:
Evidence
Verification
Follow-upIf reruns keep failing, collect full failing sections (or artifact excerpts) for:
What is this? | From workflow: PR Buildkite Detective Give us feedback! React with 🚀 if perfect, 👍 if helpful, 👎 if not. |
What is the problem this PR solves?
Fleet Server PR #7662 introduced a pre-enrollment
_refreshcall on.fleet-agentsto make prior writes visible before the deduplication msearch inkQueueEnrollSearch. On a fresh Serverless project the index does not yet exist, so_refreshreturns HTTP 404. This causesfailQueueto be called and every enrollment attempt to fail permanently — a deadlock where the index is never created because enrollment always fails before the first write can land.Only enrollments that include
enrollment_idare affected (they are routed throughkQueueEnrollSearch). Horde always setsenrollment_id; Elastic Agent may also set it. Agents that omitenrollment_idbypass this path and can enroll successfully, but they do not unblock the deadlocked agents.Discovered while investigating why Horde project drones never come online in Serverless staging (elastic/horde#569). ECH drones were unaffected because the Horde k8s smoke test deploys its own older fleet-server binary that predates #7662.
How does this PR solve the problem?
Two fixes:
1. Pass
ignore_unavailable=trueto the refresh request.When
.fleet-agentsdoes not exist the refresh becomes a no-op (HTTP 200, zero shards) instead of a fatal 404. The first enrollment proceeds to the msearch, the agent document is written, and ES auto-creates.fleet-agents-7with the correct alias and mappings via its system index descriptor. Subsequent retries with the sameenrollment_idthen deduplicate correctly.2. Fix body-close ordering (also introduced in #7662).
refreshResp.Body.Close()was called beforerefreshResp.String()in the error path, causing every enrollment failure on this path to be reported as:instead of the actual ES error. Changed to
defer refreshResp.Body.Close().How to test this PR locally
.fleet-agentsindex).enrollment_idset..fleet-agents-7is created with the.fleet-agentsalias.enrollment_idreturnsErrEnrollDuplicate.Design Checklist
Checklist
./changelog/fragmentsusing the changelog toolRelated issues
_refreshcall)This is an automatic backport of pull request fix: ignore missing
.fleet-agentsindex on enrollment_refreshpath #7688 done by Mergify.