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

[7.17] [security_solution] Cypress flaky tests catcher (#162376) #163992

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .buildkite/pipelines/pull_request/security_solution.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,14 @@ steps:
limit: 1
artifact_paths:
- "target/kibana-security-solution/**/*"

- command: .buildkite/scripts/steps/functional/security_solution_burn.sh
label: 'Security Solution Cypress tests, burning changed specs'
agents:
queue: n2-4-spot
depends_on: build
timeout_in_minutes: 120
parallelism: 1
soft_fail: true
artifact_paths:
- "target/kibana-security-solution/**/*"
15 changes: 15 additions & 0 deletions .buildkite/scripts/steps/functional/security_solution_burn.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env bash

set -euo pipefail

source .buildkite/scripts/steps/functional/common.sh
source .buildkite/scripts/steps/functional/common_cypress.sh

export JOB=kibana-security-solution-chrome
export KIBANA_INSTALL_DIR=${KIBANA_BUILD_LOCATION}

buildkite-agent meta-data set "${BUILDKITE_JOB_ID}_is_test_execution_step" 'false'

echo "--- Security Solution Cypress tests, burning changed specs (Chrome)"

yarn --cwd x-pack/plugins/security_solution cypress:changed-specs-only
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,7 @@
"@babel/types": "^7.21.2",
"@bazel/ibazel": "^0.16.2",
"@bazel/typescript": "^3.8.0",
"@cypress/grep": "^3.1.5",
"@cypress/snapshot": "^2.1.7",
"@cypress/webpack-preprocessor": "^5.12.2",
"@elastic/eslint-plugin-eui": "0.0.2",
Expand Down Expand Up @@ -720,6 +721,7 @@
"fast-glob": "2.2.7",
"fetch-mock": "^7.3.9",
"file-loader": "^4.2.0",
"find-cypress-specs": "^1.35.1",
"form-data": "^4.0.0",
"geckodriver": "^4.0.0",
"glob-watcher": "5.0.3",
Expand Down
29,008 changes: 16,802 additions & 12,206 deletions packages/kbn-pm/dist/index.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ describe('Timelines', (): void => {
});
});

describe('Create a timeline from a template', () => {
describe.skip('Create a timeline from a template', () => {
before(() => {
cy.intercept('/api/timeline*').as('timeline');
cleanKibana();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import _ from 'lodash';
import globby from 'globby';
import pMap from 'p-map';
import cypress from 'cypress';
import { findChangedFiles } from 'find-cypress-specs';
import minimatch from 'minimatch';
import path from 'path';

import {
EsVersion,
Expand Down Expand Up @@ -62,13 +65,39 @@ const retrieveIntegrations = (
export const cli = () => {
run(
async () => {
const { argv } = yargs(process.argv.slice(2));
const { argv } = yargs(process.argv.slice(2)).coerce('env', (arg: string) =>
arg.split(',').reduce((acc, curr) => {
const [key, value] = curr.split('=');
if (key === 'burn') {
acc[key] = parseInt(value, 10);
} else {
acc[key] = value;
}
return acc;
}, {} as Record<string, string | number>)
);

const isOpen = argv._[0] === 'open';
const cypressConfigFilePath = require.resolve(`../../../${argv.configFile}`) as string;
const cypressConfigFile = await import(require.resolve(`../../../${argv.configFile}`));
const spec: string | undefined = argv?.spec as string;
const files = retrieveIntegrations(spec ? [spec] : cypressConfigFile?.e2e?.specPattern);
let files = retrieveIntegrations(spec ? [spec] : cypressConfigFile?.e2e?.specPattern);

if (argv.changedSpecsOnly) {
const basePath = process.cwd().split('kibana/')[1];
files = findChangedFiles('7.17', false)
.filter(
minimatch.filter(path.join(basePath, cypressConfigFile?.e2e?.specPattern), {
matchBase: true,
})
)
.map((filePath: string) => filePath.replace(basePath, '.'));

if (!files?.length) {
// eslint-disable-next-line no-process-exit
return process.exit(0);
}
}

if (!files?.length) {
throw new Error('No files found');
Expand Down Expand Up @@ -360,7 +389,7 @@ ${JSON.stringify(config.getAll(), null, 2)}
...ftrEnv,

// NOTE:
// ELASTICSEARCH_URL needs to be crated here with auth because SIEM cypress setup depends on it. At some
// ELASTICSEARCH_URL needs to be created here with auth because SIEM cypress setup depends on it. At some
// points we should probably try to refactor that code to use `ELASTICSEARCH_URL_WITH_AUTH` instead
ELASTICSEARCH_URL:
ftrEnv.ELASTICSEARCH_URL ?? createUrlFromFtrConfig('elasticsearch', true),
Expand All @@ -376,6 +405,8 @@ ${JSON.stringify(config.getAll(), null, 2)}
KIBANA_URL_WITH_AUTH: createUrlFromFtrConfig('kibana', true),
KIBANA_USERNAME: config.get('servers.kibana.username'),
KIBANA_PASSWORD: config.get('servers.kibana.password'),

...argv.env,
};

log.info(`
Expand Down Expand Up @@ -406,7 +437,7 @@ ${JSON.stringify(cyCustomEnv, null, 2)}
configFile: cypressConfigFilePath,
reporter: argv.reporter as string,
reporterOptions: argv.reporterOptions,
headed: true,
headed: argv.headed as boolean,
config: {
e2e: {
baseUrl,
Expand Down
22 changes: 3 additions & 19 deletions x-pack/plugins/security_solution/cypress/support/e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,13 @@
* 2.0.
*/

// ***********************************************************
// This example support/index.js is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************

// Import commands.js using ES2015 syntax:
import './commands';
import 'cypress-real-events/support';
import 'cypress-pipe';
import registerCypressGrep from '@cypress/grep';

registerCypressGrep();

Cypress.on('uncaught:exception', () => {
return false;
});

// Alternatively you can use CommonJS syntax:
// require('./commands')
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* 2.0.
*/

declare module 'find-cypress-specs';
declare namespace Cypress {
interface Chainable<Subject> {
promisify(): Promise<Subject>;
Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/security_solution/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
"extract-mitre-attacks": "node scripts/extract_tactics_techniques_mitre.js && node ../../../scripts/eslint ./public/detections/mitre/mitre_tactics_techniques.ts --fix",
"build-beat-doc": "node scripts/beat_docs/build.js && node ../../../scripts/eslint ./server/utils/beat_schema/fields.ts --fix",
"cypress": "../../../node_modules/.bin/cypress",
"cypress:burn": "yarn cypress:run:reporter --env burn=2 --concurrency=1 --headed",
"cypress:changed-specs-only": "yarn cypress:run:reporter --changed-specs-only --env burn=2",
"cypress:open": "TZ=UTC node ./scripts/start_cypress_parallel open --spec './cypress/e2e/**/*.cy.ts' --config-file ./cypress/cypress.config.ts --ftr-config-file ../../../../../../../x-pack/test/security_solution_cypress/cli_config",
"cypress:run": "yarn cypress:run:reporter --spec './cypress/e2e/**/*.cy.ts'; status=$?; yarn junit:merge && exit $status",
"cypress:run:reporter": "TZ=UTC node ./scripts/start_cypress_parallel run --config-file ./cypress/cypress_ci.config.ts --ftr-config-file ../../../../../../../x-pack/test/security_solution_cypress/cli_config --reporter ../../../node_modules/cypress-multi-reporters --reporter-options configFile=./cypress/reporter_config.json",
Expand Down
Loading