Skip to content

Extension chaosgrafana

Version 0.2.0
Repository https://github.com/chaostoolkit-incubator/chaostoolkit-grafana

Version License

Build codecov Python versions

This project should be used as a starting point to create your own Chaos Toolkit extension.

Install

This package requires Python 3.7+

To be used from your experiment, this package must be installed in the Python environment where chaostoolkit already lives.

$ pip install chaostoolkit-grafana

Usage

Sending Chaos Toolkit logs to Loki

To send the Chaos Toolkit logs to Loki endpoints, you need to enable the according control as follows:

{
    "secrets": {
        "grafana": {
            "auth": ["admin", "admin"]
        }
    },
    "controls": [
        {
            "name": "loki",
            "provider": {
                "type": "python",
                "module": "chaosgrafana.controls.loki",
                "secrets": ["grafana"],
                "arguments": {
                    "loki_endpoint": "http://localhost:3100",
                    "tags": {"service": "something"}
                }
            }
        }
    ]
}

You can set two other arguments to the control:

  • trace_id: This must be a string which will identify this run uniquely in your logs. If none is a provided, a random string is generated.
  • experiment_ref: Sometimes it’s useful to identify a particular experiment, not just its run, throughout many runs. This is the string to do that. If none is provided, a hash of the experiment is performed and used. The hash is not stable across changes of the experiment of course.

These are particularly useful when you cpuple this extension with others like Prometheus where you want to cross-reference between logs and metrics.

Test

To run the tests for the project execute the following:

$ make tests

Formatting and Linting

We use a combination of black, flake8, and isort to both lint and format this repositories code.

Before raising a Pull Request, we recommend you run formatting against your code with:

$ make format

This will automatically format any code that doesn’t adhere to the formatting standards.

As some things are not picked up by the formatting, we also recommend you run:

$ make lint

To ensure that any unused import statements/strings that are too long, etc. are also picked up.

Contribute

If you wish to contribute more functions to this package, you are more than welcome to do so. Please, fork this project, make your changes following the usual PEP 8 code style, sprinkling with tests and submit a PR for review.

Exported Controls

loki

This module exports controls covering the following phases of the execution of an experiment:

Level Before After
Experiment Loading False False
Experiment False False
Steady-state Hypothesis False False
Method False False
Rollback False False
Activities False False

In addition, the controls may define the followings:

Level Enabled
Validate Control False
Configure Control True
Cleanup Control False

To use this control module, please add the following section to your experiment:

{
  "controls": [
    {
      "name": "chaosgrafana",
      "provider": {
        "type": "python",
        "module": "chaosgrafana.controls.loki"
      }
    }
  ]
}
controls:
- name: chaosgrafana
  provider:
    module: chaosgrafana.controls.loki
    type: python

This block may also be enabled at any other level (steady-state hypothesis or activity) to focus only on that level.

When enabled at the experiment level, by default, all sub-levels are also applied unless you set the automatic properties to false.

Exported Activities

controls