Added skip audit/unenroll flag to uninstall command#6206
Added skip audit/unenroll flag to uninstall command#6206michalpristas merged 21 commits intoelastic:mainfrom
Conversation
|
This pull request does not have a backport label. Could you fix it @Rohit-code14? 🙏
|
|
|
|
/test |
There was a problem hiding this comment.
@Rohit-code14 Could you please add tests relevant to what you are doing here? One suggestion is to inject notifyFleetAuditUninstall function. You can create a function type and create a mock with it using mockery which you can use in your test.
Hi @kaanyalti , Even if we inject notifyFleetAuditUninstall into Uninstall and try mocking the same to test it. To test it we need to directly invoke Uninstall function by passing the mock notify function during the test run. Which is not hard to do. I think we can refactor the pre-validations that are done to before invoking notifyFleetAuditUninstall function into a separate function and have a test case that mocks the new refactored function.
Please share your opinion on this |
|
@Rohit-code14 I am having a hard time visualizing your suggestion based on the example you provided. Can you either implement your suggestion or provide a more concrete example so it is clearer? |
@kaanyalti I have added changes and testcase, kindly review the same. |
kaanyalti
left a comment
There was a problem hiding this comment.
Tested this on mac and linux, works well. Changes look good to me.
|
/test |
|
Hi @kaanyalti , I cannot see the reasons for these failures, Can you please help me with this? |
Done! |
|
/test |
Should anything be done from my side for this? |
|
@Rohit-code14 I'm going to look into why sonarqube is complaining, you may have to increase code coverage, although right now what you have implemented looks good to me. |
Okay let me know once you have checked the it. |
|
Please trigger tests for this. |
|
/test |
|
@pkoutsovasilis sorry to ping you again. One of the buildkite testcase failed. I have pulled changes from main. So please retrigger the tests once. And also the sonarqube coverage test failed once again how can we proceed with it? |
No worries at all, and sorry for this getting stuck. We are currently discussing with the team to make the SonarQube step a non-required one, so hopefully, once that change is in place, your PR will be merged smoothly. I’ll retrigger the tests now. 🙂 |
|
/test |
Thanks @pkoutsovasilis . I am very much excited as it's my first PR. Looking forward on merging this. |
michalpristas
left a comment
There was a problem hiding this comment.
thanks for addressing changes in test code, looks much better now
|
buildkite test it |
|
|
merged, many thanks for your contribution @Rohit-code14 |
* Added skip audit/unenroll flag to uninstall command * Added tests for skip-fleet-audit flag * Added tests for skip-fleet-audit flag * Added tests for skip-fleet-audit flag * ran mage fmt * Test all combinations for which fleet audit/unenroll will be skipped --------- Co-authored-by: Michal Pristas <michal.pristas@gmail.com> (cherry picked from commit 41e7499)
@kaanyalti @pkoutsovasilis @michalpristas |
* Added skip audit/unenroll flag to uninstall command * Added tests for skip-fleet-audit flag * Added tests for skip-fleet-audit flag * Added tests for skip-fleet-audit flag * ran mage fmt * Test all combinations for which fleet audit/unenroll will be skipped --------- Co-authored-by: Michal Pristas <michal.pristas@gmail.com> (cherry picked from commit 41e7499) Co-authored-by: Rohit <59366992+Rohit-code14@users.noreply.github.com>


What does this PR do?
Added a flag to skip fleet audit/unenroll while uninstalling elastic-agent.
Why is it important?
While uninstalling elastic-agent it tries to notify fleet server about the uninstall. But in somecases users might know that the fleet server is unreachable and this notification logs multiple failures continuously. Therefore having an option to skip this would enhance the end user experience.
Checklist
[ ] I have made corresponding change to the default configuration files./changelog/fragmentsusing the changelog tool[ ] I have added an integration test or an E2E testDisruptive User Impact
No disruptive user impact
How to test this PR locally
SNAPSHOT=true PLATFORMS=linux/arm64 PACKAGES=tar.gz mage -v packagesudo elastic-agent uninstall[== ] notify Fleet: network error: fail to notify audit/unenroll on fleet-server: all hosts failed: requester 0/1 to host https://192.168.1.10:8220/ errored: Post "https://192.168.1.10:8220/api/fleet/agents/a4888371-ef7b-4cc6-8df7-cc92b6c25990/audit/unenroll?": dial tcp 192.168.1.10:8220: connect:sudo elastic-agent uninstall --skip-fleet-audit. The audit/unenroll call will be skipped and agent uninstall will happen without any errors.Related issues