Skip to content

Commit 8023de9

Browse files
skhelasticmachine
andcommitted
[Ingest Manager] Use DockerServers service in integration tests. (#69822)
* Partially disable test files. * Use DockerServers in EPM tests. * Only run tests when DockerServers have been set up * Reenable ingest manager API integration tests * Pass new test_packages to registry container * Enable DockerServers tests in CI. * Correctly serve filetest package for file tests. * Add helper to skip test and log warning. * Reenable further file tests. * Add developer documentation about Docker in Kibana CI. * Document use of yarn test:ftr Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com> # Conflicts: # x-pack/scripts/functional_tests.js
1 parent 2c48a90 commit 8023de9

24 files changed

Lines changed: 474 additions & 343 deletions

File tree

vars/kibanaPipeline.groovy

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ def functionalTestProcess(String name, Closure closure) {
2121
def kibanaPort = "61${processNumber}1"
2222
def esPort = "61${processNumber}2"
2323
def esTransportPort = "61${processNumber}3"
24+
def ingestManagementPackageRegistryPort = "61${processNumber}4"
2425

2526
withEnv([
2627
"CI_PARALLEL_PROCESS_NUMBER=${processNumber}",
@@ -29,6 +30,7 @@ def functionalTestProcess(String name, Closure closure) {
2930
"TEST_KIBANA_URL=http://elastic:changeme@localhost:${kibanaPort}",
3031
"TEST_ES_URL=http://elastic:changeme@localhost:${esPort}",
3132
"TEST_ES_TRANSPORT_PORT=${esTransportPort}",
33+
"INGEST_MANAGEMENT_PACKAGE_REGISTRY_PORT=${ingestManagementPackageRegistryPort}",
3234
"IS_PIPELINE_JOB=1",
3335
"JOB=${name}",
3436
"KBN_NP_PLUGINS_BUILT=true",
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
# API integration tests
2+
3+
Many API integration tests for Ingest Manager trigger at some point a connection to the package registry, and retrieval of some packages. If these connections are made to a package registry deployment outside of Kibana CI, these tests can fail at any time for two reasons:
4+
* the deployed registry is temporarily unavailable
5+
* the packages served by the registry do not match the expectation of the code under test
6+
7+
For that reason, we run a dockerized version of the package registry in Kibana CI. For this to work, our tests must run against a custom test configuration and be kept in a custom directory, `x-pack/test/ingest_manager_api_integration`.
8+
9+
## How to run the tests locally
10+
11+
Usually, having the test server and the test runner in two different shells is most efficient, as it is possible to keep the server running and only rerun the test runner as often as needed. To do so, in one shell in the main `kibana` directory, run:
12+
```
13+
$ export INGEST_MANAGEMENT_PACKAGE_REGISTRY_PORT=12345
14+
$ yarn test:ftr:server --config x-pack/test/ingest_manager_api_integration/config.ts
15+
```
16+
17+
In another shell in the same directory, run
18+
```
19+
$ export INGEST_MANAGEMENT_PACKAGE_REGISTRY_PORT=12345
20+
$ yarn test:ftr:runner --config x-pack/test/ingest_manager_api_integration/config.ts
21+
```
22+
23+
However, it is also possible to **alternatively** run everything in one go, again from the main `kibana` directory:
24+
```
25+
$ export INGEST_MANAGEMENT_PACKAGE_REGISTRY_PORT=12345
26+
$ yarn test:ftr --config x-pack/test/ingest_manager_api_integration/config.ts
27+
```
28+
Port `12345` is used as an example here, it can be anything, but the environment variable has to be present for the tests to run at all.
29+
30+
31+
## DockerServers service setup
32+
33+
We use the `DockerServers` service provided by `kbn-test`. The documentation for this functionality can be found here:
34+
https://github.com/elastic/kibana/blob/master/packages/kbn-test/src/functional_test_runner/lib/docker_servers/README.md
35+
36+
The main configuration for the `DockerServers` service for our tests can be found in `x-pack/test/ingest_manager_api_integration/config.ts`:
37+
38+
### Specify the arguments to pass to `docker run`:
39+
40+
```
41+
const dockerArgs: string[] = [
42+
'-v',
43+
`${path.join(
44+
path.dirname(__filename),
45+
'./apis/fixtures/package_registry_config.yml'
46+
)}:/registry/config.yml`,
47+
'-v',
48+
`${path.join(
49+
path.dirname(__filename),
50+
'./apis/fixtures/test_packages'
51+
)}:/registry/packages/test-packages`,
52+
];
53+
```
54+
55+
`-v` mounts local paths into the docker image. The first one puts a custom configuration file into the correct place in the docker container, the second one mounts a directory containing additional packages.
56+
57+
### Specify the docker image to use
58+
59+
```
60+
image: 'docker.elastic.co/package-registry/package-registry:kibana-testing-1'
61+
```
62+
63+
This image contains the content of `docker.elastic.co/package-registry/package-registry:master` on June 26 2020. The image used here should be stable, i.e. using `master` would defeat the purpose of having a stable set of packages to be used in Kibana CI.
64+
65+
### Packages available for testing
66+
67+
The containerized package registry contains a set of packages which should be sufficient to run tests against all parts of Ingest Manager. The list of the packages are logged to the console when the docker container is initialized during testing, or when the container is started manually with
68+
69+
```
70+
docker run -p 8080:8080 docker.elastic.co/package-registry/package-registry:kibana-testing-1
71+
```
72+
73+
Additional packages for testing certain corner cases or error conditions can be put into `x-pack/test/ingest_manager_api_integration/apis/fixtures/test_packages`. A package `filetest` has been added there as an example.
74+
75+
## Some DockerServers background
76+
77+
For the `DockerServers` servers to run correctly in CI, the `INGEST_MANAGEMENT_PACKAGE_REGISTRY_PORT` environment variable needs to be under control of the CI environment. The reason behind this: it is possible that several versions of our tests are run in parallel on the same worker in Jenkins, and if we used a hard-coded port number here, those tests would run into port conflicts. (This is also the case for a few other ports, and the setup happens in `vars/kibanaPipeline.groovy`).
78+
79+
Also, not every developer has `docker` installed on their workstation, so it must be possible to run the testsuite as a whole without `docker`, and preferably this should be the default behaviour. Therefore, our `DockerServers` service is only enabled when `INGEST_MANAGEMENT_PACKAGE_REGISTRY_PORT` is set. This needs to be checked in every test like this:
80+
81+
```
82+
it('fetches a .json search file', async function () {
83+
if (server.enabled) {
84+
await supertest
85+
.get('/api/ingest_manager/epm/packages/filetest/0.1.0/kibana/search/sample_search.json')
86+
.set('kbn-xsrf', 'xxx')
87+
.expect('Content-Type', 'application/json; charset=utf-8')
88+
.expect(200);
89+
} else {
90+
warnAndSkipTest(this, log);
91+
}
92+
});
93+
```
94+
95+
If the tests are skipped in this way, they are marked in the test summary as `pending` and a warning is logged:
96+
97+
```
98+
└-: EPM Endpoints
99+
└-> "before all" hook
100+
└-: list
101+
└-> "before all" hook
102+
└-> lists all packages from the registry
103+
└-> "before each" hook: global before each
104+
│ warn disabling tests because DockerServers service is not enabled, set INGEST_MANAGEMENT_PACKAGE_REGISTRY_PORT to run them
105+
└-> lists all packages from the registry
106+
└-> "after all" hook
107+
[...]
108+
109+
│1 passing (233ms)
110+
│6 pending
111+
112+
113+
```

x-pack/scripts/functional_tests.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,5 @@ require('@kbn/test').runTestsCli([
5252
require.resolve('../test/endpoint_api_integration_no_ingest/config.ts'),
5353
require.resolve('../test/reporting_api_integration/config.js'),
5454
require.resolve('../test/functional_embedded/config.ts'),
55+
require.resolve('../test/ingest_manager_api_integration/config.ts'),
5556
]);

x-pack/test/epm_api_integration/apis/file.ts

Lines changed: 0 additions & 151 deletions
This file was deleted.
Binary file not shown.

x-pack/test/epm_api_integration/apis/fixtures/packages/package/yamlpipeline_1.0.0

Lines changed: 0 additions & 32 deletions
This file was deleted.

0 commit comments

Comments
 (0)