Skip to content
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

Merged
merged 23 commits into from
Nov 16, 2023

Conversation

MadameSheema
Copy link
Member

@MadameSheema MadameSheema commented Nov 13, 2023

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:

  1. A security project will be created in QA environment with the following characteristics:
   {
      "product_line":"security",
      "product_tier":"complete"
   },
   {
      "product_line":"endpoint",
      "product_tier":"complete"
   },
   {
      "product_line":"cloud",
      "product_tier":"complete"
   }
  1. Opens the Cypress UI with all tests in the e2e directory tagged as @serverless.

  2. Tests are executed using the recently created environment

  3. The project is automatically deleted when:

  • fn resolve/rejects
  • Something calls process.exit()
  • ctrl+c is used in the terminal causing the SIGINT signal to be sent to the process

How to test it

Setup a valid Elastic Cloud API key for QA environment:

  1. Navigate to QA environment.
  2. Click on the User menu button located on the top right of the header.
  3. Click on Organization.
  4. Click on the API keys tab.
  5. Click on Create API key button.
  6. Add a name, set an expiration date, assign an organization owner role.
  7. Click on Create API key
  8. Save the value of the key
    Store the saved key on ~/.elastic/cloud.json using the following format:
{
  "api_key": {
    "qa": "<API_KEY>"
  }
}

From the x-pack/test/security_solution_cypress you can execute the following commands:

yarn cypress:open:qa:serverless
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"
   }
yarn cypress:open:qa:serverless --tier=essentials

OR

yarn cypress:open:qa:serverless -t essentials
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"
   }
yarn cypress:open:qa:serverless --no-endpoint-addon

OR

yarn cypress:open:qa:serverless --endpoint-addon=false
The above command will create a project with the following characteristics
   {
      "product_line":"security",
      "product_tier":"complete"
   },
   {
      "product_line":"cloud",
      "product_tier":"complete"
   }
yarn cypress:open:qa:serverless --no-cloud-addon

OR

yarn cypress:open:qa:serverless --cloud-addon=false
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:

yarn cypress:open:qa:serverless --tier=essentials --no-endpoint-addon 
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

  • RBAC cannot be currently tested on QA
  • Cypress in visual mode does not have the logic to modify/create a project with the product tier and line(s) needed, you should be the one providing that information when executing the command
  • The code available is the one deployed in QA environment
  • The setup of the project takes time, there is nothing we can do to speed-up the process since is outside our control

@MadameSheema MadameSheema changed the title adding the script [Security Solution] Integrates Cypress in visual mode with QA environment Nov 14, 2023
@MadameSheema MadameSheema changed the title [Security Solution] Integrates Cypress in visual mode with QA environment [Security Solution] [Serverless] Integrates Cypress in visual mode with QA environment Nov 14, 2023
@MadameSheema MadameSheema self-assigned this Nov 15, 2023
@MadameSheema MadameSheema added release_note:skip Skip the PR/issue when compiling release notes Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. v8.12.0 labels Nov 15, 2023
@MadameSheema MadameSheema marked this pull request as ready for review November 15, 2023 13:46
@MadameSheema MadameSheema requested review from a team as code owners November 15, 2023 13:46
@elasticmachine
Copy link
Contributor

Pinging @elastic/security-solution (Team: SecuritySolution)

@MadameSheema MadameSheema enabled auto-merge (squash) November 15, 2023 13:52
Copy link
Contributor

@cavokz cavokz left a 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.

Copy link
Contributor

@semd semd left a 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 💯

@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

✅ unchanged

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

cc @MadameSheema

Copy link
Contributor

@maximpn maximpn left a 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];
Copy link
Contributor

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', {
Copy link
Contributor

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 = (
Copy link
Contributor

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}"`;
Copy link
Contributor

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?

Copy link
Member Author

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. |
Copy link
Contributor

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
### 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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
### 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. |
Copy link
Contributor

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",
Copy link
Contributor

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].

@MadameSheema MadameSheema merged commit b47c793 into elastic:main Nov 16, 2023
@kibanamachine kibanamachine added the backport:skip This commit does not require backporting label Nov 16, 2023
@MadameSheema MadameSheema deleted the open-qa-serverless branch June 28, 2024 10:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting release_note:skip Skip the PR/issue when compiling release notes Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. v8.12.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants