-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Ingest Manager] Use DockerServers service in integration tests. #69822
Merged
Merged
Changes from 12 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
3449e25
Partially disable test files.
skh f8250f7
Use DockerServers in EPM tests.
skh 9c20197
Only run tests when DockerServers have been set up
skh 536cc69
Reenable ingest manager API integration tests
skh 8eadb6e
Pass new test_packages to registry container
skh 2c4d1a6
Enable DockerServers tests in CI.
skh ef693e8
Correctly serve filetest package for file tests.
skh 6304146
Add helper to skip test and log warning.
skh e4bddfd
Reenable further file tests.
skh 4190651
Add developer documentation about Docker in Kibana CI.
skh 31b29f1
Merge branch 'master' into 61699-docker-registry-ci
elasticmachine a8ecc01
Merge branch 'master' into 61699-docker-registry-ci
elasticmachine 51dc949
Document use of yarn test:ftr
skh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
x-pack/plugins/ingest_manager/dev_docs/api_integration_tests.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
# API integration tests | ||
|
||
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: | ||
* the deployed registry is temporarily unavailable | ||
* the packages served by the registry do not match the expectation of the code under test | ||
|
||
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`. | ||
|
||
## How to run the tests locally | ||
|
||
In the `x-pack` directory, run: | ||
``` | ||
$ export INGEST_MANAGEMENT_PACKAGE_REGISTRY_PORT=12345 | ||
$ node scripts/functional_tests_server.js --config test/ingest_manager_api_integration/config.ts | ||
``` | ||
|
||
In the main kibana directory, run | ||
``` | ||
$ export INGEST_MANAGEMENT_PACKAGE_REGISTRY_PORT=12345 | ||
$ node scripts/functional_test_runner.js --config x-pack/test/ingest_manager_api_integration/config.ts | ||
``` | ||
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. | ||
|
||
|
||
## DockerServers service setup | ||
|
||
We use the `DockerServers` service provided by `kbn-test`. The documentation for this functionality can be found here: | ||
https://github.com/elastic/kibana/blob/master/packages/kbn-test/src/functional_test_runner/lib/docker_servers/README.md | ||
|
||
The main configuration for the `DockerServers` service for our tests can be found in `x-pack/test/ingest_manager_api_integration/config.ts`: | ||
|
||
### Specify the arguments to pass to `docker run`: | ||
|
||
``` | ||
const dockerArgs: string[] = [ | ||
'-v', | ||
`${path.join( | ||
path.dirname(__filename), | ||
'./apis/fixtures/package_registry_config.yml' | ||
)}:/registry/config.yml`, | ||
'-v', | ||
`${path.join( | ||
path.dirname(__filename), | ||
'./apis/fixtures/test_packages' | ||
)}:/registry/packages/test-packages`, | ||
]; | ||
``` | ||
|
||
`-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. | ||
|
||
### Specify the docker image to use | ||
|
||
``` | ||
image: 'docker.elastic.co/package-registry/package-registry:kibana-testing-1' | ||
``` | ||
|
||
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. | ||
|
||
### Packages available for testing | ||
|
||
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 | ||
|
||
``` | ||
docker run -p 8080:8080 docker.elastic.co/package-registry/package-registry:kibana-testing-1 | ||
``` | ||
|
||
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. | ||
|
||
## Some DockerServers background | ||
|
||
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`). | ||
|
||
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: | ||
|
||
``` | ||
it('fetches a .json search file', async function () { | ||
if (server.enabled) { | ||
await supertest | ||
.get('/api/ingest_manager/epm/packages/filetest/0.1.0/kibana/search/sample_search.json') | ||
.set('kbn-xsrf', 'xxx') | ||
.expect('Content-Type', 'application/json; charset=utf-8') | ||
.expect(200); | ||
} else { | ||
warnAndSkipTest(this, log); | ||
} | ||
}); | ||
``` | ||
|
||
If the tests are skipped in this way, they are marked in the test summary as `pending` and a warning is logged: | ||
|
||
``` | ||
└-: EPM Endpoints | ||
└-> "before all" hook | ||
└-: list | ||
└-> "before all" hook | ||
└-> lists all packages from the registry | ||
└-> "before each" hook: global before each | ||
│ warn disabling tests because DockerServers service is not enabled, set INGEST_MANAGEMENT_PACKAGE_REGISTRY_PORT to run them | ||
└-> lists all packages from the registry | ||
└-> "after all" hook | ||
[...] | ||
│ | ||
│1 passing (233ms) | ||
│6 pending | ||
│ | ||
|
||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Binary file removed
BIN
-1.95 KB
x-pack/test/epm_api_integration/apis/fixtures/packages/epr/yamlpipeline_1.0.0.tar.gz
Binary file not shown.
32 changes: 0 additions & 32 deletions
32
x-pack/test/epm_api_integration/apis/fixtures/packages/package/yamlpipeline_1.0.0
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I recently learned about some yarn scripts that I think are preferable using
node scripts/*
For the two terminal approach listed shown here, in the kibana root,
yarn test:ftr:server --config x-pack/test/ingest_manager_api_integration/config.ts
yarn test:ftr:runner --config x-pack/test/ingest_manager_api_integration/config.ts
If you want to run everything in one go, this seems to work
yarn test:ftr --config x-pack/test/ingest_manager_api_integration/config.ts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! I've updated the documentation accordingly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's cool. I wasn't aware of that either. 👍