Skip to content

Commit

Permalink
[Logs explorer] Using dockerized package registry in tests (elastic#1…
Browse files Browse the repository at this point in the history
…92064)

Closes elastic#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 
```
  • Loading branch information
yngrdyn authored Sep 6, 2024
1 parent ad7d935 commit d8445cc
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
package_paths:
- /packages/package-storage
Original file line number Diff line number Diff line change
Expand Up @@ -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<
Expand Down Expand Up @@ -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) => {
Expand Down
18 changes: 17 additions & 1 deletion x-pack/test_serverless/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
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
```
6 changes: 2 additions & 4 deletions x-pack/test_serverless/functional/config.base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,16 @@
* 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';

export function createTestConfig(options: CreateTestConfigOptions) {
return async ({ readConfigFile }: FtrConfigProviderContext) => {
const svlSharedConfig = await readConfigFile(require.resolve('../shared/config.base.ts'));

return {
...svlSharedConfig.getAll(),

Expand All @@ -37,7 +36,6 @@ export function createTestConfig(options: CreateTestConfigOptions) {
],
},
testFiles: options.testFiles,

uiSettings: {
defaults: {
'accessibility:disableAnimations': true,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
package_paths:
- /packages/package-storage
25 changes: 25 additions & 0 deletions x-pack/test_serverless/shared/config.base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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,
},
Expand Down

0 comments on commit d8445cc

Please sign in to comment.