[Fleet] Fix bug with duplicate Fleet Server inputs in Cloud deployments#119925
Conversation
Rework logic around looking up `originalInput` value to handle cases in which `policy_template` is `undefined` on the policy's input object.
|
Pinging @elastic/fleet (Team:Fleet) |
nchaulet
left a comment
There was a problem hiding this comment.
Looks good to me, I tested an upgrade and it seems to fix the issue 🚀 we already have some unit test to that function maybe we can add this scenario
Good call. I will add some tests here tomorrow morning and then this should be good to land. I don't think this will be easy to backport to 7.16.x because of refactoring in this file - are we okay with this or do we need a "manual backport" fix to land in a patch release for 7.16? |
|
Added tests in 98adb6c |
💚 Build Succeeded
Metrics [docs]
History
To update your PR or re-run it, just comment with: cc @kpollich |
|
Waiting on #119971 to land then adding backport label for 7.16 to this |
…ts (elastic#119925) * Fix bug with duplicate Fleet Server inputs Rework logic around looking up `originalInput` value to handle cases in which `policy_template` is `undefined` on the policy's input object. * Set policy_template when possible * Add tests for duplicate input case
…ts (elastic#119925) * Fix bug with duplicate Fleet Server inputs Rework logic around looking up `originalInput` value to handle cases in which `policy_template` is `undefined` on the policy's input object. * Set policy_template when possible * Add tests for duplicate input case
…ts (#119925) (#120014) * Fix bug with duplicate Fleet Server inputs Rework logic around looking up `originalInput` value to handle cases in which `policy_template` is `undefined` on the policy's input object. * Set policy_template when possible * Add tests for duplicate input case Co-authored-by: Kyle Pollich <kyle.pollich@elastic.co>
…ts (#119925) (#120015) * Fix bug with duplicate Fleet Server inputs Rework logic around looking up `originalInput` value to handle cases in which `policy_template` is `undefined` on the policy's input object. * Set policy_template when possible * Add tests for duplicate input case Co-authored-by: Kyle Pollich <kyle.pollich@elastic.co>
…ts (elastic#119925) * Fix bug with duplicate Fleet Server inputs Rework logic around looking up `originalInput` value to handle cases in which `policy_template` is `undefined` on the policy's input object. * Set policy_template when possible * Add tests for duplicate input case
Summary
Fixes #119523
Fixes a bug in our input lookup logic that causes us to create duplicate
fleet-serverinputs on package policies when upgrading policies in Elastic Cloud created in v7.13.The root cause here was our lookup logic in cases where
policy_templatewasundefinedon a package policy inputs. When the "incoming" input has apolicy_templateand we don't find an existing input withpolicy_templateat all (not just a mismatched template), we should use that existing input. This guarantees that policies from Kibana versions prior to #101531 in whichpolicy_templatewas not always provided can still be upgraded.How to test
package_to_package_policy.tsto prevent package policies from havingpolicy_templateset at all.kibana.dev.ymlto mimic the "Elastic Agent on Cloud" policy we use in Cloud:From a clean Elasticsearch snapshot, start up and Kibana and ensure Fleet setup completes successfully
Stash your changes to
package_to_package_policy.tsor uncomment the code above. We just need this commented out during setup to reproduce the issue with the missingpolicy_templatevalue 🙂Grab the ID of the "Fleet Server" package policy under your "Elastic Agent on Cloud" agent policy from the Kibana UI, and run the following in dev tools to confirm that
policy_templateis not set:Update Fleet Server with "Upgrade integration policies" checked from the integration settings page.
Verify that the upgrade was successful, and that only a single
fleet_serverinput is defined on the agent policyRun the same dev tools query as above, and confirm that the policy data now includes the expected
policy_templatevalue.