[9.4](backport #7533) Retain output secret when agent update fails - #7545
Conversation
Avoid deleting a newly-created output API key secret when the corresponding agent update returns an error because Elasticsearch may have committed the write before the client observed a timeout. (cherry picked from commit 7fb25fd) # Conflicts: # internal/pkg/policy/policy_output.go # internal/pkg/policy/policy_output_test.go
|
Cherry-pick of 7fb25fd has failed: To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
TL;DRThe current Buildkite unit-test failures are caused by a deterministic test expectation mismatch in Remediation
Investigation detailsRoot CauseThis is a test failure introduced in the backport test content:
That mismatch makes the mock expectation impossible to satisfy. Evidence
Reproduction on the Buildkite commit Verification
Follow-upNo flaky-test signature was identified here; this appears deterministic from a test/branch-behavior mismatch. What is this? | From workflow: PR Buildkite Detective Give us feedback! React with 🚀 if perfect, 👍 if helpful, 👎 if not. |
…rets WriteSecret is not called in prepareElasticsearch on this branch so the Once() expectation caused AssertExpectations to fail. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
What is the problem this PR solves?
When Fleet Server creates an output API key, it stores the encoded key in
.fleet-secretsand then updates the agent document in.fleet-agentswith the secret reference. Elasticsearch can commit that update while the client still receives an error, for example when the request context expires while waiting for the response. This can happen under scale load and was observed during a 100k-agent scale test.The existing error path immediately deleted the secret. In the ambiguous-commit case, this left the agent document pointing at a missing secret and subsequent check-ins failed while resolving the output API key.
How does this PR solve the problem?
Retain the newly created secret whenever the agent update returns an error. This chooses a possible orphaned secret over damaging an agent document with a dangling reference.
A follow-up PR adds conservative, out-of-band reconciliation for these retained candidates.
How to test
go test ./internal/pkg/policy -run TestPolicyOutputESPrepare -count=1mage test:unitmage check:allcurrently reports 58 pre-existing linter findings in unrelated files under the repository's pinned Go/toolchain configuration. The files changed by this PR are clean.Design Checklist
Checklist
CHANGELOG.mdDocumentation and configuration changes are not applicable. The changelog entry is supplied as a fragment.
This is an automatic backport of pull request #7533 done by [Mergify](https://mergify.com).