Repository navigation
[9.5] [Fleet] Clear stale inputs_for_versions when a package drops its agent version condition (#306187) - #306739
kibanamachine wants to merge 1 commit into
Conversation
…t version condition (elastic#306187) Closes elastic#305367 ## Summary When a package upgrade drops `conditions.agent.version`, the package policy kept the `inputs_for_versions` cached from the old version. Agents kept receiving the stale per-version inputs, the agent policy stayed flagged `has_agent_version_conditions: true`, and later edits never reached them. - `compilePackagePolicyForVersions` now clears a non-empty `inputs_for_versions` when the package has no agent version condition (feature flag still gates it). It returns `{ cleared }`. - `update()` and `bulkUpdate()` (used by package upgrades) force a full agent version conditions recompute when the cache was cleared. This also self-heals package policies already affected, on their next edit. - Stale `elastic#9.x` variants are removed by the existing reassign and sweep logic once `has_agent_version_conditions` goes false. ## Test plan - [x] Unit tests for the clear / no-op / flag-off cases and the `bulkUpdate` recompute flag - [x] FTR test for upgrade to a package without the condition (not run locally, needs the package registry) 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com> (cherry picked from commit 7cc2e49)
|
Pinging @elastic/fleet (Team:Fleet) |
|
🤖 Jobs for this PR can be triggered through checkboxes. 🚧
ℹ️ To trigger the CI, please tick the checkbox below 👇
|
| clearStaleInputsSpy = jest | ||
| .spyOn(packagePolicyService as any, 'clearStaleInputsForVersions') | ||
| .mockResolvedValue(false); |
There was a problem hiding this comment.
Severity: P3 (Low)
Add a regression test that seeds a stale cache on an already-upgraded policy and exercises update() without mocking the clear. This file-wide stub bypasses that path, and the FTR edit starts after the bulk upgrade has already emptied the cache. Removing the single-update cleanup or its recompute flag would leave the new tests green.
Generated by Libra. React with 👍 or 👎 to give feedback on this comment.
| fields: ['inputs_for_versions'], | ||
| })) | ||
| ); | ||
| const stale = packagePolicySOs.filter( | ||
| (so): so is SavedObject<PackagePolicySOAttributes> => | ||
| !isSavedObjectErrorResult(so) && | ||
| Object.keys(so.attributes?.inputs_for_versions ?? {}).length > 0 |
There was a problem hiding this comment.
Severity: P3 (Low)
Tie the cache clear to the package-policy revision that was checked for conditions. If a concurrent update restores a version-conditioned package and compiles its inputs before this bulkGet, the read picks up that update’s version and the clear succeeds against its valid cache. For template-only conditions, the agent policy can then stop generating variants even though the template still needs them.
Generated by Libra. React with 👍 or 👎 to give feedback on this comment.
| const clearedInputsForVersions = await this.clearStaleInputsForVersions(soClient, [ | ||
| { packagePolicyId: newPolicy.id, packageInfo: pkgInfo, assetsMap }, | ||
| ]); |
There was a problem hiding this comment.
Severity: P2 (Medium)
Return the post-clear saved-object version from update(). newPolicy is fetched before this second write and returned unchanged, so a client that uses the successful PUT response’s version for its next edit gets a 409 even when nobody else edited the policy.
Generated by Libra. React with 👍 or 👎 to give feedback on this comment.
| assetsMap, | ||
| }), | ||
| agentVersionConditionsUnchanged: | ||
| !clearedInputsForVersions && |
There was a problem hiding this comment.
Severity: P3 (Low)
Keep the recompute retryable after the cache is gone. When a same-version edit clears a stale cache but the parent policy bump fails, retrying the edit no longer sees a cache to clear. If the parent had no stored manifest conditions, the retry can succeed while keeping has_agent_version_conditions: true, leaving agents on variants that are no longer needed.
Generated by Libra. React with 👍 or 👎 to give feedback on this comment.
|
|
||
| await retry.tryForTime(20000, async () => { | ||
| const { body } = await supertest | ||
| .get(`/api/fleet/agent_policies/${agentPolicyId}/full`) |
There was a problem hiding this comment.
Severity: P3 (Low)
Check the deployed policy revision when asserting that the agent receives 10m. The unversioned /full endpoint compiles from current saved objects, so this assertion passes even if Fleet Server still has the previous interval. Request /full?revision=… for the new revision or assert on the deployed .fleet-policies document.
Generated by Libra. React with 👍 or 👎 to give feedback on this comment.
💔 Build Failed
Failed CI StepsMetrics [docs]Async chunks
History |
Backport
This will backport the following commits from
mainto9.5:Questions ?
Please refer to the Backport tool documentation