diff --git a/packages/kbn-scout/src/servers/run_elasticsearch.ts b/packages/kbn-scout/src/servers/run_elasticsearch.ts index 5406f755f5d72..24c8a49da2d9a 100644 --- a/packages/kbn-scout/src/servers/run_elasticsearch.ts +++ b/packages/kbn-scout/src/servers/run_elasticsearch.ts @@ -12,8 +12,8 @@ import { resolve } from 'path'; import type { ToolingLog } from '@kbn/tooling-log'; import { REPO_ROOT } from '@kbn/repo-info'; import type { ArtifactLicense, ServerlessProjectType } from '@kbn/es'; -import { isServerlessProjectType, extractAndArchiveLogs } from '@kbn/es/src/utils'; -import { createTestEsCluster, esTestConfig } from '@kbn/test'; +import { isServerlessProjectType } from '@kbn/es/src/utils'; +import { createTestEsCluster, esTestConfig, cleanupElasticsearch } from '@kbn/test'; import { Config } from '../config'; interface RunElasticsearchOptions { @@ -82,8 +82,7 @@ export async function runElasticsearch( config, }); return async () => { - await node.cleanup(); - await extractAndArchiveLogs({ outputFolder: logsDir, log }); + await cleanupElasticsearch(node, config.serverless, logsDir, log); }; } diff --git a/packages/kbn-test/index.ts b/packages/kbn-test/index.ts index bd196e27c8cb0..b5506cc804ad3 100644 --- a/packages/kbn-test/index.ts +++ b/packages/kbn-test/index.ts @@ -22,6 +22,7 @@ export { remapPluginPaths, getKibanaCliArg, getKibanaCliLoggers, + cleanupElasticsearch, } from './src/functional_tests/lib'; export { initLogsDir } from './src/functional_tests/lib'; diff --git a/packages/kbn-test/src/functional_tests/lib/index.ts b/packages/kbn-test/src/functional_tests/lib/index.ts index 23c6ec8331602..62275737f6d47 100644 --- a/packages/kbn-test/src/functional_tests/lib/index.ts +++ b/packages/kbn-test/src/functional_tests/lib/index.ts @@ -8,7 +8,7 @@ */ export { runKibanaServer } from './run_kibana_server'; -export { runElasticsearch } from './run_elasticsearch'; +export { runElasticsearch, cleanupElasticsearch } from './run_elasticsearch'; export * from './run_ftr'; export { parseRawFlags, diff --git a/packages/kbn-test/src/functional_tests/lib/run_elasticsearch.ts b/packages/kbn-test/src/functional_tests/lib/run_elasticsearch.ts index 964359cdb7ee5..6e082c7083b37 100644 --- a/packages/kbn-test/src/functional_tests/lib/run_elasticsearch.ts +++ b/packages/kbn-test/src/functional_tests/lib/run_elasticsearch.ts @@ -16,7 +16,7 @@ import { REPO_ROOT } from '@kbn/repo-info'; import type { ArtifactLicense, ServerlessProjectType } from '@kbn/es'; import { isServerlessProjectType, extractAndArchiveLogs } from '@kbn/es/src/utils'; import type { Config } from '../../functional_test_runner'; -import { createTestEsCluster, esTestConfig } from '../../es'; +import { ICluster, createTestEsCluster, esTestConfig } from '../../es'; interface RunElasticsearchOptions { log: ToolingLog; @@ -77,6 +77,19 @@ function getEsConfig({ }; } +export async function cleanupElasticsearch( + node: ICluster, + isServerless: boolean, + logsDir: string | undefined, + log: ToolingLog +): Promise { + await node.cleanup(); + + if (isServerless) { + await extractAndArchiveLogs({ outputFolder: logsDir, log }); + } +} + export async function runElasticsearch( options: RunElasticsearchOptions ): Promise<() => Promise> { @@ -91,8 +104,7 @@ export async function runElasticsearch( config, }); return async () => { - await node.cleanup(); - await extractAndArchiveLogs({ outputFolder: logsDir, log }); + await cleanupElasticsearch(node, config.serverless, logsDir, log); }; }