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][Detection Engine] Running API tests in Serverless & ESS using Mocha Tagging #166755

Merged
Merged
Show file tree
Hide file tree
Changes from 74 commits
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
c165f2f
add detection_engine folder under test_serverless for testing
WafaaNasr Sep 19, 2023
423ccde
running create_rule_exception in serverless
WafaaNasr Sep 19, 2023
1e0730c
running create_rule_exception in serverless
WafaaNasr Sep 19, 2023
2189c61
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Sep 19, 2023
62d8a68
add security_solution_api_integration and config serverless
WafaaNasr Sep 20, 2023
1b95701
Merge branch 'detection-enginer-ftr-serverless-initial' of https://gi…
WafaaNasr Sep 20, 2023
82429a7
remove detection_engine from test_serverless
WafaaNasr Sep 20, 2023
c01c148
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Sep 20, 2023
35198f0
define commands in package.json
WafaaNasr Sep 20, 2023
5df3507
latest
WafaaNasr Sep 20, 2023
dbc106e
run tests for both ess and serverless
WafaaNasr Sep 20, 2023
925014a
Merge branch 'main' into detection-enginer-ftr-serverless-initial
WafaaNasr Sep 20, 2023
9bb3bf8
try mocha tags
WafaaNasr Sep 21, 2023
b08cace
Merge branch 'detection-enginer-ftr-serverless-initial' of https://gi…
WafaaNasr Sep 21, 2023
b68b981
use suiteTags in the config
WafaaNasr Sep 21, 2023
ed96e45
move serverless config to serverless config until figuring out how to…
WafaaNasr Sep 21, 2023
16aff77
add rule_creation test with utils
WafaaNasr Sep 22, 2023
fd59ac9
Merge branch 'main' of https://github.com/elastic/kibana into detecti…
WafaaNasr Sep 22, 2023
591f0fe
only allow exceptions to be for serverless and disable rule
WafaaNasr Sep 22, 2023
bcbabbf
apply the mocha tagging with introducing @brokenInServerless
WafaaNasr Sep 25, 2023
efa734d
Merge branch 'main' of https://github.com/elastic/kibana into detecti…
WafaaNasr Sep 25, 2023
6e12eba
Merge branch 'main' of https://github.com/elastic/kibana into detecti…
WafaaNasr Sep 26, 2023
7532f52
reuse config.base from test_serverless
WafaaNasr Sep 27, 2023
9199d72
reuse test_serverless configs and only add commands for detectionegine
WafaaNasr Sep 27, 2023
c868a08
Merge branch 'main' of https://github.com/elastic/kibana into detecti…
WafaaNasr Sep 27, 2023
d1970aa
add config base in ftr ci
WafaaNasr Sep 27, 2023
88cec41
remove tsconfig for now
WafaaNasr Sep 27, 2023
92899a1
fix kibana not found
WafaaNasr Sep 27, 2023
859f525
add mochaOptions for serverless config
WafaaNasr Sep 28, 2023
1776097
add mochaOptions for ess
WafaaNasr Sep 28, 2023
2c5008a
latest
WafaaNasr Sep 28, 2023
4c8ef9e
Merge branch 'main' into detection-enginer-ftr-serverless-initial
WafaaNasr Sep 29, 2023
c1a640e
Merge branch 'main' into detection-enginer-ftr-serverless-initial
WafaaNasr Sep 29, 2023
73ce67c
Merge branch 'main' into detection-enginer-ftr-serverless-initial
WafaaNasr Sep 29, 2023
fba6606
Merge branch 'main' of https://github.com/elastic/kibana into detecti…
WafaaNasr Oct 2, 2023
8d48e0f
remove group1 create_rule_exception and create_rules from detection_e…
WafaaNasr Oct 2, 2023
ce2bcb1
Merge branch 'detection-enginer-ftr-serverless-initial' of https://gi…
WafaaNasr Oct 2, 2023
29e5359
remove the import
WafaaNasr Oct 2, 2023
a3079e8
add readme file
WafaaNasr Oct 2, 2023
2be2e87
Merge branch 'main' into detection-enginer-ftr-serverless-initial
WafaaNasr Oct 2, 2023
4bd64fb
Merge branch 'main' of https://github.com/elastic/kibana into detecti…
WafaaNasr Oct 3, 2023
ddf1c1f
Merge branch 'detection-enginer-ftr-serverless-initial' of https://gi…
WafaaNasr Oct 3, 2023
31e7d38
Merge branch 'main' of https://github.com/elastic/kibana into detecti…
WafaaNasr Oct 3, 2023
3320fd1
create new class EsArchivePathBuilder to build the path based on env …
WafaaNasr Oct 3, 2023
bf729e6
Merge branch 'main' of https://github.com/elastic/kibana into detecti…
WafaaNasr Oct 3, 2023
480cd92
fix rule execution
WafaaNasr Oct 3, 2023
e08eff9
remove console
WafaaNasr Oct 3, 2023
e2a41b2
Merge branch 'main' of https://github.com/elastic/kibana into detecti…
WafaaNasr Oct 3, 2023
7e18355
Merge branch 'main' into detection-enginer-ftr-serverless-initial
WafaaNasr Oct 3, 2023
153cc6a
add tsconfig
WafaaNasr Oct 3, 2023
4ff0cbb
Merge branch 'detection-enginer-ftr-serverless-initial' of https://gi…
WafaaNasr Oct 3, 2023
e207ab7
fix path
WafaaNasr Oct 3, 2023
1e7015f
remove extra tsconfig
WafaaNasr Oct 3, 2023
86e2789
Merge branch 'main' of https://github.com/elastic/kibana into detecti…
WafaaNasr Oct 3, 2023
a7eda2b
fix tsconfig
WafaaNasr Oct 3, 2023
14652fb
update tsconfig with list of deps
WafaaNasr Oct 3, 2023
4060d23
remove @elastic
WafaaNasr Oct 3, 2023
d566155
remove compiled files
WafaaNasr Oct 3, 2023
2077cc4
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Oct 3, 2023
f439ae9
Merge branch 'main' into detection-enginer-ftr-serverless-initial
WafaaNasr Oct 4, 2023
8728f5c
removing the type import
WafaaNasr Oct 4, 2023
50556d0
Merge branch 'detection-enginer-ftr-serverless-initial' of https://gi…
WafaaNasr Oct 4, 2023
08a2f8e
add junit in ess and fix the serverless
WafaaNasr Oct 4, 2023
7d71d39
reduce the serverless config to only include what is needed
WafaaNasr Oct 4, 2023
e8d3a63
remove console
WafaaNasr Oct 4, 2023
e982ed8
exclude security_solution_api_integration
WafaaNasr Oct 4, 2023
a200c13
use tsconfig
WafaaNasr Oct 4, 2023
993cec6
Merge branch 'main' of https://github.com/elastic/kibana into detecti…
WafaaNasr Oct 4, 2023
7f3cb51
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Oct 4, 2023
76afd5a
add typings
WafaaNasr Oct 4, 2023
204871b
exclude package
WafaaNasr Oct 4, 2023
f12cabe
add mocha types
WafaaNasr Oct 4, 2023
4ba34b1
use jest
WafaaNasr Oct 4, 2023
49c3d0d
use mocha from global_ftr
WafaaNasr Oct 4, 2023
3e0c8f0
add "@kbn/ambient-ftr-types" to types
WafaaNasr Oct 5, 2023
c6e74ee
Merge branch 'main' of https://github.com/elastic/kibana into detecti…
WafaaNasr Oct 5, 2023
b075837
apply comments
WafaaNasr Oct 6, 2023
1159b10
undo start_servers
WafaaNasr Oct 6, 2023
e027c42
Merge branch 'main' of https://github.com/elastic/kibana into detecti…
WafaaNasr Oct 6, 2023
38aa9d5
rename ess/config.ts to ess/config.base.trail.ts
WafaaNasr Oct 6, 2023
4993a71
Merge branch 'main' into detection-enginer-ftr-serverless-initial
WafaaNasr Oct 10, 2023
797ab7c
Merge branch 'main' into detection-enginer-ftr-serverless-initial
WafaaNasr Oct 10, 2023
50e4fc8
Merge branch 'main' into detection-enginer-ftr-serverless-initial
WafaaNasr Oct 11, 2023
c603046
Merge branch 'main' into detection-enginer-ftr-serverless-initial
WafaaNasr Oct 11, 2023
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
9 changes: 9 additions & 0 deletions .buildkite/ftr_configs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ disabled:
- x-pack/test/functional_with_es_ssl/config.base.ts
- x-pack/test/api_integration/config.ts
- x-pack/test/fleet_api_integration/config.base.ts
- x-pack/test/security_solution_api_integration/config/ess/config.base.ts
- x-pack/test/security_solution_api_integration/config/serverless/config.base.ts


# QA suites that are run out-of-band
- x-pack/test/stack_functional_integration/configs/config.stack_functional_integration_base.js
Expand Down Expand Up @@ -437,3 +440,9 @@ enabled:
- x-pack/performance/journeys/apm_service_inventory.ts
- x-pack/test/custom_branding/config.ts
- x-pack/test/profiling_api_integration/cloud/config.ts
- x-pack/test/security_solution_api_integration/test_suites/detections_response/serverless.config.ts
- x-pack/test/security_solution_api_integration/test_suites/detections_response/ess.config.ts
Comment on lines +455 to +456
Copy link
Contributor

Choose a reason for hiding this comment

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

Having only two configs for all D&R tests will not scale, unfortunately. We need to split our tests into N groups, where each group will have at least two FTR configs: one for ESS and one for Serverless. In the near future, groups will also have additional FTR configs for enabling feature flags and running tests against enabled features. Please read more about the idea of splitting tests into meaningful groups in #151902.

Also, there's a requirement that each group of FTR tests must run under 40 minutes. This means we should aim at 15-20 minutes at most per group, leaving some time buffer for incidents where CI gets slower than it normally is.

All that can force us to split tests into more or less fine-grained groups, sometimes more fine-grained than our subdomains (exceptions, rule management, etc). I'd say that we will likely have multiple groups per subdomain.

Let's figure out what groups should be created for the tests moved in this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've planned to work on #151902 after completing this PR. This subsequent issue involves some research to determine how we can efficiently group tests based on their relevance and execution time.

The idea behind this PR is to establish the main structural changes first, reducing the number of files and scoping this PR accordingly.

Also approaching the grouping in a separate PR will serve in documenting our approach to grouping tests, making it easier for reviewers to understand. hopefully, this separation of tasks helps streamline the review process and ensures that our tests are organized and well-documented.

I am open to discussing this topic with the whole team





1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -1301,6 +1301,7 @@ x-pack/plugins/cloud_integrations/cloud_full_story/server/config.ts @elastic/kib
/x-pack/test/security_solution_cypress/cypress/e2e/entity_analytics @elastic/security-detection-engine
/x-pack/test/security_solution_cypress/cypress/e2e/exceptions @elastic/security-detection-engine
/x-pack/test/security_solution_cypress/cypress/e2e/overview @elastic/security-detection-engine
x-pack/test/security_solution_api_integration/test_suites/detections_response/exceptions @elastic/security-detection-engine
WafaaNasr marked this conversation as resolved.
Show resolved Hide resolved

## Security Threat Intelligence - Under Security Platform
/x-pack/plugins/security_solution/public/common/components/threat_match @elastic/security-detection-engine
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@ export default ({ loadTestFile }: FtrProviderContext): void => {
loadTestFile(require.resolve('./update_actions'));
loadTestFile(require.resolve('./check_privileges'));
loadTestFile(require.resolve('./create_index'));
loadTestFile(require.resolve('./create_rules'));
loadTestFile(require.resolve('./preview_rules'));
loadTestFile(require.resolve('./create_rules_bulk'));
loadTestFile(require.resolve('./create_new_terms'));
loadTestFile(require.resolve('./create_rule_exceptions'));
loadTestFile(require.resolve('./delete_rules'));
loadTestFile(require.resolve('./delete_rules_bulk'));
loadTestFile(require.resolve('./export_rules'));
Expand Down
47 changes: 47 additions & 0 deletions x-pack/test/security_solution_api_integration/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# security_solution_api_integration

This directory
serves as a centralized location to place the security solution tests that run in Serverless and ESS environments.
WafaaNasr marked this conversation as resolved.
Show resolved Hide resolved

## Subdirectories

1. `config` stores base configurations specific to both the Serverless and ESS environments, These configurations build upon the base configuration provided by `xpack/test_serverless` and `x-pack-api_integrations`, incorporating additional settings such as environment variables and tagging options.


2. `test_suites` directory now houses all the tests along with their utility functions. As an initial step,
we have introduced the `detection_response` directory to consolidate all the integration tests related to detection and response APIs.


## Overview

- In this directory, Mocha tagging is utilized to assign tags to specific test suites and individual test cases. This tagging system enables the ability to selectively apply tags to test suites and test cases, facilitating the exclusion of specific test cases within a test suite as needed.

- There are three primary tags that have been defined: @ess, @serverless, and @brokenInServerless

- Test suites and cases are prefixed with specific tags to determine their execution in particular environments or to exclude them from specific environments.

ex:
```
describe('@serverless @ess create_rules', () => { ==> tests in this suite will run in both Ess and Serverless
describe('creating rules', () => {});

describe('@brokenInServerless missing timestamps', () => {}); ==> tests in this suite will be excluded in Serverless

```

## Adding new security area's tests

1. Within the `test_suites` directory, create a new area folder.
2. Introduce `ess.config` and `serverless.config` files to reference the new test files and incorporate any additional custom properties defined in the `CreateTestConfigOptions` interface.
3. In these new configuration files, include references to the base configurations located under the config directory to inherit CI configurations, environment variables, and other settings.
4. Append a new entry in the `ftr_configs.yml` file to enable the execution of the newly added tests within the CI pipeline.


## Testing locally

In the `package.json` file, you'll find commands to configure the server for each environment and to run tests against that specific environment. These commands adhere to the Mocha tagging system, allowing for the inclusion and exclusion of tags, mirroring the setup of the CI pipeline.





WafaaNasr marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of copy-pasting this file, can we / should we import and adjust the x-pack/test/detection_engine_api_integration/common/config.ts? I have a concern that these two files could diverge if we don't migrate our tests fast.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's true, but the good thing the CI will help us identify that since it will fail for the moved tests, and I am imagining after merging this PR the process of moving the tests should be faster than this step.

I am also open if you have other thoughts!!

Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { CA_CERT_PATH } from '@kbn/dev-utils';
import { FtrConfigProviderContext, kbnTestConfig, kibanaTestUser } from '@kbn/test';
import { services } from '../../../api_integration/services';

interface CreateTestConfigOptions {
license: string;
ssl?: boolean;
}

// test.not-enabled is specifically not enabled
const enabledActionTypes = [
'.email',
'.index',
'.pagerduty',
'.swimlane',
'.server-log',
'.servicenow',
'.slack',
'.webhook',
'test.authorization',
'test.failing',
'test.index-record',
'test.noop',
'test.rate-limit',
];

export function createTestConfig(options: CreateTestConfigOptions, testFiles?: string[]) {
const { license = 'trial', ssl = false } = options;

return async ({ readConfigFile }: FtrConfigProviderContext) => {
const xPackApiIntegrationTestsConfig = await readConfigFile(
require.resolve('../../../api_integration/config.ts')
);
const servers = {
...xPackApiIntegrationTestsConfig.get('servers'),
elasticsearch: {
...xPackApiIntegrationTestsConfig.get('servers.elasticsearch'),
protocol: ssl ? 'https' : 'http',
},
};

return {
testFiles,
servers,
services,
junit: {
reportName: 'X-Pack Detection Engine API Integration Tests',
},
esTestCluster: {
...xPackApiIntegrationTestsConfig.get('esTestCluster'),
license,
ssl,
serverArgs: [`xpack.license.self_generated.type=${license}`],
},
kbnTestServer: {
...xPackApiIntegrationTestsConfig.get('kbnTestServer'),
env: {
ELASTICSEARCH_USERNAME: kbnTestConfig.getUrlParts(kibanaTestUser).username,
},
serverArgs: [
Copy link
Contributor

Choose a reason for hiding this comment

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

As I understand this file is a copy of https://github.com/elastic/kibana/blob/main/x-pack/test/detection_engine_api_integration/common/config.ts with little modifications. It looks like some of the parameters may not be required anymore like we don't need that long list of supported actions some.non.existent.com allowed host. I'm sure I saw it in the tests. On top of that serverless config is mush thinner. As we create a new config let's make sure we don't have unnecessary params.

...xPackApiIntegrationTestsConfig.get('kbnTestServer.serverArgs'),
`--xpack.actions.allowedHosts=${JSON.stringify(['localhost', 'some.non.existent.com'])}`,
`--xpack.actions.enabledActionTypes=${JSON.stringify(enabledActionTypes)}`,
'--xpack.eventLog.logEntries=true',
`--xpack.securitySolution.alertIgnoreFields=${JSON.stringify([
'testing_ignored.constant',
'/testing_regex*/',
])}`, // See tests within the file "ignore_fields.ts" which use these values in "alertIgnoreFields"
'--xpack.ruleRegistry.write.enabled=true',
'--xpack.ruleRegistry.write.cache.enabled=false',
'--xpack.ruleRegistry.unsafe.indexUpgrade.enabled=true',
'--xpack.ruleRegistry.unsafe.legacyMultiTenancy.enabled=true',
`--xpack.securitySolution.enableExperimental=${JSON.stringify([
'previewTelemetryUrlEnabled',
'riskScoringPersistence',
'riskScoringRoutesEnabled',
])}`,
'--xpack.task_manager.poll_interval=1000',
`--xpack.actions.preconfigured=${JSON.stringify({
'my-test-email': {
actionTypeId: '.email',
name: 'TestEmail#xyz',
config: {
from: '[email protected]',
service: '__json',
},
secrets: {
user: 'user',
password: 'password',
},
},
})}`,
...(ssl
? [
`--elasticsearch.hosts=${servers.elasticsearch.protocol}://${servers.elasticsearch.hostname}:${servers.elasticsearch.port}`,
`--elasticsearch.ssl.certificateAuthorities=${CA_CERT_PATH}`,
]
: []),
],
},
mochaOpts: {
grep: '/^(?!.*@brokenInEss).*@ess.*/',
WafaaNasr marked this conversation as resolved.
Show resolved Hide resolved
},
};
};
}
14 changes: 14 additions & 0 deletions x-pack/test/security_solution_api_integration/config/ess/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { createTestConfig } from './config.base';

// eslint-disable-next-line import/no-default-export
export default createTestConfig({
license: 'trial',
ssl: true,
});
WafaaNasr marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { FtrConfigProviderContext } from '@kbn/test';

export interface CreateTestConfigOptions {
testFiles: string[];
junit: { reportName: string };
}

export function createTestConfig(options: CreateTestConfigOptions) {
return async ({ readConfigFile }: FtrConfigProviderContext) => {
const svlSharedConfig = await readConfigFile(
require.resolve('../../../../test_serverless/shared/config.base.ts')
);

Comment on lines +14 to +19
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 wondering if there could be a reason for reusing x-pack/test_serverless/functional/test_suites/security/config.ts instead of test_serverless/shared/config.base.ts. Probably not but wanted to check what are your thoughts.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah sure, that's a valid point!
We add one important additional field for the CI which is the mochaOptions to pass our own allowed/skipped mocha tags, so we get everything defined under the base.config.ts and we just tweak a small configuration

return {
...svlSharedConfig.getAll(),
kbnTestServer: {
...svlSharedConfig.get('kbnTestServer'),
serverArgs: [...svlSharedConfig.get('kbnTestServer.serverArgs'), '--serverless=security'],
},
Comment on lines +22 to +25
Copy link
Contributor

Choose a reason for hiding this comment

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

x-pack/test_serverless/functional/test_suites/security/config.ts has a serverlessProject: 'security', property. Is it a proper way to configure this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The serverlessProject parameter can take on the values 'es', 'oblt', or 'security' to indicate the specific project it pertains to. Given that x-pack/test_serverless encompasses all three solutions, the project should clearly identify itself as one of them. However, in our new folder, where we exclusively work with the 'security' project, we can directly pass it to the serverArgs, as this serverlessProject variable gets compiled accordingly.

testFiles: options.testFiles,
junit: options.junit,

mochaOpts: {
...svlSharedConfig.get('mochaOpts'),
grep: '/^(?!.*@brokenInServerless).*@serverless.*/',
WafaaNasr marked this conversation as resolved.
Show resolved Hide resolved
},
};
};
}
Copy link
Contributor

Choose a reason for hiding this comment

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

We have a lot of es archives in x-pack/test/functional/es_archives, including auditbeat/hosts and security_solution. What is the reason for introducing another folder for keeping es archives?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Related to #166755 (comment)

Binary file not shown.
Loading