|
| 1 | +# RFC 15056 - 2022-10-31 - Tooling revamp |
| 2 | + |
| 3 | +----- |
| 4 | + |
| 5 | +This RFC discusses improving Vector's developer tooling in order to ease maintenance and expand testing possibilities. |
| 6 | + |
| 7 | +**Table of Contents** |
| 8 | + |
| 9 | +- [Scope](#scope) |
| 10 | + - [In scope](#in-scope) |
| 11 | + - [Out of scope](#out-of-scope) |
| 12 | +- [Pain](#pain) |
| 13 | +- [Proposal](#proposal) |
| 14 | + - [User Experience](#user-experience) |
| 15 | + - [Implementation](#implementation) |
| 16 | + - [Environment management](#environment-management) |
| 17 | + - [Configuration](#configuration) |
| 18 | + - [Interface](#interface) |
| 19 | + - [Testing container](#testing-container) |
| 20 | +- [Drawbacks](#drawbacks) |
| 21 | +- [Prior Art](#prior-art) |
| 22 | +- [Alternatives](#alternatives) |
| 23 | + - [Status quo](#status-quo) |
| 24 | + - [Python](#python) |
| 25 | +- [Plan Of Attack](#plan-of-attack) |
| 26 | +- [Future Improvements](#future-improvements) |
| 27 | + |
| 28 | +## Scope |
| 29 | + |
| 30 | +### In scope |
| 31 | + |
| 32 | +- Begin the standardization of interfacing with the repository (building, testing, releasing, etc.) |
| 33 | +- Define a version support matrix for each integration |
| 34 | +- Make developer UX consistent across platforms |
| 35 | + |
| 36 | +### Out of scope |
| 37 | + |
| 38 | +- Non-integration tests |
| 39 | + |
| 40 | +## Pain |
| 41 | + |
| 42 | +- Test failures are difficult to debug, esp. since [this change](https://github.com/vectordotdev/vector/pull/13128) |
| 43 | +- Windows is essentially unsupported since Make takes a great deal of effort to install and most [scripts](https://github.com/vectordotdev/vector/tree/v0.24.2/scripts) require Bash and utilities like `find` |
| 44 | +- Adding tests for new integrations to CI ([here](https://github.com/vectordotdev/vector/blob/v0.24.2/Makefile#L333-L341) and [here](https://github.com/vectordotdev/vector/blob/v0.24.2/.github/workflows/integration-test.yml#L58-L91)) is a manual and occasionally forgotten step (see [outstanding questions](#outstanding-questions)) |
| 45 | +- Makefiles and scripts can get messy fast and often are hard to scale well |
| 46 | + |
| 47 | +## Proposal |
| 48 | + |
| 49 | +### User Experience |
| 50 | + |
| 51 | +Interaction with the repository will be done with a new tool called `vdev`, which will eventually replace most Bash and all Ruby scripts. (PoC in [#14990](https://github.com/vectordotdev/vector/pull/14990)) |
| 52 | + |
| 53 | +```text |
| 54 | +Vector's unified dev tool |
| 55 | +
|
| 56 | +Usage: vdev [OPTIONS] <COMMAND> |
| 57 | +
|
| 58 | +Commands: |
| 59 | + build Build Vector |
| 60 | + config Manage the vdev config file |
| 61 | + exec Execute a command within the repository |
| 62 | + int Manage integrations |
| 63 | + meta Collection of useful utilities |
| 64 | + status Show information about the current environment |
| 65 | +
|
| 66 | +Options: |
| 67 | + -v, --verbose... More output per occurrence |
| 68 | + -q, --quiet... Less output per occurrence |
| 69 | + -h, --help Print help information |
| 70 | + -V, --version Print version information |
| 71 | +``` |
| 72 | + |
| 73 | +### Implementation |
| 74 | + |
| 75 | +The [integration test directory](https://github.com/vectordotdev/vector/tree/v0.24.2/scripts/integration) will become nested, with each integration having its own directory, which will be a Rust crate. |
| 76 | + |
| 77 | +#### Environment management |
| 78 | + |
| 79 | +Each project will expose a CLI binary with 2 commands: |
| 80 | + |
| 81 | +- `start` - will set up the environment, create mock test data (like hitting some endpoint), wait until it's "ready", etc. |
| 82 | +- `stop` - will tear down the environment |
| 83 | + |
| 84 | +Both commands receive a single argument representing the JSON configuration of the environment generated by the `matrix` (see [below](#configuration)). |
| 85 | + |
| 86 | +Note that while most environments will continue to be Docker-based, this unlocks the ability to use Kubernetes, Terraform, or do arbitrary things. |
| 87 | + |
| 88 | +#### Configuration |
| 89 | + |
| 90 | +Each directory will have a `test.yaml` with the following options: |
| 91 | + |
| 92 | +- `args` - default array of arguments to pass to the test command |
| 93 | +- `env` - table of environment variables that will be set during tests |
| 94 | +- `matrix` - array of tables used to generate the environments |
| 95 | + |
| 96 | +For example, the [Elasticsearch setup](https://github.com/vectordotdev/vector/blob/v0.24.2/scripts/integration/docker-compose.elasticsearch.yml) might be: |
| 97 | + |
| 98 | +```yaml |
| 99 | +args: |
| 100 | +- --features |
| 101 | +- es-integration-tests |
| 102 | +- --lib |
| 103 | +- "::elasticsearch::integration_tests::" |
| 104 | + |
| 105 | +env: |
| 106 | + AWS_ACCESS_KEY_ID: dummy |
| 107 | + AWS_SECRET_ACCESS_KEY: dummy |
| 108 | + ELASTICSEARCH_AWS_ADDRESS: http://localstack:4571 |
| 109 | + ELASTICSEARCH_HTTP_ADDRESS: http://elasticsearch:9200 |
| 110 | + ELASTICSEARCH_HTTPS_ADDRESS: https://elasticsearch-secure:9200 |
| 111 | + |
| 112 | +matrix: |
| 113 | +- version: ["7.13.1"] |
| 114 | + type: ["classic"] |
| 115 | +``` |
| 116 | +
|
| 117 | +We could then extend the support matrices: |
| 118 | +
|
| 119 | +```yaml |
| 120 | +matrix: |
| 121 | +- version: ["7.13.1", "8.4.3"] |
| 122 | + type: ["classic"] |
| 123 | + |
| 124 | +- version: ["1.3.6", "2.3.0"] |
| 125 | + type: ["opensearch"] |
| 126 | +``` |
| 127 | +
|
| 128 | +That would indicate the following unique environments: |
| 129 | +
|
| 130 | +```text |
| 131 | +7.13.1-classic |
| 132 | +8.4.3-classic |
| 133 | +1.3.6-opensearch |
| 134 | +2.3.0-opensearch |
| 135 | +``` |
| 136 | + |
| 137 | +If we were testing the `8.4.3-classic` environment the [management CLI](#environment-management) would get the following payload: |
| 138 | + |
| 139 | +```json |
| 140 | +{ |
| 141 | + "type": "classic", |
| 142 | + "version": "8.4.3" |
| 143 | +} |
| 144 | +``` |
| 145 | + |
| 146 | +#### Interface |
| 147 | + |
| 148 | +The `vdev int` command would have the following sub-commands: |
| 149 | + |
| 150 | +- `show` - accepts an integration name and shows the available/running environments |
| 151 | +- `start` - calls the equivalently named command of the [management CLI](#environment-management). requires an integration name and environment name. the integration names refer to the names of the integration test directories |
| 152 | +- `stop` - ^^ |
| 153 | +- `test` - executes the tests and will terminate with the same exit code. accepts an integration name, environment name, and arbitrary extra arguments to pass to the test command. if no environment name is provided then all will be tested and any not already started will be torn down |
| 154 | + |
| 155 | + ```text |
| 156 | + vdev int test elasticsearch |
| 157 | + vdev int test elasticsearch 7.13.1-classic |
| 158 | + vdev int test elasticsearch 8.4.3-classic -- --no-capture |
| 159 | + ``` |
| 160 | + |
| 161 | +#### Testing container |
| 162 | + |
| 163 | +There will be a single container per integration for running tests and the entry point will be `/bin/sleep infinity`. |
| 164 | + |
| 165 | +## Drawbacks |
| 166 | + |
| 167 | +- Slight change in process for all developers which would require communication and docs |
| 168 | + |
| 169 | +## Prior Art |
| 170 | + |
| 171 | +- [ddev](https://datadoghq.dev/integrations-core/ddev/cli/) is a tool specific to Datadog Agent integrations |
| 172 | +- [Hatch](https://github.com/pypa/hatch) provides environment management and the matrix syntax we borrowed |
| 173 | + |
| 174 | +## Alternatives |
| 175 | + |
| 176 | +### Status quo |
| 177 | + |
| 178 | +- Could ignore all pain and add some more Docker compose test files |
| 179 | + |
| 180 | +### Python |
| 181 | + |
| 182 | +- Could call environments' `start`/`stop` methods through Hatch to avoid maintaining matrix logic |
| 183 | +- Could write all tooling in Python to theoretically increase development velocity |
| 184 | + |
| 185 | +Since Rust is already a requirement, it's easiest to run a single Cargo command to install the tooling. Introducing a dependency on Python at any point would not just require installing the right version of Python but also installing tools inside of a dedicated virtual environment (to avoid dependency conflicts) and adding its `bin` (`Scripts` on Windows) directory to PATH. [pipx](https://github.com/pypa/pipx) could help with that. |
| 186 | + |
| 187 | +Python development on macOS can be particularly painful. |
| 188 | + |
| 189 | +## Plan Of Attack |
| 190 | + |
| 191 | +- [ ] Merge the [PoC](https://github.com/vectordotdev/vector/pull/14990) of `vdev` |
| 192 | +- [ ] Implement the testing logic and add step to CI |
| 193 | +- [ ] For every integration ported remove it from the Makefile |
| 194 | +- [ ] When complete, enable integration tests on all PRs (even for contributors) |
| 195 | + |
| 196 | +## Future Improvements |
| 197 | + |
| 198 | +- Command to generate the scaffolding for new integrations |
| 199 | +- Shared test utilities like for running Docker compose |
| 200 | +- Only run an integration's tests on PRs for changes. The test matrix on PRs could be computed ([example](https://github.com/vectordotdev/vector/blob/v0.24.2/.github/workflows/soak.yml#L137-L169)) by `vdev` based on what has changed. This will save [somewhere between](https://github.com/vectordotdev/vector/actions/workflows/integration-test.yml) 6.5-8 hours of billable CI time per commit. |
0 commit comments