From d8445ccab6cff2b2d4f238ecf6f4af245af72ba0 Mon Sep 17 00:00:00 2001 From: Yngrid Coello Date: Fri, 6 Sep 2024 12:49:44 +0200 Subject: [PATCH] [Logs explorer] Using dockerized package registry in tests (#192064) Closes https://github.com/elastic/kibana/issues/190343. This PR aims to use a dockerized package registry version for testing. In order to test it locally you have to set the value of `FLEET_PACKAGE_REGISTRY_PORT` env var in your terminal, and you also need to have a docker daemon running. For example, you can open a terminal and start the server ``` yarn test:ftr:server --config ./x-pack/test/functional/apps/observability_logs_explorer/config.ts ``` then open a new terminal set the var value and start the runner with the specific test using this configuration ``` export set FLEET_PACKAGE_REGISTRY_PORT=12345 yarn test:ftr:runner --config ./x-pack/test/functional/apps/observability_logs_explorer/config.ts --include ./x-pack/test/functional/apps/observability_logs_explorer/data_source_selector ``` If you want to test again without the dockerized version, you should remove the value of the var ``` unset FLEET_PACKAGE_REGISTRY_PORT ``` --- .../observability_logs_explorer/README.md | 16 ++++++++++ .../common/package_registry_config.yml | 2 ++ .../observability_logs_explorer/config.ts | 30 ++++++++++++++++++- x-pack/test_serverless/README.md | 18 ++++++++++- .../test_serverless/functional/config.base.ts | 6 ++-- .../shared/common/package_registry_config.yml | 2 ++ x-pack/test_serverless/shared/config.base.ts | 25 ++++++++++++++++ 7 files changed, 93 insertions(+), 6 deletions(-) create mode 100644 x-pack/test/functional/apps/observability_logs_explorer/common/package_registry_config.yml create mode 100644 x-pack/test_serverless/shared/common/package_registry_config.yml diff --git a/x-pack/plugins/observability_solution/observability_logs_explorer/README.md b/x-pack/plugins/observability_solution/observability_logs_explorer/README.md index f3546186c1ef3..8f060d48b04f5 100644 --- a/x-pack/plugins/observability_solution/observability_logs_explorer/README.md +++ b/x-pack/plugins/observability_solution/observability_logs_explorer/README.md @@ -37,6 +37,22 @@ yarn test:ftr:runner --config ./x-pack/test_serverless/functional/test_suites/ob yarn test:ftr:runner --config ./x-pack/test_serverless/functional/test_suites/observability/config.ts --include ./x-pack/test_serverless/functional/test_suites/observability/observability_logs_explorer/$1 ``` +### Using dockerized package registry + +For tests using package registry we have enabled a configuration that uses a dockerized lite version to execute the tests in the CI, this will reduce the flakyness of them when calling the real endpoint. + +To be able to run this version locally you must have a docker daemon running in your system and set `FLEET_PACKAGE_REGISTRY_PORT` env var. In order to set this variable execute + +``` +export set FLEET_PACKAGE_REGISTRY_PORT=12345 +``` + +To unset the variable, and run the tests against the real endpoint again, execute + +``` +unset FLEET_PACKAGE_REGISTRY_PORT +``` + ## Checktypes #### Logs Explorer diff --git a/x-pack/test/functional/apps/observability_logs_explorer/common/package_registry_config.yml b/x-pack/test/functional/apps/observability_logs_explorer/common/package_registry_config.yml new file mode 100644 index 0000000000000..1885fa5c2ebe5 --- /dev/null +++ b/x-pack/test/functional/apps/observability_logs_explorer/common/package_registry_config.yml @@ -0,0 +1,2 @@ +package_paths: + - /packages/package-storage diff --git a/x-pack/test/functional/apps/observability_logs_explorer/config.ts b/x-pack/test/functional/apps/observability_logs_explorer/config.ts index 0811f0e2a794e..74c54a9c9e953 100644 --- a/x-pack/test/functional/apps/observability_logs_explorer/config.ts +++ b/x-pack/test/functional/apps/observability_logs_explorer/config.ts @@ -5,8 +5,14 @@ * 2.0. */ -import { FtrConfigProviderContext, GenericFtrProviderContext } from '@kbn/test'; +import { + FtrConfigProviderContext, + GenericFtrProviderContext, + defineDockerServersConfig, +} from '@kbn/test'; import { createLogger, LogLevel, LogsSynthtraceEsClient } from '@kbn/apm-synthtrace'; +import path from 'path'; +import { dockerImage } from '../../../fleet_api_integration/config.base'; import { FtrProviderContext as InheritedFtrProviderContext } from '../../ftr_provider_context'; export type InheritedServices = InheritedFtrProviderContext extends GenericFtrProviderContext< @@ -37,9 +43,31 @@ export default async function createTestConfig({ const functionalConfig = await readConfigFile(require.resolve('../../config.base.js')); const services = functionalConfig.get('services'); + const packageRegistryConfig = path.join(__dirname, './common/package_registry_config.yml'); + const dockerArgs: string[] = ['-v', `${packageRegistryConfig}:/package-registry/config.yml`]; + + /** + * This is used by CI to set the docker registry port + * you can also define this environment variable locally when running tests which + * will spin up a local docker package registry locally for you + * if this is defined it takes precedence over the `packageRegistryOverride` variable + */ + const dockerRegistryPort: string | undefined = process.env.FLEET_PACKAGE_REGISTRY_PORT; + return { ...functionalConfig.getAll(), testFiles: [require.resolve('.')], + dockerServers: defineDockerServersConfig({ + registry: { + enabled: !!dockerRegistryPort, + image: dockerImage, + portInContainer: 8080, + port: dockerRegistryPort, + args: dockerArgs, + waitForLogLine: 'package manifests loaded', + waitForLogLineTimeoutMs: 60 * 2 * 1000, // 2 minutes + }, + }), services: { ...services, logSynthtraceEsClient: (context: InheritedFtrProviderContext) => { diff --git a/x-pack/test_serverless/README.md b/x-pack/test_serverless/README.md index 18bc002d7488d..d7bb3d62d552a 100644 --- a/x-pack/test_serverless/README.md +++ b/x-pack/test_serverless/README.md @@ -259,4 +259,20 @@ describe("my test suite", async function() { }); ``` -If you are running tests from your local against MKI projects, make sure to add `--exclude-tag=skipMKI` to your FTR command. \ No newline at end of file +If you are running tests from your local against MKI projects, make sure to add `--exclude-tag=skipMKI` to your FTR command. + +## Run tests with dockerized package registry + +For tests using package registry we have enabled a configuration that uses a dockerized lite version to execute the tests in the CI, this will reduce the flakyness of them when calling the real endpoint. + +To be able to run this version locally you must have a docker daemon running in your system and set `FLEET_PACKAGE_REGISTRY_PORT` env var. In order to set this variable execute + +``` +export set FLEET_PACKAGE_REGISTRY_PORT=12345 +``` + +To unset the variable, and run the tests against the real endpoint again, execute + +``` +unset FLEET_PACKAGE_REGISTRY_PORT +``` diff --git a/x-pack/test_serverless/functional/config.base.ts b/x-pack/test_serverless/functional/config.base.ts index 22fb253d9896b..826b8bce03885 100644 --- a/x-pack/test_serverless/functional/config.base.ts +++ b/x-pack/test_serverless/functional/config.base.ts @@ -5,10 +5,8 @@ * 2.0. */ -import { resolve } from 'path'; - import { FtrConfigProviderContext } from '@kbn/test'; - +import { resolve } from 'path'; import { pageObjects } from './page_objects'; import { services } from './services'; import type { CreateTestConfigOptions } from '../shared/types'; @@ -16,6 +14,7 @@ import type { CreateTestConfigOptions } from '../shared/types'; export function createTestConfig(options: CreateTestConfigOptions) { return async ({ readConfigFile }: FtrConfigProviderContext) => { const svlSharedConfig = await readConfigFile(require.resolve('../shared/config.base.ts')); + return { ...svlSharedConfig.getAll(), @@ -37,7 +36,6 @@ export function createTestConfig(options: CreateTestConfigOptions) { ], }, testFiles: options.testFiles, - uiSettings: { defaults: { 'accessibility:disableAnimations': true, diff --git a/x-pack/test_serverless/shared/common/package_registry_config.yml b/x-pack/test_serverless/shared/common/package_registry_config.yml new file mode 100644 index 0000000000000..1885fa5c2ebe5 --- /dev/null +++ b/x-pack/test_serverless/shared/common/package_registry_config.yml @@ -0,0 +1,2 @@ +package_paths: + - /packages/package-storage diff --git a/x-pack/test_serverless/shared/config.base.ts b/x-pack/test_serverless/shared/config.base.ts index 099bc6455db3d..1c702f02cff28 100644 --- a/x-pack/test_serverless/shared/config.base.ts +++ b/x-pack/test_serverless/shared/config.base.ts @@ -19,9 +19,23 @@ import { import { CA_CERT_PATH, kibanaDevServiceAccount } from '@kbn/dev-utils'; import { commonFunctionalServices } from '@kbn/ftr-common-functional-services'; import { MOCK_IDP_REALM_NAME } from '@kbn/mock-idp-utils'; +import path from 'path'; +import { defineDockerServersConfig } from '@kbn/test'; +import { dockerImage } from '@kbn/test-suites-xpack/fleet_api_integration/config.base'; import { services } from './services'; export default async () => { + const packageRegistryConfig = path.join(__dirname, './common/package_registry_config.yml'); + const dockerArgs: string[] = ['-v', `${packageRegistryConfig}:/package-registry/config.yml`]; + + /** + * This is used by CI to set the docker registry port + * you can also define this environment variable locally when running tests which + * will spin up a local docker package registry locally for you + * if this is defined it takes precedence over the `packageRegistryOverride` variable + */ + const dockerRegistryPort: string | undefined = process.env.FLEET_PACKAGE_REGISTRY_PORT; + const servers = { kibana: { ...kbnTestConfig.getUrlParts(kibanaTestSuperuserServerless), @@ -49,6 +63,17 @@ export default async () => { return { servers, + dockerServers: defineDockerServersConfig({ + registry: { + enabled: !!dockerRegistryPort, + image: dockerImage, + portInContainer: 8080, + port: dockerRegistryPort, + args: dockerArgs, + waitForLogLine: 'package manifests loaded', + waitForLogLineTimeoutMs: 60 * 2 * 1000, // 2 minutes + }, + }), browser: { acceptInsecureCerts: true, },