-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thanks for doing this Glo 💯
💚 Build Succeeded
Metrics [docs]
History
To update your PR or re-run it, just comment with: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
@@ -371,7 +395,22 @@ export const cli = () => { | |||
} | |||
return acc; | |||
}, {} as Record<string, string | number>) | |||
); | |||
) | |||
.option('tier', { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
@@ -325,9 +326,32 @@ function waitForKibanaLogin(kbUrl: string, credentials: Credentials): Promise<vo | |||
return pRetry(fetchLoginStatusAttempt, retryOptions); | |||
} | |||
|
|||
const getProductTypes = ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getProductTypes
sounds too generic and doesn't reflect its purpose. Something like getVisualModeProductTypes
should work better.
|
||
if (!project) { | ||
log.info('Failed to create project.'); | ||
// eslint-disable-next-line no-process-exit | ||
return process.exit(1); | ||
} | ||
|
||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just curious. Why did you decide to run curl command instead of axios?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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 :)
@@ -72,6 +71,10 @@ Run the tests with the following yarn scripts from `x-pack/test/security_solutio | |||
| 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. | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
kibana
-> Kibana
@@ -190,7 +193,7 @@ Task [cypress/support/es_archiver.ts](https://github.com/elastic/kibana/blob/mai | |||
Note that we use tags in order to select which tests we want to execute, if you want a test to be executed on serverless you need to add @serverless tag to it. | |||
|
|||
|
|||
### Running the serverless tests locally | |||
### Running serverless tests locally pointing to FTR serverless (First Quality Gate) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
### Running serverless tests locally pointing to FTR serverless (First Quality Gate) | |
### Running serverless tests locally against FTR Serverless (First Quality Gate) |
@@ -234,6 +237,97 @@ Per the way we set the environment during the execution process on CI, the above | |||
|
|||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
### 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. | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
kibana
-> Kibana
@@ -28,6 +28,7 @@ | |||
"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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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:serverless
command.When the command is executed:
Opens the Cypress UI with all tests in the
e2e
directory tagged as@serverless
.Tests are executed using the recently created environment
The project is automatically deleted when:
fn
resolve/rejectsprocess.exit()
How to test it
Setup a valid Elastic Cloud API key for QA environment:
User menu button
located on the top right of the header.Organization
.API keys
tab.Create API key
button.Create API key
Store the saved key on
~/.elastic/cloud.json
using the following format:From the
x-pack/test/security_solution_cypress
you can execute the following commands:The above command will create a project with the following characteristics
OR
The above commands will create a project with the following characteristics
OR
The above command will create a project with the following characteristics
OR
The above commands will create a project with the following characteristics
Note that tier and addons flags can be combined, for instance:
The above command will create a project with the following characteristics
To take into consideration