Skip to content

Commit

Permalink
[8.x] [EDR Workflows] Download multiple agent versions (#197469) (#19…
Browse files Browse the repository at this point in the history
…7674)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[EDR Workflows] Download multiple agent versions
(#197469)](#197469)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Tomasz
Ciecierski","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-10-24T15:10:19Z","message":"[EDR
Workflows] Download multiple agent versions
(#197469)","sha":"f3c29f82d6bb2fa2c823ae44ad980f4242da65ec","branchLabelMapping":{"^v9.0.0$":"main","^v8.17.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","Team:Defend
Workflows","v8.16.0","backport:version","v8.17.0"],"title":"[EDR
Workflows] Download multiple agent
versions","number":197469,"url":"https://github.com/elastic/kibana/pull/197469","mergeCommit":{"message":"[EDR
Workflows] Download multiple agent versions
(#197469)","sha":"f3c29f82d6bb2fa2c823ae44ad980f4242da65ec"}},"sourceBranch":"main","suggestedTargetBranches":["8.16","8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/197469","number":197469,"mergeCommit":{"message":"[EDR
Workflows] Download multiple agent versions
(#197469)","sha":"f3c29f82d6bb2fa2c823ae44ad980f4242da65ec"}},{"branch":"8.16","label":"v8.16.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.x","label":"v8.17.0","branchLabelMappingKey":"^v8.17.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Tomasz Ciecierski <[email protected]>
  • Loading branch information
kibanamachine and tomsonpl authored Oct 24, 2024
1 parent 9c788b3 commit fb9e553
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,18 @@ const downloadAndStoreElasticAgent = async (
): Promise<void> => {
const versionsToDownload = getVersionsToDownload(version);

// Although we have a list of versions to try downloading, we only need to download one, and will return as soon as it succeeds.
// Download all the versions in the list
for (const versionToDownload of versionsToDownload) {
try {
const { url } = await getAgentDownloadUrl(versionToDownload, closestMatch, log);
const fileName = `${getAgentFileName(versionToDownload)}.tar.gz`;

await downloadAndStoreAgent(url, fileName);
log.info(`Successfully downloaded and stored version ${versionToDownload}`);
return; // Exit once successful
} catch (error) {
log.error(`Failed to download or store version ${versionToDownload}: ${error.message}`);
}
}

log.error(`Failed to download agent for any available version: ${versionsToDownload.join(', ')}`);
};

export const agentDownloaderRunner: RunFn = async (cliContext) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,14 @@ class AgentDownloadStorage extends SettingsStorage<AgentDownloadStorageSettings>

await handleProcessInterruptions(
async () => {
const { body } = await nodeFetch(agentDownloadUrl);
await finished(body.pipe(outputStream));
try {
const { body } = await nodeFetch(agentDownloadUrl);
await finished(body.pipe(outputStream));
} catch (error) {
this.log.error(`Error during download attempt ${attempt}: ${error.message}`);
// Ensure any errors here propagate and trigger retry
throw error;
}
},
() => fs.unlinkSync(newDownloadInfo.fullFilePath) // Clean up on interruption
);
Expand Down

0 comments on commit fb9e553

Please sign in to comment.