Skip to content

Extension chaosk6

Version 0.3.0
Repository https://github.com/k6io/chaostoolkit-k6

Python versions

This project is a collection of actions and probes, gathered as an extension to the Chaos Toolkit.

Install

This package requires Python 3.5+

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

$ pip install -U chaostoolkit-k6

Usage

Please explore the code to see existing probes and actions.

Configuration

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.

The Chaos Toolkit projects require all contributors must sign a Developer Certificate of Origin on each commit they would like to merge into the master branch of the repository. Please, make sure you can abide by the rules of the DCO before submitting a PR.

Develop

If you wish to develop on this project, make sure to install the development dependencies. But first, create a virtual environment and then install those dependencies.

$ pip install -r requirements-dev.txt -r requirements.txt

Then, point your environment to this directory:

$ pip install -e .

Now, you can edit the files and they will be automatically be seen by your environment, even when running from the chaos command locally.

Test

To run the tests for the project execute the following:

$ pytest

Exported Activities

actions


run_script

Type action
Module chaosk6.actions
Name run_script
Return None

Run an arbitrary k6 script with a configurable amount of VUs and duration. Depending on the specs of the attacking machine, possible VU amount may vary. For a non-customized 2019 Macbook Pro, it will cap around 250 ± 50.

– scriptPath : str Full path to the k6 test script vus : int Amount of virtual users to run the test with duration : str Duration, written as a string, ie: 1h2m3s etc

Signature:

def run_script(scriptPath: str = None, vus: int = 1, duration: str = '1s'):
    pass

Arguments:

Name Type Default Required
scriptPath string null No
vus integer 1 No
duration string “1s” No

Usage:

{
  "name": "run-script",
  "type": "action",
  "provider": {
    "type": "python",
    "module": "chaosk6.actions",
    "func": "run_script"
  }
}
name: run-script
provider:
  func: run_script
  module: chaosk6.actions
  type: python
type: action

stress_endpoint

Type action
Module chaosk6.actions
Name stress_endpoint
Return None

Stress a single endpoint with a configurable amount of VUs and duration. Depending on the specs of the attacking machine, possible VU amount may vary. For a non-customized 2019 Macbook Pro, it will cap around 250 ± 50.

– endpoint : str The URL to the endpoint you want to stress, including the scheme prefix. vus : int Amount of virtual users to run the test with duration : str Duration, written as a string, ie: 1h2m3s etc

Signature:

def stress_endpoint(endpoint: str = None, vus: int = 1, duration: str = '1s'):
    pass

Arguments:

Name Type Default Required
endpoint string null No
vus integer 1 No
duration string “1s” No

Usage:

{
  "name": "stress-endpoint",
  "type": "action",
  "provider": {
    "type": "python",
    "module": "chaosk6.actions",
    "func": "stress_endpoint"
  }
}
name: stress-endpoint
provider:
  func: stress_endpoint
  module: chaosk6.actions
  type: python
type: action

probes


http

Type probe
Module chaosk6.probes
Name http
Return boolean

Probe an endpoint to make sure it responds to an http request with the expected HTTP status code. Depending on the endpoint and your payload, this action might be destructive. Use with caution.

– endpoint : str The URL to the endpoint to probe method : str A valid http request method name, like GET, POST, PUT, DELETE, OPTIONS, or PATCH status : int The expected HTTP Response status code. vus : int The amount of concurrent virtual users accessing the endpoint duration : str How long to probe the endpoint. Expressed as a duration string, i.e “20s”, “1m”, “1h” etc. timeout : int Timeout duration for http requests. Defaults to 1 second

Signature:

def http(endpoint: str,
         method: str = 'GET',
         status: int = 200,
         body: str = '',
         headers: dict = {},
         vus: int = 1,
         duration: str = '',
         debug: bool = False,
         timeout: int = 1) -> bool:
    pass

Arguments:

Name Type Default Required
endpoint string Yes
method string “GET” No
status integer 200 No
body string ”“ No
headers mapping {} No
vus integer 1 No
duration string ”“ No
debug boolean false No
timeout integer 1 No

Usage:

{
  "name": "http",
  "type": "probe",
  "provider": {
    "type": "python",
    "module": "chaosk6.probes",
    "func": "http",
    "arguments": {
      "endpoint": ""
    }
  }
}
name: http
provider:
  arguments:
    endpoint: ''
  func: http
  module: chaosk6.probes
  type: python
type: probe