Skip to content

Conversation

mergify[bot]
Copy link
Contributor

@mergify mergify bot commented Sep 18, 2025

PR 5/6

  • Enhancement

What does this PR do?

  • Updates the download step to return path after download succeeds even in error cases
  • Adds deferred cleanup process in the upgrade function to cleanup download and extracted agent versioned home paths
  • Updates error handling sequence in the upgrade function to add download and versioned home paths in the cleanup list
  • Adds relevant tests

Why is it important?

  • Currently http and fs downloaders cleanup if they fail however if there is any other error (verifier errors) in the download process, the agent does not cleanup the downloaded artifacts
  • The upgrade process reverts the symlink changes and cleans up the new versioned home only after the symlink switch happens. If anything in between the downloaders and symlink switch fails, the agent does not clean up anything.

Checklist

  • I have read and understood the pull request guidelines of this project.
  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • [ ] I have made corresponding changes to the documentation
  • [ ] I have made corresponding change to the default configuration files
  • I have added tests that prove my fix is effective or that my feature works
  • [ ] I have added an entry in ./changelog/fragments using the changelog tool
  • [ ] I have added an integration test or an E2E test

Disruptive User Impact

none

How to test this PR locally

  • Run the upgrade_test tests
  • Build the agent for windows, mac and linux
  • Try to upgrade from one version to another without sha512 and force verification failure and validate that the downloads directory is cleaned up.
  • The way I triggered the second cleanup scenario was by filling up the disk space just enough so that the agent can partially extract the downloaded archive but fails midway. Then I validated that the versioned home for the new agent is removed along with the downloads in the initial agent's versioned home directory.

Related issues


This is an automatic backport of pull request #9386 done by [Mergify](https://mergify.com).

* enhancement(5235): added comments describing updates in error handling. returning path in error cases if the download is completed

* enhancement(5235): added wrapper var for verifier
constructor in download step to improve testability

* enhancement(5235): added test for downloadArtifact
verifier errors

* enhancement(5235): addded cleanupPaths slice. added deferred call to remove paths in the cleanupPaths slice

* enhancement(5235): add archive and hash path to cleanup paths after artifact download

* enhancement(5235): update error handling after unpack. add new versioned home to cleanup paths

enhancement(5235): move newHome declaration

* enhancement(5235): added upgrade cleanup test

* enhancement(5235): added changelog fragment

enhancement(5235): updated changelog fragment

* enhancement(5235): fix errors in step_download after rebase

* enhancement(5235): fix error in step_download_test after rebase

* enhancement(5235): refactor disk space error check and path cleanup into one deferred call

* enhancement(5235): refactored verifier factory and updated relevant download tests

* enhancement(5235): removed separate test for cleanup, added cleanup checks in error handling test

* enhancement(5235): changed function name in verifier

* enhancement(5235): using AddHashExtension instead of hard coded hash extension string in upgrader

(cherry picked from commit ab23962)

# Conflicts:
#	internal/pkg/agent/application/upgrade/upgrade.go
#	internal/pkg/agent/application/upgrade/upgrade_test.go
@mergify mergify bot requested a review from a team as a code owner September 18, 2025 16:56
@mergify mergify bot added backport conflicts There is a conflict in the backported pull request labels Sep 18, 2025
@mergify mergify bot requested review from blakerouse and straistaru and removed request for a team September 18, 2025 16:56
@mergify mergify bot added the backport label Sep 18, 2025
Copy link
Contributor Author

mergify bot commented Sep 18, 2025

Cherry-pick of ab23962 has failed:

On branch mergify/bp/8.18/pr-9386
Your branch is up to date with 'origin/8.18'.

You are currently cherry-picking commit ab23962a0.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --skip" to skip this patch)
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Changes to be committed:
	new file:   changelog/fragments/1755268130-cleanup-downloads-directory-and-the-new-versioned-home-if-upgrade-fails.yaml
	modified:   internal/pkg/agent/application/upgrade/artifact/download/verifier.go
	modified:   internal/pkg/agent/application/upgrade/step_download.go
	modified:   internal/pkg/agent/application/upgrade/step_download_test.go

Unmerged paths:
  (use "git add <file>..." to mark resolution)
	both modified:   internal/pkg/agent/application/upgrade/upgrade.go
	both modified:   internal/pkg/agent/application/upgrade/upgrade_test.go

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

@github-actions github-actions bot added the Team:Elastic-Agent-Control-Plane Label for the Agent Control Plane team label Sep 18, 2025
@elasticmachine
Copy link
Collaborator

Pinging @elastic/elastic-agent-control-plane (Team:Elastic-Agent-Control-Plane)

Copy link
Contributor Author

mergify bot commented Sep 22, 2025

This pull request has not been merged yet. Could you please review and merge it @kaanyalti? 🙏

@ebeahan
Copy link
Member

ebeahan commented Sep 23, 2025

@kaanyalti can you take a look at this backport?

@kaanyalti
Copy link
Contributor

@kaanyalti can you take a look at this backport?

@ebeahan I'm going through all the backports today

@kaanyalti kaanyalti removed the conflicts There is a conflict in the backported pull request label Sep 24, 2025
Copy link

@elasticmachine
Copy link
Collaborator

💛 Build succeeded, but was flaky

Failed CI Steps

History

cc @kaanyalti

@kaanyalti kaanyalti merged commit b1d0474 into 8.18 Sep 24, 2025
19 checks passed
@kaanyalti kaanyalti deleted the mergify/bp/8.18/pr-9386 branch September 24, 2025 18:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport Team:Elastic-Agent-Control-Plane Label for the Agent Control Plane team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants