Skip to content

Commit

Permalink
[ML] Functional tests - increase module test coverage (elastic#99758) (
Browse files Browse the repository at this point in the history
…elastic#99904)

This PR adds a couple API integrations tests to get, recognize and setup modules.

Co-authored-by: Robert Oskamp <robert.oskamp@elastic.co>
  • Loading branch information
kibanamachine and pheyos authored May 12, 2021
1 parent a93d77a commit 5106f42
Show file tree
Hide file tree
Showing 18 changed files with 43,588 additions and 453 deletions.
10 changes: 10 additions & 0 deletions x-pack/test/api_integration/apis/ml/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ export default function ({ getService, loadTestFile }: FtrProviderContext) {
await ml.testResources.deleteIndexPatternByTitle('ft_module_siem_winlogbeat');
await ml.testResources.deleteIndexPatternByTitle('ft_farequote');
await ml.testResources.deleteIndexPatternByTitle('ft_logs-endpoint.events.*');
await ml.testResources.deleteIndexPatternByTitle('ft_module_metricbeat');
await ml.testResources.deleteIndexPatternByTitle('ft_module_siem_cloudtrail');
await ml.testResources.deleteIndexPatternByTitle('ft_module_metrics_ui');
await ml.testResources.deleteIndexPatternByTitle('ft_module_apache_data_stream');
await ml.testResources.deleteIndexPatternByTitle('ft_module_nginx_data_stream');

await esArchiver.unload('ml/ecommerce');
await esArchiver.unload('ml/categorization');
Expand All @@ -54,6 +59,11 @@ export default function ({ getService, loadTestFile }: FtrProviderContext) {
await esArchiver.unload('ml/farequote');
await esArchiver.unload('ml/bm_classification');
await esArchiver.unload('ml/ihp_outlier');
await esArchiver.unload('ml/module_metricbeat');
await esArchiver.unload('ml/module_siem_cloudtrail');
await esArchiver.unload('ml/module_metrics_ui');
await esArchiver.unload('ml/module_apache_data_stream');
await esArchiver.unload('ml/module_nginx_data_stream');

await ml.testResources.resetKibanaTimeZone();
});
Expand Down
2 changes: 2 additions & 0 deletions x-pack/test/api_integration/apis/ml/modules/get_module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { COMMON_REQUEST_HEADERS } from '../../../../functional/services/ml/commo
import { isPopulatedObject } from '../../../../../plugins/ml/common/util/object_utils';

const moduleIds = [
'apache_data_stream',
'apache_ecs',
'apm_jsbase',
'apm_nodejs',
Expand All @@ -25,6 +26,7 @@ const moduleIds = [
'metricbeat_system_ecs',
'metrics_ui_hosts',
'metrics_ui_k8s',
'nginx_data_stream',
'nginx_ecs',
'sample_data_ecommerce',
'sample_data_weblogs',
Expand Down
18 changes: 17 additions & 1 deletion x-pack/test/api_integration/apis/ml/modules/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,24 @@

import { FtrProviderContext } from '../../../ftr_provider_context';

export default function ({ loadTestFile }: FtrProviderContext) {
export default function ({ getService, loadTestFile }: FtrProviderContext) {
const ml = getService('ml');

const fleetPackages = ['apache-0.5.0', 'nginx-0.5.0'];

describe('modules', function () {
before(async () => {
for (const fleetPackage of fleetPackages) {
await ml.testResources.installFleetPackage(fleetPackage);
}
});

after(async () => {
for (const fleetPackage of fleetPackages) {
await ml.testResources.removeFleetPackage(fleetPackage);
}
});

loadTestFile(require.resolve('./get_module'));
loadTestFile(require.resolve('./recognize_module'));
loadTestFile(require.resolve('./setup_module'));
Expand Down
57 changes: 56 additions & 1 deletion x-pack/test/api_integration/apis/ml/modules/recognize_module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,12 @@ export default ({ getService }: FtrProviderContext) => {
user: USER.ML_POWERUSER,
expected: {
responseCode: 200,
moduleIds: ['siem_winlogbeat'],
moduleIds: [
'security_network',
'security_windows',
'siem_winlogbeat',
'siem_winlogbeat_auth',
],
},
},
{
Expand Down Expand Up @@ -146,6 +151,56 @@ export default ({ getService }: FtrProviderContext) => {
moduleIds: ['security_linux', 'security_network', 'security_windows'],
},
},
{
testTitleSuffix: 'for metricbeat dataset',
sourceDataArchive: 'ml/module_metricbeat',
indexPattern: 'ft_module_metricbeat',
user: USER.ML_POWERUSER,
expected: {
responseCode: 200,
moduleIds: ['metricbeat_system_ecs', 'security_linux'],
},
},
{
testTitleSuffix: 'for siem clodutrail dataset',
sourceDataArchive: 'ml/module_siem_cloudtrail',
indexPattern: 'ft_module_siem_cloudtrail',
user: USER.ML_POWERUSER,
expected: {
responseCode: 200,
moduleIds: ['siem_cloudtrail'],
},
},
{
testTitleSuffix: 'for metrics ui dataset',
sourceDataArchive: 'ml/module_metrics_ui',
indexPattern: 'ft_module_metrics_ui',
user: USER.ML_POWERUSER,
expected: {
responseCode: 200,
moduleIds: ['security_linux'], // the metrics ui modules don't define a query and can't be recognized
},
},
{
testTitleSuffix: 'for apache data stream dataset',
sourceDataArchive: 'ml/module_apache_data_stream',
indexPattern: 'ft_module_apache_data_stream',
user: USER.ML_POWERUSER,
expected: {
responseCode: 200,
moduleIds: ['apache_data_stream'],
},
},
{
testTitleSuffix: 'for nginx data stream dataset',
sourceDataArchive: 'ml/module_nginx_data_stream',
indexPattern: 'ft_module_nginx_data_stream',
user: USER.ML_POWERUSER,
expected: {
responseCode: 200,
moduleIds: ['nginx_data_stream'],
},
},
];

async function executeRecognizeModuleRequest(indexPattern: string, user: USER, rspCode: number) {
Expand Down
Loading

0 comments on commit 5106f42

Please sign in to comment.