From 70f18793265b03cbd7a68f29ad9f6aae633e8d2f Mon Sep 17 00:00:00 2001 From: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Date: Wed, 17 Nov 2021 16:08:25 -0500 Subject: [PATCH] Completed the first part which is the backend tests to run less than 600 megs (#118734) (#118930) ## Summary This addresses parts of https://github.com/elastic/kibana/issues/117255 By introducing top level mocks for: * `core/server/index.ts` * `task_manager/server/index.ts` * `alerting/server/index.ts` * `actions/server/index.ts` These top level mocks add the few required functions we use sparingly and adds them from the "restricted zones" to avoid giant typescript imports from happening from the server side which also pulls in the memory leaks. ```ts moduleNameMapper: { 'core/server$': '/x-pack/plugins/security_solution/server/__mocks__/core.mock.ts', 'task_manager/server$': '/x-pack/plugins/security_solution/server/__mocks__/task_manager.mock.ts', 'alerting/server$': '/x-pack/plugins/security_solution/server/__mocks__/alert.mock.ts', 'actions/server$': '/x-pack/plugins/security_solution/server/__mocks__/action.mock.ts', }, ``` For testing this you can now run: ```sh node --max-old-space-size=600 --expose-gc ./node_modules/.bin/jest --runInBand --logHeapUsage --detectOpenHandles --no-cache --config x-pack/plugins/security_solution/jest.config.dev.js x-pack/plugins/security_solution/server ``` And the server side tests will be able to complete in less than 600 megs of memory. The memory leaks and memory consumption issues are mitigated through the layers but this doesn't guarantee that in the future these won't show up again. The root of the issue(s) with the memory leaks from `core/server` aren't addressed here as those are separate concerns at this point but this at least mitigates the amount of leakage from our side for now. ### Checklist - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios Co-authored-by: Frank Hassanabad --- .../delete_exception_list_items_by_list.ts | 2 +- .../exception_lists/get_exception_list.ts | 2 +- .../get_exception_list_item.ts | 2 +- .../get_exception_list_summary.ts | 2 +- .../security_solution/common/jest.config.js | 8 ++++++++ .../public/app/jest.config.js | 8 ++++++++ .../public/cases/jest.config.js | 8 ++++++++ .../public/common/jest.config.js | 8 ++++++++ .../public/detections/jest.config.js | 8 ++++++++ .../public/hosts/jest.config.js | 8 ++++++++ .../security_solution/public/jest.config.js | 8 ++++++++ .../public/management/jest.config.js | 8 ++++++++ .../public/network/jest.config.js | 8 ++++++++ .../public/overview/jest.config.js | 8 ++++++++ .../public/resolver/jest.config.js | 8 ++++++++ .../public/timelines/jest.config.js | 8 ++++++++ .../public/transforms/jest.config.js | 8 ++++++++ .../server/__mocks__/action.mock.ts | 9 +++++++++ .../server/__mocks__/alert.mock.ts | 19 +++++++++++++++++++ .../server/__mocks__/core.mock.ts | 15 +++++++++++++++ .../server/__mocks__/task_manager.mock.ts | 14 ++++++++++++++ .../server/client/jest.config.js | 8 ++++++++ .../server/endpoint/jest.config.js | 8 ++++++++ .../server/fleet_integration/jest.config.js | 8 ++++++++ .../security_solution/server/jest.config.js | 8 ++++++++ .../routes/__mocks__/request_context.ts | 6 +++++- .../server/lib/jest.config.js | 8 ++++++++ .../server/lib/machine_learning/authz.ts | 2 +- .../server/search_strategy/jest.config.js | 8 ++++++++ .../server/usage/jest.config.js | 8 ++++++++ .../server/utils/jest.config.js | 8 ++++++++ 31 files changed, 235 insertions(+), 6 deletions(-) create mode 100644 x-pack/plugins/security_solution/server/__mocks__/action.mock.ts create mode 100644 x-pack/plugins/security_solution/server/__mocks__/alert.mock.ts create mode 100644 x-pack/plugins/security_solution/server/__mocks__/core.mock.ts create mode 100644 x-pack/plugins/security_solution/server/__mocks__/task_manager.mock.ts diff --git a/x-pack/plugins/lists/server/services/exception_lists/delete_exception_list_items_by_list.ts b/x-pack/plugins/lists/server/services/exception_lists/delete_exception_list_items_by_list.ts index 23c389f2a5331..873fe66b1ad3b 100644 --- a/x-pack/plugins/lists/server/services/exception_lists/delete_exception_list_items_by_list.ts +++ b/x-pack/plugins/lists/server/services/exception_lists/delete_exception_list_items_by_list.ts @@ -9,7 +9,7 @@ import type { ListId, NamespaceType } from '@kbn/securitysolution-io-ts-list-typ import { getSavedObjectType } from '@kbn/securitysolution-list-utils'; import { asyncForEach } from '@kbn/std'; -import { SavedObjectsClientContract } from '../../../../../../src/core/server/'; +import { SavedObjectsClientContract } from '../../../../../../src/core/server'; import { findExceptionListItem } from './find_exception_list_item'; diff --git a/x-pack/plugins/lists/server/services/exception_lists/get_exception_list.ts b/x-pack/plugins/lists/server/services/exception_lists/get_exception_list.ts index 2b09642f59c9c..b0b66ffb70d77 100644 --- a/x-pack/plugins/lists/server/services/exception_lists/get_exception_list.ts +++ b/x-pack/plugins/lists/server/services/exception_lists/get_exception_list.ts @@ -16,7 +16,7 @@ import { getSavedObjectType } from '@kbn/securitysolution-list-utils'; import { SavedObjectsClientContract, SavedObjectsErrorHelpers, -} from '../../../../../../src/core/server/'; +} from '../../../../../../src/core/server'; import { ExceptionListSoSchema } from '../../schemas/saved_objects'; import { transformSavedObjectToExceptionList } from './utils'; diff --git a/x-pack/plugins/lists/server/services/exception_lists/get_exception_list_item.ts b/x-pack/plugins/lists/server/services/exception_lists/get_exception_list_item.ts index ef825b4cf5e3e..12580af8a1d07 100644 --- a/x-pack/plugins/lists/server/services/exception_lists/get_exception_list_item.ts +++ b/x-pack/plugins/lists/server/services/exception_lists/get_exception_list_item.ts @@ -16,7 +16,7 @@ import { getSavedObjectType } from '@kbn/securitysolution-list-utils'; import { SavedObjectsClientContract, SavedObjectsErrorHelpers, -} from '../../../../../../src/core/server/'; +} from '../../../../../../src/core/server'; import { ExceptionListSoSchema } from '../../schemas/saved_objects'; import { transformSavedObjectToExceptionListItem } from './utils'; diff --git a/x-pack/plugins/lists/server/services/exception_lists/get_exception_list_summary.ts b/x-pack/plugins/lists/server/services/exception_lists/get_exception_list_summary.ts index f5722ea26ccf7..272fd70bcb322 100644 --- a/x-pack/plugins/lists/server/services/exception_lists/get_exception_list_summary.ts +++ b/x-pack/plugins/lists/server/services/exception_lists/get_exception_list_summary.ts @@ -16,7 +16,7 @@ import { getSavedObjectType } from '@kbn/securitysolution-list-utils'; import { SavedObjectsClientContract, SavedObjectsErrorHelpers, -} from '../../../../../../src/core/server/'; +} from '../../../../../../src/core/server'; import { ExceptionListSoSchema } from '../../schemas/saved_objects'; interface GetExceptionListSummaryOptions { diff --git a/x-pack/plugins/security_solution/common/jest.config.js b/x-pack/plugins/security_solution/common/jest.config.js index ca6f7cd368f2b..1b5f75f8380ba 100644 --- a/x-pack/plugins/security_solution/common/jest.config.js +++ b/x-pack/plugins/security_solution/common/jest.config.js @@ -13,4 +13,12 @@ module.exports = { '/target/kibana-coverage/jest/x-pack/plugins/security_solution/common', coverageReporters: ['text', 'html'], collectCoverageFrom: ['/x-pack/plugins/security_solution/common/**/*.{ts,tsx}'], + // See: https://github.com/elastic/kibana/issues/117255, the moduleNameMapper creates mocks to avoid memory leaks from kibana core. + moduleNameMapper: { + 'core/server$': '/x-pack/plugins/security_solution/server/__mocks__/core.mock.ts', + 'task_manager/server$': + '/x-pack/plugins/security_solution/server/__mocks__/task_manager.mock.ts', + 'alerting/server$': '/x-pack/plugins/security_solution/server/__mocks__/alert.mock.ts', + 'actions/server$': '/x-pack/plugins/security_solution/server/__mocks__/action.mock.ts', + }, }; diff --git a/x-pack/plugins/security_solution/public/app/jest.config.js b/x-pack/plugins/security_solution/public/app/jest.config.js index 452cee5e5b3a6..8674e6754aabf 100644 --- a/x-pack/plugins/security_solution/public/app/jest.config.js +++ b/x-pack/plugins/security_solution/public/app/jest.config.js @@ -13,4 +13,12 @@ module.exports = { '/target/kibana-coverage/jest/x-pack/plugins/security_solution/public/app', coverageReporters: ['text', 'html'], collectCoverageFrom: ['/x-pack/plugins/security_solution/public/app/**/*.{ts,tsx}'], + // See: https://github.com/elastic/kibana/issues/117255, the moduleNameMapper creates mocks to avoid memory leaks from kibana core. + moduleNameMapper: { + 'core/server$': '/x-pack/plugins/security_solution/server/__mocks__/core.mock.ts', + 'task_manager/server$': + '/x-pack/plugins/security_solution/server/__mocks__/task_manager.mock.ts', + 'alerting/server$': '/x-pack/plugins/security_solution/server/__mocks__/alert.mock.ts', + 'actions/server$': '/x-pack/plugins/security_solution/server/__mocks__/action.mock.ts', + }, }; diff --git a/x-pack/plugins/security_solution/public/cases/jest.config.js b/x-pack/plugins/security_solution/public/cases/jest.config.js index 4b0a49fd65aff..9089585ce8687 100644 --- a/x-pack/plugins/security_solution/public/cases/jest.config.js +++ b/x-pack/plugins/security_solution/public/cases/jest.config.js @@ -13,4 +13,12 @@ module.exports = { '/target/kibana-coverage/jest/x-pack/plugins/security_solution/public/cases', coverageReporters: ['text', 'html'], collectCoverageFrom: ['/x-pack/plugins/security_solution/public/cases/**/*.{ts,tsx}'], + // See: https://github.com/elastic/kibana/issues/117255, the moduleNameMapper creates mocks to avoid memory leaks from kibana core. + moduleNameMapper: { + 'core/server$': '/x-pack/plugins/security_solution/server/__mocks__/core.mock.ts', + 'task_manager/server$': + '/x-pack/plugins/security_solution/server/__mocks__/task_manager.mock.ts', + 'alerting/server$': '/x-pack/plugins/security_solution/server/__mocks__/alert.mock.ts', + 'actions/server$': '/x-pack/plugins/security_solution/server/__mocks__/action.mock.ts', + }, }; diff --git a/x-pack/plugins/security_solution/public/common/jest.config.js b/x-pack/plugins/security_solution/public/common/jest.config.js index e59f9c68f7590..3fedce946d633 100644 --- a/x-pack/plugins/security_solution/public/common/jest.config.js +++ b/x-pack/plugins/security_solution/public/common/jest.config.js @@ -13,4 +13,12 @@ module.exports = { '/target/kibana-coverage/jest/x-pack/plugins/security_solution/public/common', coverageReporters: ['text', 'html'], collectCoverageFrom: ['/x-pack/plugins/security_solution/public/common/**/*.{ts,tsx}'], + // See: https://github.com/elastic/kibana/issues/117255, the moduleNameMapper creates mocks to avoid memory leaks from kibana core. + moduleNameMapper: { + 'core/server$': '/x-pack/plugins/security_solution/server/__mocks__/core.mock.ts', + 'task_manager/server$': + '/x-pack/plugins/security_solution/server/__mocks__/task_manager.mock.ts', + 'alerting/server$': '/x-pack/plugins/security_solution/server/__mocks__/alert.mock.ts', + 'actions/server$': '/x-pack/plugins/security_solution/server/__mocks__/action.mock.ts', + }, }; diff --git a/x-pack/plugins/security_solution/public/detections/jest.config.js b/x-pack/plugins/security_solution/public/detections/jest.config.js index 23bc914b6493b..1121326c4ee34 100644 --- a/x-pack/plugins/security_solution/public/detections/jest.config.js +++ b/x-pack/plugins/security_solution/public/detections/jest.config.js @@ -15,4 +15,12 @@ module.exports = { collectCoverageFrom: [ '/x-pack/plugins/security_solution/public/detections/**/*.{ts,tsx}', ], + // See: https://github.com/elastic/kibana/issues/117255, the moduleNameMapper creates mocks to avoid memory leaks from kibana core. + moduleNameMapper: { + 'core/server$': '/x-pack/plugins/security_solution/server/__mocks__/core.mock.ts', + 'task_manager/server$': + '/x-pack/plugins/security_solution/server/__mocks__/task_manager.mock.ts', + 'alerting/server$': '/x-pack/plugins/security_solution/server/__mocks__/alert.mock.ts', + 'actions/server$': '/x-pack/plugins/security_solution/server/__mocks__/action.mock.ts', + }, }; diff --git a/x-pack/plugins/security_solution/public/hosts/jest.config.js b/x-pack/plugins/security_solution/public/hosts/jest.config.js index b0ead04130b74..d8354b47c3cbe 100644 --- a/x-pack/plugins/security_solution/public/hosts/jest.config.js +++ b/x-pack/plugins/security_solution/public/hosts/jest.config.js @@ -13,4 +13,12 @@ module.exports = { '/target/kibana-coverage/jest/x-pack/plugins/security_solution/public/hosts', coverageReporters: ['text', 'html'], collectCoverageFrom: ['/x-pack/plugins/security_solution/public/hosts/**/*.{ts,tsx}'], + // See: https://github.com/elastic/kibana/issues/117255, the moduleNameMapper creates mocks to avoid memory leaks from kibana core. + moduleNameMapper: { + 'core/server$': '/x-pack/plugins/security_solution/server/__mocks__/core.mock.ts', + 'task_manager/server$': + '/x-pack/plugins/security_solution/server/__mocks__/task_manager.mock.ts', + 'alerting/server$': '/x-pack/plugins/security_solution/server/__mocks__/alert.mock.ts', + 'actions/server$': '/x-pack/plugins/security_solution/server/__mocks__/action.mock.ts', + }, }; diff --git a/x-pack/plugins/security_solution/public/jest.config.js b/x-pack/plugins/security_solution/public/jest.config.js index f2bde770370f4..5eb349b2c16e9 100644 --- a/x-pack/plugins/security_solution/public/jest.config.js +++ b/x-pack/plugins/security_solution/public/jest.config.js @@ -15,4 +15,12 @@ module.exports = { '/target/kibana-coverage/jest/x-pack/plugins/security_solution/public', coverageReporters: ['text', 'html'], collectCoverageFrom: ['/x-pack/plugins/security_solution/public/**/*.{ts,tsx}'], + // See: https://github.com/elastic/kibana/issues/117255, the moduleNameMapper creates mocks to avoid memory leaks from kibana core. + moduleNameMapper: { + 'core/server$': '/x-pack/plugins/security_solution/server/__mocks__/core.mock.ts', + 'task_manager/server$': + '/x-pack/plugins/security_solution/server/__mocks__/task_manager.mock.ts', + 'alerting/server$': '/x-pack/plugins/security_solution/server/__mocks__/alert.mock.ts', + 'actions/server$': '/x-pack/plugins/security_solution/server/__mocks__/action.mock.ts', + }, }; diff --git a/x-pack/plugins/security_solution/public/management/jest.config.js b/x-pack/plugins/security_solution/public/management/jest.config.js index fdb6212ef6c81..3e5560b56aa09 100644 --- a/x-pack/plugins/security_solution/public/management/jest.config.js +++ b/x-pack/plugins/security_solution/public/management/jest.config.js @@ -15,4 +15,12 @@ module.exports = { collectCoverageFrom: [ '/x-pack/plugins/security_solution/public/management/**/*.{ts,tsx}', ], + // See: https://github.com/elastic/kibana/issues/117255, the moduleNameMapper creates mocks to avoid memory leaks from kibana core. + moduleNameMapper: { + 'core/server$': '/x-pack/plugins/security_solution/server/__mocks__/core.mock.ts', + 'task_manager/server$': + '/x-pack/plugins/security_solution/server/__mocks__/task_manager.mock.ts', + 'alerting/server$': '/x-pack/plugins/security_solution/server/__mocks__/alert.mock.ts', + 'actions/server$': '/x-pack/plugins/security_solution/server/__mocks__/action.mock.ts', + }, }; diff --git a/x-pack/plugins/security_solution/public/network/jest.config.js b/x-pack/plugins/security_solution/public/network/jest.config.js index 6059805c0652a..98b45b1e5699b 100644 --- a/x-pack/plugins/security_solution/public/network/jest.config.js +++ b/x-pack/plugins/security_solution/public/network/jest.config.js @@ -13,4 +13,12 @@ module.exports = { '/target/kibana-coverage/jest/x-pack/plugins/security_solution/public/network', coverageReporters: ['text', 'html'], collectCoverageFrom: ['/x-pack/plugins/security_solution/public/network/**/*.{ts,tsx}'], + // See: https://github.com/elastic/kibana/issues/117255, the moduleNameMapper creates mocks to avoid memory leaks from kibana core. + moduleNameMapper: { + 'core/server$': '/x-pack/plugins/security_solution/server/__mocks__/core.mock.ts', + 'task_manager/server$': + '/x-pack/plugins/security_solution/server/__mocks__/task_manager.mock.ts', + 'alerting/server$': '/x-pack/plugins/security_solution/server/__mocks__/alert.mock.ts', + 'actions/server$': '/x-pack/plugins/security_solution/server/__mocks__/action.mock.ts', + }, }; diff --git a/x-pack/plugins/security_solution/public/overview/jest.config.js b/x-pack/plugins/security_solution/public/overview/jest.config.js index 673eece7a36fd..b34dea8802c5e 100644 --- a/x-pack/plugins/security_solution/public/overview/jest.config.js +++ b/x-pack/plugins/security_solution/public/overview/jest.config.js @@ -13,4 +13,12 @@ module.exports = { '/target/kibana-coverage/jest/x-pack/plugins/security_solution/public/overview', coverageReporters: ['text', 'html'], collectCoverageFrom: ['/x-pack/plugins/security_solution/public/overview/**/*.{ts,tsx}'], + // See: https://github.com/elastic/kibana/issues/117255, the moduleNameMapper creates mocks to avoid memory leaks from kibana core. + moduleNameMapper: { + 'core/server$': '/x-pack/plugins/security_solution/server/__mocks__/core.mock.ts', + 'task_manager/server$': + '/x-pack/plugins/security_solution/server/__mocks__/task_manager.mock.ts', + 'alerting/server$': '/x-pack/plugins/security_solution/server/__mocks__/alert.mock.ts', + 'actions/server$': '/x-pack/plugins/security_solution/server/__mocks__/action.mock.ts', + }, }; diff --git a/x-pack/plugins/security_solution/public/resolver/jest.config.js b/x-pack/plugins/security_solution/public/resolver/jest.config.js index 43e1202d9d8da..f517075bf5962 100644 --- a/x-pack/plugins/security_solution/public/resolver/jest.config.js +++ b/x-pack/plugins/security_solution/public/resolver/jest.config.js @@ -13,4 +13,12 @@ module.exports = { '/target/kibana-coverage/jest/x-pack/plugins/security_solution/public/resolver', coverageReporters: ['text', 'html'], collectCoverageFrom: ['/x-pack/plugins/security_solution/public/resolver/**/*.{ts,tsx}'], + // See: https://github.com/elastic/kibana/issues/117255, the moduleNameMapper creates mocks to avoid memory leaks from kibana core. + moduleNameMapper: { + 'core/server$': '/x-pack/plugins/security_solution/server/__mocks__/core.mock.ts', + 'task_manager/server$': + '/x-pack/plugins/security_solution/server/__mocks__/task_manager.mock.ts', + 'alerting/server$': '/x-pack/plugins/security_solution/server/__mocks__/alert.mock.ts', + 'actions/server$': '/x-pack/plugins/security_solution/server/__mocks__/action.mock.ts', + }, }; diff --git a/x-pack/plugins/security_solution/public/timelines/jest.config.js b/x-pack/plugins/security_solution/public/timelines/jest.config.js index 94434b9303d47..ac28fe2d34979 100644 --- a/x-pack/plugins/security_solution/public/timelines/jest.config.js +++ b/x-pack/plugins/security_solution/public/timelines/jest.config.js @@ -15,4 +15,12 @@ module.exports = { collectCoverageFrom: [ '/x-pack/plugins/security_solution/public/timelines/**/*.{ts,tsx}', ], + // See: https://github.com/elastic/kibana/issues/117255, the moduleNameMapper creates mocks to avoid memory leaks from kibana core. + moduleNameMapper: { + 'core/server$': '/x-pack/plugins/security_solution/server/__mocks__/core.mock.ts', + 'task_manager/server$': + '/x-pack/plugins/security_solution/server/__mocks__/task_manager.mock.ts', + 'alerting/server$': '/x-pack/plugins/security_solution/server/__mocks__/alert.mock.ts', + 'actions/server$': '/x-pack/plugins/security_solution/server/__mocks__/action.mock.ts', + }, }; diff --git a/x-pack/plugins/security_solution/public/transforms/jest.config.js b/x-pack/plugins/security_solution/public/transforms/jest.config.js index 30847fa39a8d8..095a70933abc1 100644 --- a/x-pack/plugins/security_solution/public/transforms/jest.config.js +++ b/x-pack/plugins/security_solution/public/transforms/jest.config.js @@ -15,4 +15,12 @@ module.exports = { collectCoverageFrom: [ '/x-pack/plugins/security_solution/public/transforms/**/*.{ts,tsx}', ], + // See: https://github.com/elastic/kibana/issues/117255, the moduleNameMapper creates mocks to avoid memory leaks from kibana core. + moduleNameMapper: { + 'core/server$': '/x-pack/plugins/security_solution/server/__mocks__/core.mock.ts', + 'task_manager/server$': + '/x-pack/plugins/security_solution/server/__mocks__/task_manager.mock.ts', + 'alerting/server$': '/x-pack/plugins/security_solution/server/__mocks__/alert.mock.ts', + 'actions/server$': '/x-pack/plugins/security_solution/server/__mocks__/action.mock.ts', + }, }; diff --git a/x-pack/plugins/security_solution/server/__mocks__/action.mock.ts b/x-pack/plugins/security_solution/server/__mocks__/action.mock.ts new file mode 100644 index 0000000000000..2a430c47cc127 --- /dev/null +++ b/x-pack/plugins/security_solution/server/__mocks__/action.mock.ts @@ -0,0 +1,9 @@ +/* + * 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. + */ + +// See: https://github.com/elastic/kibana/issues/117255, this creates mocks to avoid memory leaks from kibana core. +module.exports = {}; diff --git a/x-pack/plugins/security_solution/server/__mocks__/alert.mock.ts b/x-pack/plugins/security_solution/server/__mocks__/alert.mock.ts new file mode 100644 index 0000000000000..917eb205837a6 --- /dev/null +++ b/x-pack/plugins/security_solution/server/__mocks__/alert.mock.ts @@ -0,0 +1,19 @@ +/* + * 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. + */ + +// See: https://github.com/elastic/kibana/issues/117255, this creates mocks to avoid memory leaks from kibana core. + +import { parseDuration } from '../../../alerting/common/parse_duration'; +// We _must_ import from the restricted path or we pull in _everything_ including memory leaks from Kibana core +// eslint-disable-next-line @kbn/eslint/no-restricted-paths +import { ReadOperations, WriteOperations } from '../../../alerting/server/authorization'; + +module.exports = { + parseDuration, + ReadOperations, + WriteOperations, +}; diff --git a/x-pack/plugins/security_solution/server/__mocks__/core.mock.ts b/x-pack/plugins/security_solution/server/__mocks__/core.mock.ts new file mode 100644 index 0000000000000..c5e07f9c135a7 --- /dev/null +++ b/x-pack/plugins/security_solution/server/__mocks__/core.mock.ts @@ -0,0 +1,15 @@ +/* + * 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. + */ + +// See: https://github.com/elastic/kibana/issues/117255, this creates mocks to avoid memory leaks from kibana core. + +// We _must_ import from the restricted path or we pull in _everything_ including memory leaks from Kibana core +// eslint-disable-next-line @kbn/eslint/no-restricted-paths +import { SavedObjectsUtils } from '../../../../../src/core/server/saved_objects/service/lib/utils'; +module.exports = { + SavedObjectsUtils, +}; diff --git a/x-pack/plugins/security_solution/server/__mocks__/task_manager.mock.ts b/x-pack/plugins/security_solution/server/__mocks__/task_manager.mock.ts new file mode 100644 index 0000000000000..e61080e56ea69 --- /dev/null +++ b/x-pack/plugins/security_solution/server/__mocks__/task_manager.mock.ts @@ -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. + */ + +// See: https://github.com/elastic/kibana/issues/117255, this creates mocks to avoid memory leaks from kibana core. + +// eslint-disable-next-line @kbn/eslint/no-restricted-paths +import { TaskStatus } from '../../../task_manager/server/task'; +module.exports = { + TaskStatus, +}; diff --git a/x-pack/plugins/security_solution/server/client/jest.config.js b/x-pack/plugins/security_solution/server/client/jest.config.js index ba3dd88f83303..593eb77b287e1 100644 --- a/x-pack/plugins/security_solution/server/client/jest.config.js +++ b/x-pack/plugins/security_solution/server/client/jest.config.js @@ -13,4 +13,12 @@ module.exports = { '/target/kibana-coverage/jest/x-pack/plugins/security_solution/server/client', coverageReporters: ['text', 'html'], collectCoverageFrom: ['/x-pack/plugins/security_solution/server/client/**/*.{ts,tsx}'], + // See: https://github.com/elastic/kibana/issues/117255, the moduleNameMapper creates mocks to avoid memory leaks from kibana core. + moduleNameMapper: { + 'core/server$': '/x-pack/plugins/security_solution/server/__mocks__/core.mock.ts', + 'task_manager/server$': + '/x-pack/plugins/security_solution/server/__mocks__/task_manager.mock.ts', + 'alerting/server$': '/x-pack/plugins/security_solution/server/__mocks__/alert.mock.ts', + 'actions/server$': '/x-pack/plugins/security_solution/server/__mocks__/action.mock.ts', + }, }; diff --git a/x-pack/plugins/security_solution/server/endpoint/jest.config.js b/x-pack/plugins/security_solution/server/endpoint/jest.config.js index 4fed1c5e7ac15..9bdafcc7668e3 100644 --- a/x-pack/plugins/security_solution/server/endpoint/jest.config.js +++ b/x-pack/plugins/security_solution/server/endpoint/jest.config.js @@ -13,4 +13,12 @@ module.exports = { '/target/kibana-coverage/jest/x-pack/plugins/security_solution/server/endpoint', coverageReporters: ['text', 'html'], collectCoverageFrom: ['/x-pack/plugins/security_solution/server/endpoint/**/*.{ts,tsx}'], + // See: https://github.com/elastic/kibana/issues/117255, the moduleNameMapper creates mocks to avoid memory leaks from kibana core. + moduleNameMapper: { + 'core/server$': '/x-pack/plugins/security_solution/server/__mocks__/core.mock.ts', + 'task_manager/server$': + '/x-pack/plugins/security_solution/server/__mocks__/task_manager.mock.ts', + 'alerting/server$': '/x-pack/plugins/security_solution/server/__mocks__/alert.mock.ts', + 'actions/server$': '/x-pack/plugins/security_solution/server/__mocks__/action.mock.ts', + }, }; diff --git a/x-pack/plugins/security_solution/server/fleet_integration/jest.config.js b/x-pack/plugins/security_solution/server/fleet_integration/jest.config.js index 81625081c40c6..abcd1a214c200 100644 --- a/x-pack/plugins/security_solution/server/fleet_integration/jest.config.js +++ b/x-pack/plugins/security_solution/server/fleet_integration/jest.config.js @@ -15,4 +15,12 @@ module.exports = { collectCoverageFrom: [ '/x-pack/plugins/security_solution/server/fleet_integration/**/*.{ts,tsx}', ], + // See: https://github.com/elastic/kibana/issues/117255, the moduleNameMapper creates mocks to avoid memory leaks from kibana core. + moduleNameMapper: { + 'core/server$': '/x-pack/plugins/security_solution/server/__mocks__/core.mock.ts', + 'task_manager/server$': + '/x-pack/plugins/security_solution/server/__mocks__/task_manager.mock.ts', + 'alerting/server$': '/x-pack/plugins/security_solution/server/__mocks__/alert.mock.ts', + 'actions/server$': '/x-pack/plugins/security_solution/server/__mocks__/action.mock.ts', + }, }; diff --git a/x-pack/plugins/security_solution/server/jest.config.js b/x-pack/plugins/security_solution/server/jest.config.js index 2fc23670388b9..3f5aa91c5faec 100644 --- a/x-pack/plugins/security_solution/server/jest.config.js +++ b/x-pack/plugins/security_solution/server/jest.config.js @@ -15,4 +15,12 @@ module.exports = { '/target/kibana-coverage/jest/x-pack/plugins/security_solution/server', coverageReporters: ['text', 'html'], collectCoverageFrom: ['/x-pack/plugins/security_solution/server/**/*.{ts,tsx}'], + // See: https://github.com/elastic/kibana/issues/117255, the moduleNameMapper creates mocks to avoid memory leaks from kibana core. + moduleNameMapper: { + 'core/server$': '/x-pack/plugins/security_solution/server/__mocks__/core.mock.ts', + 'task_manager/server$': + '/x-pack/plugins/security_solution/server/__mocks__/task_manager.mock.ts', + 'alerting/server$': '/x-pack/plugins/security_solution/server/__mocks__/alert.mock.ts', + 'actions/server$': '/x-pack/plugins/security_solution/server/__mocks__/action.mock.ts', + }, }; diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/__mocks__/request_context.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/__mocks__/request_context.ts index fc88e7b8b2be0..86bba69699195 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/__mocks__/request_context.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/__mocks__/request_context.ts @@ -11,7 +11,11 @@ import { coreMock } from 'src/core/server/mocks'; import { ActionsApiRequestHandlerContext } from '../../../../../../actions/server'; import { AlertingApiRequestHandlerContext } from '../../../../../../alerting/server'; import { rulesClientMock } from '../../../../../../alerting/server/mocks'; -import { actionsClientMock } from '../../../../../../actions/server/mocks'; + +// See: https://github.com/elastic/kibana/issues/117255, the moduleNameMapper creates mocks to avoid memory leaks from kibana core. +// We cannot import from "../../../../../../actions/server" directly here or we have a really bad memory issue. We cannot add this to the existing mocks we created, this fix must be here. +// eslint-disable-next-line @kbn/eslint/no-restricted-paths +import { actionsClientMock } from '../../../../../../actions/server/actions_client.mock'; import { licensingMock } from '../../../../../../licensing/server/mocks'; import { listMock } from '../../../../../../lists/server/mocks'; import { ruleRegistryMocks } from '../../../../../../rule_registry/server/mocks'; diff --git a/x-pack/plugins/security_solution/server/lib/jest.config.js b/x-pack/plugins/security_solution/server/lib/jest.config.js index 4c4c7d8d4a6b7..88b4ff927971d 100644 --- a/x-pack/plugins/security_solution/server/lib/jest.config.js +++ b/x-pack/plugins/security_solution/server/lib/jest.config.js @@ -13,4 +13,12 @@ module.exports = { '/target/kibana-coverage/jest/x-pack/plugins/security_solution/server/lib', coverageReporters: ['text', 'html'], collectCoverageFrom: ['/x-pack/plugins/security_solution/server/lib/**/*.{ts,tsx}'], + // See: https://github.com/elastic/kibana/issues/117255, the moduleNameMapper creates mocks to avoid memory leaks from kibana core. + moduleNameMapper: { + 'core/server$': '/x-pack/plugins/security_solution/server/__mocks__/core.mock.ts', + 'task_manager/server$': + '/x-pack/plugins/security_solution/server/__mocks__/task_manager.mock.ts', + 'alerting/server$': '/x-pack/plugins/security_solution/server/__mocks__/alert.mock.ts', + 'actions/server$': '/x-pack/plugins/security_solution/server/__mocks__/action.mock.ts', + }, }; diff --git a/x-pack/plugins/security_solution/server/lib/machine_learning/authz.ts b/x-pack/plugins/security_solution/server/lib/machine_learning/authz.ts index d5e8e951397c2..3b96de2d4b1d1 100644 --- a/x-pack/plugins/security_solution/server/lib/machine_learning/authz.ts +++ b/x-pack/plugins/security_solution/server/lib/machine_learning/authz.ts @@ -8,7 +8,7 @@ import { i18n } from '@kbn/i18n'; import { Type } from '@kbn/securitysolution-io-ts-alerting-types'; -import { KibanaRequest, SavedObjectsClientContract } from '../../../../../../src/core/server/'; +import { KibanaRequest, SavedObjectsClientContract } from '../../../../../../src/core/server'; import { ILicense } from '../../../../licensing/server'; import { MlPluginSetup } from '../../../../ml/server'; import { SetupPlugins } from '../../plugin'; diff --git a/x-pack/plugins/security_solution/server/search_strategy/jest.config.js b/x-pack/plugins/security_solution/server/search_strategy/jest.config.js index 93b9ddbf7a27d..22999d3c5820e 100644 --- a/x-pack/plugins/security_solution/server/search_strategy/jest.config.js +++ b/x-pack/plugins/security_solution/server/search_strategy/jest.config.js @@ -15,4 +15,12 @@ module.exports = { collectCoverageFrom: [ '/x-pack/plugins/security_solution/server/search_strategy/**/*.{ts,tsx}', ], + // See: https://github.com/elastic/kibana/issues/117255, the moduleNameMapper creates mocks to avoid memory leaks from kibana core. + moduleNameMapper: { + 'core/server$': '/x-pack/plugins/security_solution/server/__mocks__/core.mock.ts', + 'task_manager/server$': + '/x-pack/plugins/security_solution/server/__mocks__/task_manager.mock.ts', + 'alerting/server$': '/x-pack/plugins/security_solution/server/__mocks__/alert.mock.ts', + 'actions/server$': '/x-pack/plugins/security_solution/server/__mocks__/action.mock.ts', + }, }; diff --git a/x-pack/plugins/security_solution/server/usage/jest.config.js b/x-pack/plugins/security_solution/server/usage/jest.config.js index 82386fea363fe..193590dbff542 100644 --- a/x-pack/plugins/security_solution/server/usage/jest.config.js +++ b/x-pack/plugins/security_solution/server/usage/jest.config.js @@ -13,4 +13,12 @@ module.exports = { '/target/kibana-coverage/jest/x-pack/plugins/security_solution/server/usage', coverageReporters: ['text', 'html'], collectCoverageFrom: ['/x-pack/plugins/security_solution/server/usage/**/*.{ts,tsx}'], + // See: https://github.com/elastic/kibana/issues/117255, the moduleNameMapper creates mocks to avoid memory leaks from kibana core. + moduleNameMapper: { + 'core/server$': '/x-pack/plugins/security_solution/server/__mocks__/core.mock.ts', + 'task_manager/server$': + '/x-pack/plugins/security_solution/server/__mocks__/task_manager.mock.ts', + 'alerting/server$': '/x-pack/plugins/security_solution/server/__mocks__/alert.mock.ts', + 'actions/server$': '/x-pack/plugins/security_solution/server/__mocks__/action.mock.ts', + }, }; diff --git a/x-pack/plugins/security_solution/server/utils/jest.config.js b/x-pack/plugins/security_solution/server/utils/jest.config.js index d3a2e138b789d..ceaa2d790da2f 100644 --- a/x-pack/plugins/security_solution/server/utils/jest.config.js +++ b/x-pack/plugins/security_solution/server/utils/jest.config.js @@ -13,4 +13,12 @@ module.exports = { '/target/kibana-coverage/jest/x-pack/plugins/security_solution/server/utils', coverageReporters: ['text', 'html'], collectCoverageFrom: ['/x-pack/plugins/security_solution/server/utils/**/*.{ts,tsx}'], + // See: https://github.com/elastic/kibana/issues/117255, the moduleNameMapper creates mocks to avoid memory leaks from kibana core. + moduleNameMapper: { + 'core/server$': '/x-pack/plugins/security_solution/server/__mocks__/core.mock.ts', + 'task_manager/server$': + '/x-pack/plugins/security_solution/server/__mocks__/task_manager.mock.ts', + 'alerting/server$': '/x-pack/plugins/security_solution/server/__mocks__/alert.mock.ts', + 'actions/server$': '/x-pack/plugins/security_solution/server/__mocks__/action.mock.ts', + }, };