[Security Solution][Endpoint] New enroll endpoint host function CI specific for Cypress tests to use cached agent files#171399
Conversation
ashokaditya
left a comment
There was a problem hiding this comment.
Tested it out and it works nicely! I've few suggestions and nits but this is good to 🚢 !
| // Check if agent file is already on disk before downloading it again | ||
| agentDownload = isAgentDownloadFromDiskAvailable(agentFileName); | ||
|
|
||
| // If it has not been already dowloaded, it has to be donwnloaded. |
There was a problem hiding this comment.
nit:
| // If it has not been already dowloaded, it has to be donwnloaded. | |
| // If it has not been already downloaded, it should be downloaded. |
| log, | ||
| kbnClient, | ||
| }) | ||
| : await createAndEnrollEndpointHost({ |
There was a problem hiding this comment.
You can now remove the CI check and dependent code in createAndEnrollEndpointHost that also has a vagrant VM creation logic
There was a problem hiding this comment.
Yes, I added a note in the description about doing that in a follow up pr.
| export const downloadAndStoreAgent = async ( | ||
| agentDownloadUrl: string | ||
| agentDownloadUrl: string, | ||
| agentFileName?: string |
There was a problem hiding this comment.
nit: please also add the new param to JSDoc above
| `UNSUPPORTED_ARCHITECTURE_${process.arch}`; | ||
| const fileNameNoExtension = `elastic-agent-${agentVersion}-linux-${downloadArch}`; | ||
|
|
||
| const fileNameNoExtension = getAgentFileName(agentVersion); |
There was a problem hiding this comment.
nit:
| const fileNameNoExtension = getAgentFileName(agentVersion); | |
| const fileNameWithoutExtension = getAgentFileName(agentVersion); |
…int_host_using_cached_agent_installers
|
packer_cache.sh build didn't have any issues. The new image can be tested by replacing |
|
Pinging @elastic/security-defend-workflows (Team:Defend Workflows) |
|
@elasticmachine merge upstream |
…int_host_using_cached_agent_installers
tomsonpl
left a comment
There was a problem hiding this comment.
Hey, interesting changes, thanks for investing time and efforts into fixing this issue 👍
I left a few comments, but in general lgtm 👍
| node scripts/es snapshot --download-only --base-path "$ES_CACHE_DIR" --version "$version" | ||
| done | ||
|
|
||
| for version in $(cat versions.json | jq -r '.versions[].version'); do |
There was a problem hiding this comment.
Do you think combining two for loops into one would be possible? What are the beenfits of doing it separately?
There was a problem hiding this comment.
Yeah I think should be okay to download ES snapshot and agent in the same loop.
There was a problem hiding this comment.
I went for that path in order to not block the existing code path if something fails with the elastic agent download
| log.info(`Creating endpoint host, attempt ${retryAttempt}`); | ||
| const newHost = process.env.CI | ||
| ? await createAndEnrollEndpointHostCI({ | ||
| useClosestVersionMatch: true, |
There was a problem hiding this comment.
if I understand correctly options can contain useClosestVersionMatch , do we want to let the hardcoded one be overwritten by options? What is the reason for this order, asking because this looks confusing to me :)
There was a problem hiding this comment.
even more confusing since we set useClosestVersionMatch to default to true in the function params
There was a problem hiding this comment.
This looks like a typo in the order introduced here. 🤔
There was a problem hiding this comment.
Good call, this was a copy/paste of the existing code here. I'm ok removing this since the default value is true in a follow up pr if that looks good to you
💛 Build succeeded, but was flaky
Failed CI StepsTest Failures
Metrics [docs]Unknown metric groupsESLint disabled line counts
Total ESLint disabled count
History
To update your PR or re-run it, just comment with: |
Summary
In order to avoid downloading the elastic agent installer file on each Cypress test, we have introduced a new method CI specific that will cache elastic agent files and reuse it across all tests.
Old code about
if CIconditions will be removed in a follow up pr.It also introduces a CLI script to download a specific version of elastic agent using the existing methods in place.