2022-01-04 17:47:05 +00:00
# How to Use Antithesis
2021-10-13 22:22:54 +00:00
2022-01-04 17:47:05 +00:00
## Context
2024-02-27 11:47:14 -08:00
Antithesis is a third party vendor with an environment that can perform network fuzzing. We can
upload images containing `docker-compose.yml` files, which represent various MongoDB topologies, to
the Antithesis Docker registry. Antithesis runs `docker-compose up` from these images to spin up
the corresponding multi-container application in their environment and run a test suite. Network
fuzzing is performed on the topology while the test suite runs & a report is generated by
Antithesis identifying bugs. Check out
https://github.com/mongodb/mongo/wiki/Testing-MongoDB-with-Antithesis to see an example of how we
2022-02-23 13:48:04 +00:00
use Antithesis today.
2021-10-13 22:22:54 +00:00
2022-01-04 17:47:05 +00:00
## Base Images
2024-02-27 11:47:14 -08:00
The `base_images` directory consists of the building blocks for creating a MongoDB test topology.
2025-06-12 10:55:16 -07:00
These images are uploaded to the Antithesis Docker registry [nightly ](https://github.com/mongodb/mongo/blob/6cf8b162a61173eb372b54213def6dd61e1fd684/etc/evergreen_yml_components/variants/ubuntu/test_dev_master_and_lts_branches_only.yml#L28 ) during the
[`antithesis image build and push` ](https://github.com/mongodb/mongo/blob/020632e3ae328f276b2c251417b5a39389af6141/etc/evergreen_yml_components/definitions.yml#L2823 ) function.
2022-01-04 17:47:05 +00:00
### mongo_binaries
2024-02-27 11:47:14 -08:00
This image contains the latest `mongo` , `mongos` and `mongod` binaries. It can be used to
start a `mongod` instance, `mongos` instance or execute `mongo` commands. This is the main building
2022-01-04 17:47:05 +00:00
block for creating the System Under Test topology.
### workload
2024-02-27 11:47:14 -08:00
This image contains the latest `mongo` binary as well as the `resmoke` test runner. The `workload`
container is not part of the actual toplogy. The purpose of a `workload` container is to execute
`mongo` commands to complete the topology setup, and to run a test suite on an existing topology
2022-01-04 17:47:05 +00:00
like so:
2024-02-27 11:47:14 -08:00
2022-01-04 17:47:05 +00:00
```shell
2022-06-16 15:35:41 +00:00
buildscript/resmoke.py run --suite antithesis_concurrency_sharded_with_stepdowns_and_balancer
2022-01-04 17:47:05 +00:00
```
**Every topology must have 1 workload container.**
2024-12-10 10:08:59 -05:00
Note: During `workload` image build, `evergreen/antithesis_image_build_and_push.sh` runs, which generates
2024-02-27 11:47:14 -08:00
"antithesis compatible" test suites and prepends them with `antithesis_` . These are the test suites
2024-12-10 10:08:59 -05:00
that can run in antithesis and are available from within the `workload` container.
2022-01-04 17:47:05 +00:00
### Dockerfile
2024-02-27 11:47:14 -08:00
This assembles an image with the necessary files for spinning up the corresponding topology. It
consists of a `docker-compose.yml` , a `logs` directory, a `scripts` directory and a `data`
directory. If this is structured properly, you should be able to copy the files & directories
2022-02-23 13:48:04 +00:00
from this image and run `docker-compose up` to set up the desired topology.
2022-01-04 17:47:05 +00:00
2024-12-10 10:08:59 -05:00
Example from what `buildscripts/resmokelib/testing/docker_cluster_image_builder.py` generates:
2024-02-27 11:47:14 -08:00
2022-01-04 17:47:05 +00:00
```Dockerfile
FROM scratch
COPY docker-compose.yml /
ADD scripts /scripts
ADD logs /logs
2022-02-23 13:48:04 +00:00
ADD data /data
2022-06-16 15:35:41 +00:00
ADD debug /debug
2022-01-04 17:47:05 +00:00
```
2024-02-27 11:47:14 -08:00
All topology images are built and uploaded to the Antithesis Docker registry during the
2024-12-10 10:08:59 -05:00
`antithesis image build and push` task. Some of these directories are created during the
`evergreen/antithesis_image_build_and_push.sh` script such as `/data` and `/logs` .
2022-01-04 17:47:05 +00:00
2024-02-27 11:47:14 -08:00
Note: These images serve solely as a filesystem containing all necessary files for a topology,
2022-01-04 17:47:05 +00:00
therefore use `FROM scratch` .
### docker-compose.yml
2024-02-27 11:47:14 -08:00
This describes how to construct the corresponding topology using the
`mongo-binaries` and `workload` images.
2022-01-04 17:47:05 +00:00
2022-06-16 15:35:41 +00:00
Example from `buildscripts/antithesis/topologies/sharded_cluster/docker-compose.yml` :
2024-02-27 11:47:14 -08:00
2022-01-04 17:47:05 +00:00
```yml
version: '3.0'
services:
2022-06-16 15:35:41 +00:00
configsvr1:
container_name: configsvr1
hostname: configsvr1
image: mongo-binaries:evergreen-latest-master
volumes:
- ./logs/configsvr1:/var/log/mongodb/
- ./scripts:/scripts/
- ./data/configsvr1:/data/configdb/
command: /bin/bash /scripts/configsvr_init.sh
networks:
antithesis-net:
ipv4_address: 10.20.20.6
# Set the an IPv4 with an address of 10.20.20.130 or higher
# to be ignored by the fault injector
#
configsvr2: ...
configsvr3: ...
database1: ...
2022-01-04 17:47:05 +00:00
container_name: database1
hostname: database1
image: mongo-binaries:evergreen-latest-master
volumes:
- ./logs/database1:/var/log/mongodb/
2022-02-23 13:48:04 +00:00
- ./scripts:/scripts/
- ./data/database1:/data/db/
2022-06-16 15:35:41 +00:00
command: /bin/bash /scripts/database_init.sh Shard1
2022-01-04 17:47:05 +00:00
networks:
antithesis-net:
ipv4_address: 10.20.20.3
# Set the an IPv4 with an address of 10.20.20.130 or higher
# to be ignored by the fault injector
#
database2: ...
database3: ...
2022-06-16 15:35:41 +00:00
database4: ...
database5: ...
database6: ...
mongos:
container_name: mongos
hostname: mongos
image: mongo-binaries:evergreen-latest-master
volumes:
- ./logs/mongos:/var/log/mongodb/
- ./scripts:/scripts/
command: python3 /scripts/mongos_init.py
depends_on:
- "database1"
- "database2"
- "database3"
- "database4"
- "database5"
- "database6"
- "configsvr1"
- "configsvr2"
- "configsvr3"
networks:
antithesis-net:
ipv4_address: 10.20.20.9
# The subnet provided here is an example
# An alternative subnet can be used
2022-01-04 17:47:05 +00:00
workload:
container_name: workload
hostname: workload
image: workload:evergreen-latest-master
volumes:
2022-02-23 13:48:04 +00:00
- ./logs/workload:/var/log/resmoke/
2022-01-04 17:47:05 +00:00
- ./scripts:/scripts/
2022-06-16 15:35:41 +00:00
command: python3 /scripts/workload_init.py
2022-01-04 17:47:05 +00:00
depends_on:
2022-06-16 15:35:41 +00:00
- "mongos"
2022-01-04 17:47:05 +00:00
networks:
antithesis-net:
ipv4_address: 10.20.20.130
# The subnet provided here is an example
# An alternative subnet can be used
networks:
antithesis-net:
driver: bridge
ipam:
config:
- subnet: 10.20.20.0/24
```
2024-02-27 11:47:14 -08:00
Each container must have a `command` in `docker-compose.yml` that runs an init script. The init
script belongs in the `scripts` directory, which is included as a volume. The `command` should be
set like so: `/bin/bash /scripts/[script_name].sh` or `python3 /scripts/[script_name].py` . This is
2022-06-16 15:35:41 +00:00
a requirement for the topology to start up properly in Antithesis.
2022-01-04 17:47:05 +00:00
2024-02-27 11:47:14 -08:00
When creating `mongod` or `mongos` instances, route the logs like so:
`--logpath /var/log/mongodb/mongodb.log` and utilize `volumes` -- as in `database1` .
This enables us to easily retrieve logs if a bug is detected by Antithesis.
2022-01-04 17:47:05 +00:00
2024-02-27 11:47:14 -08:00
The `ipv4_address` should be set to `10.20.20.130` or higher if you do not want that container to
2022-01-04 17:47:05 +00:00
be affected by network fuzzing. For instance, you would likely not want the `workload` container
to be affected by network fuzzing -- as shown in the example above.
2024-02-27 11:47:14 -08:00
Use the `evergreen-latest-master` tag for all images. This is updated automatically in
2024-12-10 10:08:59 -05:00
`evergreen/antithesis_image_build_and_push.sh` -- if needed.
2022-01-04 17:47:05 +00:00
### scripts
2024-02-27 11:47:14 -08:00
Take a look at `buildscripts/antithesis/topologies/sharded_cluster/scripts/mongos_init.py` to see
how to use util methods from `buildscripts/antithesis/topologies/sharded_cluster/scripts/utils.py`
to set up the desired topology. You can also use simple shell scripts as in the case of
`buildscripts/antithesis/topologies/sharded_cluster/scripts/database_init.py` . These init scripts
must not end in order to keep the underlying container alive. You can use an infinite while
loop for `python` scripts or you can use `tail -f /dev/null` for shell scripts.
2022-01-04 17:47:05 +00:00
## How do I create a new topology for Antithesis testing?
2024-02-27 11:47:14 -08:00
2024-12-10 10:08:59 -05:00
This should be done with care to ensure we are using our limited resources efficiently.
2024-02-27 11:47:14 -08:00
2024-12-10 10:08:59 -05:00
Create a new task extending the `antithesis_task_template` , tagged with `antithesis` , passing the specified `suite` to the `antithesis image build and push` task. See other examples to get started.
2021-10-13 22:22:54 +00:00
2022-02-23 13:48:04 +00:00
## Additional Resources
2024-02-27 11:47:14 -08:00
If you are interested in leveraging Antithesis feel free to reach out to #server -testing on Slack.