Avoid uninstalling and re-installing service components on policy change#11740
Conversation
|
This pull request does not have a backport label. Could you fix it @ycombinator? 🙏
|
84a4523 to
1951fec
Compare
|
Pinging @elastic/elastic-agent-control-plane (Team:Elastic-Agent-Control-Plane) |
|
Dropping the output ID makes sense to me, but I think if you do a policy assignment the input ID also changes, which would cause an uninstall and reinstall. Does the policy reassignment case work properly for tamper protected agents? Or is this only handling the case where the output is changed within the same policy? |
As discussed in today's meeting, the component ID uses the input type (not input ID) so, with the change in this PR, we should still prevent an uninstall and reinstall. |
Yes, it does. I forgot that that's how I'd tested this PR to begin with. I even added manual testing steps to the PR's description. 🤦 I will test the upgrade scenario next. |
Okay, so upgrading works in that nothing is broken after upgrade. Here's the output of BeforeDuringAfter |
|
What's the right additional testing to add for this? It looks correct by inspection, but I think we should add something proving it does what we think. If we could get a simulated policy reassignment (input If policy reassignment always fails without this change, that's a test case that is missing from the endpoint integration tests, so we could add that. I also don't think we have a test that does an upgrade with defend installed but that is even heavier, though we have had lots of problems around this discovered in the field so maybe worth it. |
e892133 to
6fadd3c
Compare
Added a unit test case for input ID change to A unit test that tests just changing the output already exists in But I added additional assertions for that test case to make sure no components were added, removed, or updated in the component model as a result of such a change: 4e352a7#diff-21de8fb82a5ebccaa0ca3afb0cb8bfbe10d5b8f920021785c2d485ee35a3556cR225-R227 |
Added in 8a1a8c3 |
13f5ff1 to
8a1a8c3
Compare
|
changelog/fragments/1765439361-service-component-avoid-stop-start.yaml
Outdated
Show resolved
Hide resolved
0bac7f9 to
f70ec1f
Compare
…essful policy reassignment
f70ec1f to
284dcb8
Compare
|
@cmacknz Thanks for the review. I see you added the |
💛 Build succeeded, but was flaky
Failed CI StepsHistory
cc @ycombinator |
…nge (#11740) * Add UsesCommandRuntime and UsesServiceRuntime methods on Component * Use new methods * Add test case for only output being changed on service component * Implement logic to not remove and add same service component * Adding CHANGELOG fragment * Improve comment * Fix logic location * Update unit test * Update service component naming * Refactor: extract logic into helper method * Relocate unit test and add lots of cases * Remove unnecessary code * Clarify comments * Remove unnecessary unit test * Undo unnecessary changes * Update component ID in integration test * Add assertions on lengths of components added, removed, updated * Add test case for only input ID changing * Add integration test: TestPolicyReassignWithTamperProtectedEndpoint * Update replace in go.mod * Bump up context timeout and use for entire test * Define fixture * Fix syntax errors * Fix installOpts * Only cleanup Endpoint using first policy's uninstall token until successful policy reassignment * Clarify log message * Upgrade endpoint package version * Use exec.CommandContext and separate out args * Compare Endpoint policy IDs * Use agentID from enrollment response * Install Elastic Defend in second policy * Add endpoint cleanup after reassigning policy * Fixing log messages * Give Endpoint time to receive reassigned policy * Updating dependency version * Adding log statements * Remove replace * Remove duplicate CHANGELOG fragment * Remove PID checks (cherry picked from commit c8deb6d)
…nge (#11740) (#12100) * Add UsesCommandRuntime and UsesServiceRuntime methods on Component * Use new methods * Add test case for only output being changed on service component * Implement logic to not remove and add same service component * Adding CHANGELOG fragment * Improve comment * Fix logic location * Update unit test * Update service component naming * Refactor: extract logic into helper method * Relocate unit test and add lots of cases * Remove unnecessary code * Clarify comments * Remove unnecessary unit test * Undo unnecessary changes * Update component ID in integration test * Add assertions on lengths of components added, removed, updated * Add test case for only input ID changing * Add integration test: TestPolicyReassignWithTamperProtectedEndpoint * Update replace in go.mod * Bump up context timeout and use for entire test * Define fixture * Fix syntax errors * Fix installOpts * Only cleanup Endpoint using first policy's uninstall token until successful policy reassignment * Clarify log message * Upgrade endpoint package version * Use exec.CommandContext and separate out args * Compare Endpoint policy IDs * Use agentID from enrollment response * Install Elastic Defend in second policy * Add endpoint cleanup after reassigning policy * Fixing log messages * Give Endpoint time to receive reassigned policy * Updating dependency version * Adding log statements * Remove replace * Remove duplicate CHANGELOG fragment * Remove PID checks (cherry picked from commit c8deb6d) Co-authored-by: Shaunak Kashyap <ycombinator@gmail.com>
I think we need to release this in 9.3 first, and if there are no unintended problems once we get through the 9.3 testing cycle we can backport. The difference between 9.3 and 9.2+9.1 is time to release, if we had backported to the already released minors this would have released very quickly after merge with no soak time. |
@cmacknz I think we're good to backport this PR now? |
|
Possibly, 9.3.0 has not been available for that long yet. Unless someone asks us to backport this I would leave it in 9.3 only to be conservative. |
What does this PR do?
This PR identifies Service Runtime components with only their input type; the output ID is not longer used.
Why is it important?
Service Runtime components are intended to be kept running (via a service) for as long as possible. We should only install/start or uninstall/stop them if they are being explicitly added or removed, respectively, from the component model. If only their configuration is being updated, we should keep the component running.
If a component's ID changes between the last and current component models, Elastic Agent will ask the component's service to uninstall and then reinstall itself. Prior to this PR, service components' ID were determined by their input type and output ID. Therefore, if a service component's output were changed, it would cause the service to be uninstall and then reinstalled. This is undesirable behavior, as services should be kept running as long as possible.
With the changes in this PR, we no longer consider the output ID when generating service components' IDs. If a service component's output is changed, it's ID remains the same between the last and current component models. Elastic Agent does not uninstall and reinstall the component's service but simply passes the configuration change to it (which it was doing prior to this PR anyway).
Checklist
I have made corresponding changes to the documentationI have made corresponding change to the default configuration files./changelog/fragmentsusing the changelog toolI have added an integration test or an E2E testDisruptive User Impact
None.
How to test this PR locally
Policy reassign does not uninstall/reinstall Endpoint
default: containing only thesystemintegrationtp-es: containing the Elastic Defend integration, with tamper protection enabled, and using the Elasticsearch output.tp-ls: containing the Elastic Defend integration, with tamper protection enabled, and using the Logstash output. Note that you will need to create the Logstash output in Fleet > Settings.tp-espolicy and verify the agent is healthy and shipping data.tp-lspolicy.uninstall endpoint service./opt/Elastic/Endpoint/state/log/on Linux) and make sure that Endpoint has connected to Logstash (or has attempted to and failed if there is no actual Logstash endpoint listening).Removing Endpoint from policy uninstalls Endpoint
defaultpolicy.stopping endpoint service runtime, followed byuninstall endpoint service, followed byStopped: endpoint service runtime.Related issues
Questions to ask yourself