From 4a17afea6184847e7de695a496e61100ac5ea61f Mon Sep 17 00:00:00 2001 From: Dzmitry Lemechko Date: Wed, 2 Jul 2025 11:23:16 +0300 Subject: [PATCH 1/4] [scout] adding ESLint rules for test package imports (#225791) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary Adding ESLint rules to control the proper test package is used for testing: - platform tests should import only from `@kbn/scout` - solution tests should import only from solution-specific scout package (e.g. security plugins => `@kbn/scout-security`) example: ``` ERROR /Users/dmle/github/kibana/x-pack/solutions/observability/plugins/apm/ui_tests/parallel_tests/service_inventory/service_inventory.spec.ts 7:1 error '@kbn/scout' import is restricted from being used by a pattern. Observability solution tests should import from '@kbn/scout-oblt' instead no-restricted-imports ✖ 1 problem (1 error, 0 warnings) ``` --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com> (cherry picked from commit 4c6ab87ddf409ca92db7f8278a851e3751c6bb99) # Conflicts: # x-pack/solutions/observability/plugins/observability/tsconfig.json # x-pack/solutions/observability/plugins/observability/ui_tests/fixtures/generators.ts --- .eslintrc.js | 77 +++++++++++++++++++ .../plugins/shared/streams_app/tsconfig.json | 2 +- .../packages/kbn-scout-oblt/index.ts | 1 + .../plugins/observability/tsconfig.json | 7 +- .../ui_tests/fixtures/generators.ts | 58 ++++++++++++++ 5 files changed, 142 insertions(+), 3 deletions(-) create mode 100644 x-pack/solutions/observability/plugins/observability/ui_tests/fixtures/generators.ts diff --git a/.eslintrc.js b/.eslintrc.js index fff0e3a9d62f8..c86967aeeca5c 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -2316,6 +2316,83 @@ module.exports = { ], }, }, + { + files: [ + 'src/platform/plugins/**/ui_tests/**/*.ts', + 'x-pack/platform/**/plugins/**/ui_tests/**/*.ts', + ], + rules: { + 'no-restricted-imports': [ + 'error', + { + paths: [ + { + name: '@playwright/test', + message: "Platform tests should import only from '@kbn/scout'.", + }, + { + name: 'playwright', + message: "Platform tests should import only from '@kbn/scout'.", + }, + ], + }, + ], + }, + }, + { + files: ['x-pack/solutions/observability/plugins/**/ui_tests/**/*.ts'], + rules: { + 'no-restricted-imports': [ + 'error', + { + paths: [ + { + name: '@kbn/scout', + message: + "Observability solution tests should import from '@kbn/scout-oblt' instead.", + }, + { + name: '@playwright/test', + message: + "Observability solution tests should import from '@kbn/scout-oblt' instead.", + }, + { + name: 'playwright', + message: + "Observability solution tests should import from '@kbn/scout-oblt' instead.", + }, + ], + }, + ], + }, + }, + { + files: ['x-pack/solutions/security/plugins/**/ui_tests/**/*.ts'], + rules: { + 'no-restricted-imports': [ + 'error', + { + paths: [ + { + name: '@kbn/scout', + message: + "Security solution tests should import from '@kbn/scout-security' instead.", + }, + { + name: '@playwright/test', + message: + "Security solution tests should import from '@kbn/scout-security' instead.", + }, + { + name: 'playwright', + message: + "Security solution tests should import from '@kbn/scout-security' instead.", + }, + ], + }, + ], + }, + }, ], }; diff --git a/x-pack/platform/plugins/shared/streams_app/tsconfig.json b/x-pack/platform/plugins/shared/streams_app/tsconfig.json index 27ad746c690c6..5cf63f87ad3ee 100644 --- a/x-pack/platform/plugins/shared/streams_app/tsconfig.json +++ b/x-pack/platform/plugins/shared/streams_app/tsconfig.json @@ -75,6 +75,6 @@ "@kbn/kibana-utils-plugin", "@kbn/field-types", "@kbn/field-formats-plugin", - "@kbn/test" + "@kbn/test", ] } diff --git a/x-pack/solutions/observability/packages/kbn-scout-oblt/index.ts b/x-pack/solutions/observability/packages/kbn-scout-oblt/index.ts index 057cf957ba13f..cd86b3dae87b7 100644 --- a/x-pack/solutions/observability/packages/kbn-scout-oblt/index.ts +++ b/x-pack/solutions/observability/packages/kbn-scout-oblt/index.ts @@ -35,4 +35,5 @@ export type { ScoutPlaywrightOptions, ScoutTestOptions, Locator, + SynthtraceFixture, } from '@kbn/scout'; diff --git a/x-pack/solutions/observability/plugins/observability/tsconfig.json b/x-pack/solutions/observability/plugins/observability/tsconfig.json index baa1f1f88bd15..d53eac656bcfc 100644 --- a/x-pack/solutions/observability/plugins/observability/tsconfig.json +++ b/x-pack/solutions/observability/plugins/observability/tsconfig.json @@ -124,6 +124,9 @@ "@kbn/core-saved-objects-server", "@kbn/core-pricing-browser-mocks", "@kbn/esql", + "@kbn/apm-synthtrace-client", ], - "exclude": ["target/**/*"] -} + "exclude": [ + "target/**/*" + ] +} \ No newline at end of file diff --git a/x-pack/solutions/observability/plugins/observability/ui_tests/fixtures/generators.ts b/x-pack/solutions/observability/plugins/observability/ui_tests/fixtures/generators.ts new file mode 100644 index 0000000000000..d8b7bf130085a --- /dev/null +++ b/x-pack/solutions/observability/plugins/observability/ui_tests/fixtures/generators.ts @@ -0,0 +1,58 @@ +/* + * 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 { SynthtraceFixture } from '@kbn/scout-oblt'; +import { apm, log, timerange } from '@kbn/apm-synthtrace-client'; + +const TEST_START_TIME = '2024-01-01T00:00:00.000Z'; +const TEST_END_TIME = '2024-01-01T01:00:00.000Z'; + +/** + * Generate synthetic logs data for testing + */ +export async function generateLogsData( + logsSynthtraceEsClient: SynthtraceFixture['logsSynthtraceEsClient'] +) { + const logsData = timerange(TEST_START_TIME, TEST_END_TIME) + .interval('1m') + .rate(1) + .generator((timestamp) => + log + .create() + .message('Test log message') + .timestamp(timestamp) + .dataset('synth.test') + .namespace('default') + .logLevel(Math.random() > 0.5 ? 'info' : 'warn') + .defaults({ + 'service.name': 'test-service', + }) + ); + + await logsSynthtraceEsClient.index(logsData); +} + +/** + * Generate synthetic APM data for testing + */ +export async function generateApmData( + apmSynthtraceEsClient: SynthtraceFixture['apmSynthtraceEsClient'] +) { + const apmData = timerange(TEST_START_TIME, TEST_END_TIME) + .interval('1m') + .rate(1) + .generator((timestamp) => + apm + .service({ name: 'test-service-1', environment: 'test', agentName: 'nodejs' }) + .instance('instance-1') + .transaction({ transactionName: 'GET /api/test' }) + .timestamp(timestamp) + .duration(100) + .success() + ); + + await apmSynthtraceEsClient.index(apmData); +} From 67d4a97f3d66cd4bb643377e428dd99714bf03f3 Mon Sep 17 00:00:00 2001 From: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Date: Wed, 2 Jul 2025 10:43:02 +0000 Subject: [PATCH 2/4] [CI] Auto-commit changed files from 'node scripts/styled_components_mapping' --- .../observability/plugins/observability/tsconfig.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/x-pack/solutions/observability/plugins/observability/tsconfig.json b/x-pack/solutions/observability/plugins/observability/tsconfig.json index d53eac656bcfc..9d8a9590fd6f4 100644 --- a/x-pack/solutions/observability/plugins/observability/tsconfig.json +++ b/x-pack/solutions/observability/plugins/observability/tsconfig.json @@ -124,9 +124,8 @@ "@kbn/core-saved-objects-server", "@kbn/core-pricing-browser-mocks", "@kbn/esql", - "@kbn/apm-synthtrace-client", ], "exclude": [ "target/**/*" ] -} \ No newline at end of file +} From d03193bdd74a7445e1d4c0f6bb4bcf34d2832d62 Mon Sep 17 00:00:00 2001 From: Dzmitry Lemechko Date: Wed, 2 Jul 2025 14:53:49 +0200 Subject: [PATCH 3/4] Delete x-pack/solutions/observability/plugins/observability/ui_tests/fixtures/generators.ts --- .../ui_tests/fixtures/generators.ts | 58 ------------------- 1 file changed, 58 deletions(-) delete mode 100644 x-pack/solutions/observability/plugins/observability/ui_tests/fixtures/generators.ts diff --git a/x-pack/solutions/observability/plugins/observability/ui_tests/fixtures/generators.ts b/x-pack/solutions/observability/plugins/observability/ui_tests/fixtures/generators.ts deleted file mode 100644 index d8b7bf130085a..0000000000000 --- a/x-pack/solutions/observability/plugins/observability/ui_tests/fixtures/generators.ts +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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 { SynthtraceFixture } from '@kbn/scout-oblt'; -import { apm, log, timerange } from '@kbn/apm-synthtrace-client'; - -const TEST_START_TIME = '2024-01-01T00:00:00.000Z'; -const TEST_END_TIME = '2024-01-01T01:00:00.000Z'; - -/** - * Generate synthetic logs data for testing - */ -export async function generateLogsData( - logsSynthtraceEsClient: SynthtraceFixture['logsSynthtraceEsClient'] -) { - const logsData = timerange(TEST_START_TIME, TEST_END_TIME) - .interval('1m') - .rate(1) - .generator((timestamp) => - log - .create() - .message('Test log message') - .timestamp(timestamp) - .dataset('synth.test') - .namespace('default') - .logLevel(Math.random() > 0.5 ? 'info' : 'warn') - .defaults({ - 'service.name': 'test-service', - }) - ); - - await logsSynthtraceEsClient.index(logsData); -} - -/** - * Generate synthetic APM data for testing - */ -export async function generateApmData( - apmSynthtraceEsClient: SynthtraceFixture['apmSynthtraceEsClient'] -) { - const apmData = timerange(TEST_START_TIME, TEST_END_TIME) - .interval('1m') - .rate(1) - .generator((timestamp) => - apm - .service({ name: 'test-service-1', environment: 'test', agentName: 'nodejs' }) - .instance('instance-1') - .transaction({ transactionName: 'GET /api/test' }) - .timestamp(timestamp) - .duration(100) - .success() - ); - - await apmSynthtraceEsClient.index(apmData); -} From d68dd8f2b392c00000dcc86ce85abcc64bf67671 Mon Sep 17 00:00:00 2001 From: Dzmitry Lemechko Date: Wed, 2 Jul 2025 16:07:51 +0200 Subject: [PATCH 4/4] Update index.ts --- x-pack/solutions/observability/packages/kbn-scout-oblt/index.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/x-pack/solutions/observability/packages/kbn-scout-oblt/index.ts b/x-pack/solutions/observability/packages/kbn-scout-oblt/index.ts index cd86b3dae87b7..057cf957ba13f 100644 --- a/x-pack/solutions/observability/packages/kbn-scout-oblt/index.ts +++ b/x-pack/solutions/observability/packages/kbn-scout-oblt/index.ts @@ -35,5 +35,4 @@ export type { ScoutPlaywrightOptions, ScoutTestOptions, Locator, - SynthtraceFixture, } from '@kbn/scout';