Skip to content

Commit f84eec3

Browse files
authored
Improve Integration test documentation (#10155)
1 parent 0f7f287 commit f84eec3

File tree

1 file changed

+125
-7
lines changed

1 file changed

+125
-7
lines changed

docs/test-framework-dev-guide.md

Lines changed: 125 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,27 @@ provides a high level overview of the testing framework.
1616
Go version should be at least the same than the one in [.go-version](https://github.com/elastic/elastic-agent/blob/main/.go-version) file at the root of this repository.
1717

1818

19-
### GCloud CLI
19+
#### GCloud CLI
2020
The integration testing framework spins up resources in GCP. To achieve this, it needs the
2121
[GCloud CLI](https://cloud.google.com/sdk/gcloud) to be installed on the system where the tests are initiated from.
2222

23-
### Beats
23+
#### Beats
2424
The Elastic Agent package that is used for integration tests packages Beats built from the Unified Release (as opposed to DRA). There is no explicit action needed for this prerequisite but just keep in mind that if any Agent integration tests rely on certain Beats features or bugfixes, they may not be available in the integration tests yet because a unified release containing those features or bugfixes may not have happened yet.
2525

26+
#### Helm & Helm charts
27+
To run the Kubernets integration tests you need to install
28+
[helm](https://helm.sh/). Then add and update some helm charts
29+
repositories:
30+
31+
```
32+
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
33+
helm repo update
34+
```
35+
36+
Make sure to run `helm repo update` before running K8s integration
37+
tests otherwise the tests will fail stating a chart/version cannot be
38+
found.
39+
2640
### Configuration
2741

2842
ESS (production) API Key to create on <https://cloud.elastic.co/account/keys>
@@ -39,6 +53,7 @@ If necessary, you can create a new serverless deployment manually; the previous
3953

4054
Credentials for these deployments are securely stored in Google and can only be accessed by Buildkite pipelines. The access control is set using [OpenID Connect in Google Cloud Platform](https://docs.github.com/en/actions/security-for-github-actions/security-hardening-your-deployments/configuring-openid-connect-in-google-cloud-platform). And that's managed by the Robots team.
4155

56+
4257
## Running tests
4358

4459
Some integration and E2E tests are safe to run locally. These tests set
@@ -60,9 +75,100 @@ Go to https://docker-auth.elastic.co/ and authenticate with Okta to receive your
6075

6176
[elastic_docker_registry]: docker.elastic.co
6277

78+
### Packaging
79+
Before you can run any test, you first need to package the Elastic
80+
Agent version you want to test. For that you'll need to run
81+
82+
```
83+
DEV=true SNAPSHOT=true EXTERNAL=true PACKAGES="tar.gz,deb,rpm" PLATFORMS=linux/amd64 mage -v package
84+
```
85+
86+
The packaging process has many leavers that need to be correctly set:
87+
88+
- `DEV=true|false`: Build with debug symbols
89+
- `EXTERNAL=true|false`: If `false` it will look for the `beats`
90+
folder at the same level as `elastic-agent` and build
91+
`x-pack/agentbeat` from there. Be aware that if you change Beats
92+
code and there is already an Agentbeat artifact built, it will not
93+
be re-build. You need to manually clean the Agentbeat build
94+
folder. If `true` it will download the latest snapshot.
95+
- `SNAPSHOT=true|false`: When downloading dependencies (like Beats)
96+
use snapshot versions. That is required to package from the `main`
97+
branch with `EXTERNAL=true`.
98+
- `PLATFORMS`: Comma separated list of platforms you want to build. If
99+
not set, it defaults to **ALL** platforms. [Selecting specific
100+
platform](#selecting-specific-platform) contains a list of common
101+
values. For a full list look at [`elastic-agent/dev-tools/mage/platforms.go`](https://github.com/elastic/elastic-agent/blob/main/dev-tools/mage/platforms.go#L15).
102+
- `PACKAGES`: Comma separated list of packages you want to build. If
103+
not set, it defaults to **ALL** packages, which takes a long time,
104+
so make sure to *always* set it correctly. The packages are defined
105+
on
106+
[`elastic-agent/dev-tools/mage/pkgtypes.go`](https://github.com/elastic/elastic-agent/blob/main/dev-tools/mage/pkgtypes.go#L72).
107+
To run Linux tests you need to package `tar.gz` ,`deb` and `rpm`.
108+
The possible options are:
109+
- `tar.gz`
110+
- `zip` (Windows only)
111+
- `deb`
112+
- `rpm`
113+
- `docker`
114+
- `DOCKER_VARIANTS`: When building Docker images, which variants to
115+
build. The variants are defined on
116+
[`elastic-agent/dev-tools/mage/dockervariants.go`](https://github.com/elastic/elastic-agent/blob/9f6c6a79f9e19ec2090d8f7da184280412cb8663/dev-tools/mage/dockervariants.go#L30),
117+
possible values are:
118+
- `basic`
119+
- `ubi`
120+
- `wolfi`
121+
- `complete`
122+
- `complete-wolfi`
123+
- `cloud`
124+
- `service`
125+
- `elastic-otel-collector`
126+
- `slim`
127+
- `elastic-otel-collector-wolfi`
128+
- `slim-wolfi`
129+
63130
### Running the tests
64131

65-
The test are run with mage using the `integration` namespace:
132+
The test are run with mage using the `integration` namespace, they
133+
share similar leavers as the packaging process.
134+
135+
- `AGENT_VERSION`: The version to test, in the format
136+
`9.2.0-SNAPSHOT`. It is **REQUIRED** to be set if you built the
137+
packages with `SNAPTHOST=true`. Currently there is no way to tell
138+
the integration tests framework to use snapshot versions if testing
139+
on VMs.
140+
141+
- `SNAPSHOT=true|false`: Use snapshot build when running Kubernetes
142+
tests.
143+
144+
- `INSTANCE_PROVISIONER`: Sets the provisioner used to create
145+
instances, possible values are:
146+
- `ogc`: Uses OGC to create VMs on GCP, if not set, that's the default.
147+
- `multipass`: Uses [Multipass](https://canonical.com/multipass) to
148+
create local VMs.
149+
- `kind`: Uses [Kind](https://kind.sigs.k8s.io/) to run Kubernetes
150+
in Docker. This needs to be set if running Kubernetes integration
151+
tests.
152+
153+
154+
### TL;DR: Packaging and running tests
155+
**Package the Elastic Agent**
156+
```
157+
# If testing on VMs.
158+
DEV=true SNAPSHOT=true EXTERNAL=true PACKAGES="tar.gz,deb,rpm" PLATFORMS=linux/amd64 mage -v package
159+
160+
# If running Kubernetes tests. Adjust the variants according to your tests
161+
DEV=true SNAPSHOT=true EXTERNAL=true PACKAGES="tar.gz,deb,rpm" DOCKER_VARIANTS="basic,complete,elastic-otel-collector" PLATFORMS=linux/amd64 mage -v package
162+
```
163+
164+
**Run the tests**
165+
```
166+
# If testing on VMs. Adjust the AGENT_VERSION according to your build.
167+
AGENT_VERSION="9.2.0-SNAPSHOT" mage -v integration:single TestLogIngestionFleetManaged
168+
169+
# If testing on Kubernetes
170+
SNAPSHOT=true INSTANCE_PROVISIONER=kind mage -v integration:testKubernetesSingle TestKubernetesJournaldInput
171+
```
66172

67173
#### ESS oriented tests
68174

@@ -80,11 +186,11 @@ The test are run with mage using the `integration` namespace:
80186

81187
#### Kubernetes oriented tests
82188

83-
- `mage integration:testKubernetes` to run kubernetes tests under the `testing/integration/k8s` folder for the default image on the default version of kubernetes (all previous commands will not run any kubernetes tests).
189+
- `INSTANCE_PROVISIONER=kind mage integration:testKubernetes` to run kubernetes tests under the `testing/integration/k8s` folder for the default image on the default version of kubernetes (all previous commands will not run any kubernetes tests).
84190

85-
- `mage integration:testKubernetesMatrix` to run a matrix of kubernetes tests under the `testing/integration/k8s` folder for all image types and supported versions of kubernetes.
191+
- `INSTANCE_PROVISIONER=kind mage integration:testKubernetesMatrix` to run a matrix of kubernetes tests under the `testing/integration/k8s` folder for all image types and supported versions of kubernetes.
86192

87-
- `mage integration:testKubernetesSingle [testName|all]` to execute a single test under the `testing/integration/k8s` folder. Only the selected test will be executed.
193+
- `INSTANCE_PROVISIONER=kind mage integration:testKubernetesSingle [testName|all]` to execute a single test under the `testing/integration/k8s` folder. Only the selected test will be executed.
88194

89195
#### Serverless oriented tests
90196

@@ -100,7 +206,7 @@ The test are run with mage using the `integration` namespace:
100206

101207
You can list all available mage targets by running `mage -l`
102208

103-
#### Selecting specific platform
209+
#### Selecting specific platform<a name="selecting-specific-platform"></a>
104210

105211
By default, the runner will deploy to every combination of operating system and architecture that the tests define
106212
as supporting. When working on tests and debugging an issue it's better to limit the operating system and architecture
@@ -493,3 +599,15 @@ using a separate env variable `AGENT_STACK_VERSION` like in this example (we use
493599
custom package version for the agent):
494600

495601
```AGENT_VERSION="8.10.0-testpkgversion.1-SNAPSHOT" AGENT_STACK_VERSION="8.10.0-SNAPSHOT" mage integration:test```
602+
603+
### K8s: pod not read (`timeout waiting for k8s object elastic-agent-standalone-xxxxx to be ready`/`client rate limiter Wait returned an error: context deadline exceeded`)
604+
Your Kind cluster might be in a broken state. Run:
605+
606+
```
607+
% kubectl get nodes
608+
NAME STATUS ROLES AGE VERSION
609+
v1.33.0-kubernetes-control-plane NotReady control-plane 58m v1.33.0
610+
```
611+
612+
And check the status of your node. If it is different than `Ready`,
613+
delete the cluster and create a new one.

0 commit comments

Comments
 (0)