[Security Solution] [Serverless] Integrates Cypress in visual mode with QA environment#171107
Conversation
|
Pinging @elastic/security-solution (Team: SecuritySolution) |
x-pack/plugins/security_solution/scripts/run_cypress/parallel_serverless.ts
Outdated
Show resolved
Hide resolved
x-pack/plugins/security_solution/scripts/run_cypress/parallel_serverless.ts
Outdated
Show resolved
Hide resolved
cavokz
left a comment
There was a problem hiding this comment.
As far as I can understand, LGTM.
x-pack/plugins/security_solution/scripts/run_cypress/parallel_serverless.ts
Outdated
Show resolved
Hide resolved
…serverless.ts Co-authored-by: Sergi Massaneda <sergi.massaneda@gmail.com>
semd
left a comment
There was a problem hiding this comment.
LGTM! Thanks for doing this Glo 💯
💚 Build Succeeded
Metrics [docs]
History
To update your PR or re-run it, just comment with: |
maximpn
left a comment
There was a problem hiding this comment.
@MadameSheema thank you for adding an ability to run Cypress against QA in visual mode 👍
The changes look good overall. I left some comments regarding code structure and naming. On top of this I believe we should stick to first capital letter in texts for Kibana and Serverless but it's a minor note.
| endpointAddon: boolean, | ||
| cloudAddon: boolean | ||
| ): ProductType[] => { | ||
| let productTypes: ProductType[] = [...DEFAULT_CONFIGURATION]; |
There was a problem hiding this comment.
nit: Instead of filtering out product types I'd recommend to add product types if a corresponding flag is set. It will make the implementation clearer.
| }, {} as Record<string, string | number>) | ||
| ); | ||
| ) | ||
| .option('tier', { |
There was a problem hiding this comment.
nit: tier, endpointAddon and cloudAddon are only specific for running Cypress against QA env in visual mode but script consumer can specify these props in the other modes as well though it has no effect. Since yargs supports commands clearer solution would to split functionality in commands with unique params.
| return pRetry(fetchLoginStatusAttempt, retryOptions); | ||
| } | ||
|
|
||
| const getProductTypes = ( |
There was a problem hiding this comment.
getProductTypes sounds too generic and doesn't reflect its purpose. Something like getVisualModeProductTypes should work better.
| } | ||
|
|
||
| context.addCleanupTask(() => { | ||
| const command = `curl -X DELETE ${BASE_ENV_URL}/api/v1/serverless/projects/security/${project.id} -H "Authorization: ApiKey ${API_KEY}"`; |
There was a problem hiding this comment.
Just curious. Why did you decide to run curl command instead of axios?
There was a problem hiding this comment.
@maximpn this addCleanupTask() didn't accept async, that was the reason behind if there is any other solution/way, more than happy to implement it :)
| | cypress:explore:run:ess | Runs all tests tagged as ESS in the `e2e/explore` directory in headless mode | | ||
| | cypress:investigations:run:serverless | Runs all tests tagged as SERVERLESS in the `e2e/investigations` directory in headless mode | | ||
| | cypress:explore:run:serverless | Runs all tests tagged as SERVERLESS in the `e2e/explore` directory in headless mode | | ||
| | cypress:open:qa:serverless | Opens the Cypress UI with all tests in the `e2e` directory tagged as SERVERLESS. This also creates an MKI project in console.qa enviornment. The kibana instance will reload when you make code changes. This is the recommended way to debug tests in QA. Follow the readme in order to learn about the known limitations. | |
|
|
||
|
|
||
| ### Running the serverless tests locally | ||
| ### Running serverless tests locally pointing to FTR serverless (First Quality Gate) |
There was a problem hiding this comment.
| ### Running serverless tests locally pointing to FTR serverless (First Quality Gate) | |
| ### Running serverless tests locally against FTR Serverless (First Quality Gate) |
| For test developing or test debugging purposes, you need to modify the configuration but without committing and pushing the changes in `x-pack/test/security_solution_cypress/serverless_config.ts`. | ||
|
|
||
|
|
||
| ### Running serverless tests locally pointing to a MKI project created in QA environment (Second Quality Gate) |
There was a problem hiding this comment.
| ### Running serverless tests locally pointing to a MKI project created in QA environment (Second Quality Gate) | |
| ### Running serverless tests locally against a MKI project created in QA environment (Second Quality Gate) |
|
|
||
| | Script Name | Description | | ||
| | ----------- | ----------- | | ||
| | cypress:open:qa:serverless | Opens the Cypress UI with all tests in the `e2e` directory tagged as SERVERLESS. This also creates an MKI project in console.qa enviornment. The kibana instance will reload when you make code changes. This is the recommended way to debug tests in QA. Follow the readme in order to learn about the known limitations. | |
| "cypress:changed-specs-only:serverless": "yarn cypress:serverless --changed-specs-only --env burn=5", | ||
| "cypress:burn:serverless": "yarn cypress:serverless --env burn=2", | ||
| "cypress:qa:serverless": "TZ=UTC NODE_OPTIONS=--openssl-legacy-provider node ../../plugins/security_solution/scripts/start_cypress_parallel_serverless --config-file ../../test/security_solution_cypress/cypress/cypress_ci_serverless_qa.config.ts", | ||
| "cypress:open:qa:serverless": "yarn cypress:qa:serverless open", |
There was a problem hiding this comment.
I'm curious about command naming. We have only one separate QA environment we run tests against. It turns out qa is a subset of serverless in some sense. I can imagine we have ESS QA environment in the future and this naming will have more sense.
Have you considered the other options like cypress:open:serverless-qa?
Naming in this file isn't consistent but we can improve it by sticking to one format something like cypress:mode:env[:suites name].
Summary
We are working in order to have our Cypress tests ready to be executed on MKI projects. Our first goal is to be able to execute the tests in the QA environment.
So far we have created all the code needed to be able to execute them in headless mode:
With all the above code, what we are doing is mimicking what we currently have for ESS and serverless on the first quality gate but for MKI projects in the QA environment. We create a project for each spec file following the indications of the Cypress spec and we execute the tests on that specific project.
That is really convenient for CI, but what happens when a test fails? How can we debug what is happening there?
In this PR
Continue mimicking our current flows, in this PR we have created the
cypress:open:qa:serverlesscommand.When the command is executed:
{ "product_line":"security", "product_tier":"complete" }, { "product_line":"endpoint", "product_tier":"complete" }, { "product_line":"cloud", "product_tier":"complete" }Opens the Cypress UI with all tests in the
e2edirectory tagged as@serverless.Tests are executed using the recently created environment
The project is automatically deleted when:
fnresolve/rejectsprocess.exit()How to test it
Setup a valid Elastic Cloud API key for QA environment:
User menu buttonlocated on the top right of the header.Organization.API keystab.Create API keybutton.Create API keyStore the saved key on
~/.elastic/cloud.jsonusing the following format:{ "api_key": { "qa": "<API_KEY>" } }From the
x-pack/test/security_solution_cypressyou can execute the following commands:The above command will create a project with the following characteristics
{ "product_line":"security", "product_tier":"complete" }, { "product_line":"endpoint", "product_tier":"complete" }, { "product_line":"cloud", "product_tier":"complete" }OR
The above commands will create a project with the following characteristics
{ "product_line":"security", "product_tier":"essentials" }, { "product_line":"endpoint", "product_tier":"essentials" }, { "product_line":"cloud", "product_tier":"essentials" }OR
The above command will create a project with the following characteristics
{ "product_line":"security", "product_tier":"complete" }, { "product_line":"cloud", "product_tier":"complete" }OR
The above commands will create a project with the following characteristics
{ "product_line":"security", "product_tier":"complete" }, { "product_line":"endpoint", "product_tier":"complete" }Note that tier and addons flags can be combined, for instance:
The above command will create a project with the following characteristics
{ "product_line":"security", "product_tier":"essentials" }, { "product_line":"cloud", "product_tier":"essentials" }To take into consideration