Skip to content

Extending Chaos Toolkit with Python

Create your new Chaos Toolkit extension project

All Chaos Toolkit extensions follow the same structure and you can benefit from a project template. You can create a repository using that template from the GitHub UI or using the gh.

$ gh repo create mytest --private -p chaostoolkit/chaostoolkit-extension-template

Where to put your code

There are two extension points for a Chaos Toolkit Python extension, and they are captured in two files: actions.py and probes.py.

It is conventional to use the actions.py module as the place where you expose the actions that you would like to conduct as part of your Chaos Toolkit experimental method against the environment you want to inject failure into.

It’s also conventional to use the probes.py module as the place where you can integrate with your system’s existing observability so that those values can be used either for an experiment’s Steady State Hypothesis, or as simple additional data-gathering probes that can be declared throughout an experiment’s method.

Running Discover on a New Extension

Chaos Toolkit extensions often implement functionality that assists in discovering what a system, and the extension against that system, supports. This is executed using the chaos discover command.

When writing your own implementation of discovery you will often want to test the new functionality locally. To do this you should first execute from your extension workspace:

$ python setup.py develop

Then you can exercise your discovery functionality using the --no-install flag on the chaos discover command, for example:

chaos discover --no-install ext-name

Log From Your Extension

You can write to the Chaos Toolkit log by using the logzero package.

from logzero import logger

logger.info("Hello!")

Make sure to add logzero as an entry of the requirements.txt file of your extension.