Giter Club home page Giter Club logo

chaostoolkit-toxiproxy's Introduction

Chaos Toolkit Driver for Toxiproxy

Build Status Python versions

Welcome to the Chaos Toolkit driver for Toxiproxy! This extension allows you to setup toxy proxy probes and methods from chaostoolkit by leveraging the toxyproxy http management api.

Install

  1. Install the Toxiproxy base client
  2. Install the Toxiproxy CLI

Driver

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-toxiproxy

Usage

Configuration

First, run the Toxiproxy base client locally to create a localhost:8474 host on your computer. Then create a proxy.

Next, to start using the actions and probes all you need to do is add the toxiproxy host with "toxiproxy_host" as the key, and optionally the port with "toxiproxy_port" as the key, to the configuration section in your experiment json. If not provided the port defaults to 8474.

Alternatively, if toxiproxy api is accessible using a reverse proxy, you can use toxiproxy_url setting.

Example using toxiproxy_host in experiment.json

"configuration": {
    "toxiproxy_host" : "10.124.23.183",
    "some_environment_variable": {
      "type": "environment",
      "key": "ENVIRONMENT_VARIABLE"
    }
  },

Example using toxiproxy_url in experiment.json

"configuration": {
    "toxiproxy_url" : "http://mydomain.com:8080/path-to-toxiproxy-api",
    "some_environment_variable": {
      "type": "environment",
      "key": "ENVIRONMENT_VARIABLE"
    }
  },

This extension follows the toxiproxy rules. A proxy is the channel where toxicity can be added. For this reason the extension is broken into proxy management and toxic management.

All actions and probes in the extension are of python type and are used like any other python extension.

Proxy actions

create_proxy

Creates a proxy to which toxics can be added. In toxiproxy a listen port of value 0 tells the API to assign a random available port. The value where the proxy is listenting will be attached to the chaostoolkit configuration object as <proxyname>_PORT. Should the creation of the proxy fail, an assertion error is raised stopping all subsequent actions.

Argument Description Required Default
proxy_name name for the proxy Yes None
upstream_host ip address of the host to send traffic to Yes None
upstream_port port of the application to send traffic to Yes None
listen_host IP address to bind where toxiproxy listens No 0.0.0.0
listen_port port to listen for requests, 0 means pick random value No 0
enabled Whether to start listening or not No True

modify_proxy

Modify the configuration of a given proxy. Useful to change the upstream configiuration. Only arguments supplied result in modification of the proxy.

Argument Description Required Default
proxy_name name for the proxy Yes None
listen_addres ip:port address to modify No None
upstream_addres ip:port of the upstream No None
enabled Toggle enabled/disabled state No None

disable_proxy

Disables the proxy, this is useful to simulate a proxied service being down.

Argument Description Required Default
proxy_name name for the proxy to disable Yes None

enable_proxy

Enables a disabled proxy.

Argument Description Required Default
proxy_name name for the proxy to enable Yes None

delete_proxy

Removes the proxy from the system.

Example usage

 "method": [
      {
            "type": "action",
            "name": "setup_toxiproxy_proxy",
            "provider": {
                "type": "python",
                "module": "chaostoxi.proxy.actions",
                "func": "create_proxy",
                "arguments": {
                    "proxy_name": "myproxy",
                    "listen_port" : 6666,
                    "upstream_host" : "10.28.188.118",
                    "upstream_port" : 6040
                }
            },
            "pauses": {
                "after": 1
            }
        }
      ] 

reset

Enable all proxies and remove all active toxics.

Example usage:

"method": [
    {
        "type": "action",
        "name": "reset all proxies",
        "provider": {
            "type": "python",
            "module": "chaostoxi.proxy.actions",
            "func": "reset"
        },
        "pauses": {
            "after": 1
        }
    }
]

Proxy pobes

proxy_exist

Returns True of False if a given proxy exists.

Argument Description Required Default
proxy_name name for the proxy Yes None

Toxic actions

All actions provided by this extension match the types and attributes of toxics.

create_toxic

Allows you to create any of the supported types of toxics with their attributes.

Argument Description Required Default
for_proxy name for the proxy to attach the toxy Yes None
toxic_name name for this toxy Yes None
toxic_type A valid toxic type Yes None
stream The direction of the toxic "upstream" or "downstream" No downstream
toxicity Percentage of toxiciy 1.0 is 100%, 0.5 is 50% etc No 1.0
attributes Dictionary of attributes for the type of toxic No None

create_latency_toxic

Add a delay to all data going through the proxy using a downstream with a toxicity of 100%.

Argument Description Required Default
for_proxy name for the proxy to attach the toxy Yes None
toxic_name name for this toxy Yes None
latency time in milliseconds to add for latency Yes None
jitter time in milliseconds to jitter No 0

create_bandwith_degradation_toxic

Limit the bandwith of a downstream connection with a toxicity of 100%.

Argument Description Required Default
for_proxy name for the proxy to attach the toxy Yes None
toxic_name name for this toxy Yes None
rate desired bandwith rate in KB/s Yes None

create_slow_connection_close_toxic

Generate as downstream delayed TCP close with a toxicity of 100%.

Argument Description Required Default
for_proxy name for the proxy to attach the toxy Yes None
toxic_name name for this toxy Yes None
delay desired close delay in milliseconds Yes None

create_slicer_toxic

Slices TCP data up into small bits, optionally adding a delay between each sliced "packet" with a toxicity of 100%.

Argument Description Required Default
for_proxy name for the proxy to attach the toxy Yes None
toxic_name name for this toxy Yes None
average_size size in bytes for the average package Yes None
size_variation variation in bytes of an average pkg (should be smaller than average_size) Yes None
delay time in microseconds to delay each packet by Yes None

create_limiter_toxic

Closes connections when transmitted data after the limit, sets it up as a dowsntream, 100% toxicity.

Argument Description Required Default
for_proxy name for the proxy to attach the toxy Yes None
toxic_name name for this toxy Yes None
bytes number of bytes to transmit before connection is closed Yes None

delete_toxic

Deletes the a given toxic.

Argument Description Required Default
for_proxy name for the proxy to attach the toxy Yes None
toxic_name name for this toxy Yes None

Example usage:

 "method": [        
      {
            "type": "action",
            "name": "create_latency_toxic",
            "provider": {
                "type": "python",
                "module": "toxiproxy.toxic.actions",
                "func": "create_dowsntream_latency_toxic",
                "arguments": {
                    "for_proxy": "edsproxy",
                    "toxic_name": "latency_toxic",
                    "latency": 5000,
                    "jitter": 200
                }
            },
            "pauses": {
                "after": 1
            }
        }    
 ]

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:

$ python setup.py develop

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 unit tests for the project execute the following:

$ pytest

To run the integration tests for the project execute the following:

$ tox

chaostoolkit-toxiproxy's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

chaostoolkit-toxiproxy's Issues

Creating a toxic for an existent proxy gives an exception

Issue
I'm trying to add an experiment to the catalogue. The idea is to use toxiproxy, and proxy the calls to a mysql database. With that, I can control the type of faults that would be injected,
The environment is on AWS: toxiproxy in a ubuntu machine, and mysql in a rds instance. The app is .net core (not relevant) and exposes a REST API.

The experiment verifies the steady-state (one of the API endpoints) and then creates a toxic. The proxy is already created, due to the fact that the app needs to connect to it.
However, when trying to create the toxic, there is an error:

[2019-10-21 09:47:38 ERROR] [toxiproxyapi:68] Unable to create toxic for proxy: mysql

Digging into that, I used postman to post the same payload to the endpoint. The payload generated by the chaostollokit extensions:

[2019-10-21 09:47:38 INFO] [actions:39] Creating toxy mysql-latency for proxy mysql with type: latency as a downstream with toxicity 1.0 and attributes {'latency': '1234', 'jitter': '89'}

Extracting the full payload (on my environment added a line to output the json), looks like this:

[2019-10-21 09:47:38 DEBUG] [actions:46] json format for toxy creation: {'name': 'mysql-latency', 'type': 'latency', 'stream': 'downstream', 'toxicity': 1.0, 'attributes': {'latency': '1234', 'jitter': '89'}}

Using the same payload on postman, I get the full error:

{"error":"bad request body: json: cannot unmarshal string into Go struct field LatencyToxic.latency of type int64","status":400}

Although the attributes are of type int (from what I got in the code), when parsed to json transforms into string. Toxiproxy is picky with the types.

Environment

  • Toxiproxy
    • Version: 2.1.4
    • OS: Ubuntu
  • Chaostoolkit
    • Version 1.3.0
    • OS: Cataliana 10.15

README example wrong and error creating proxy

the json snippets in the documentation refer to the toxiproxy module which doesn't exist, moreover, running the "create_proxy" example snippet, I get this error:

[2019-01-22 18:53:21 INFO] Action: create_proxy
[2019-01-22 18:53:21 ERROR] => failed: AttributeError: 'int' object has no attribute 'startswith'

Possible to modify the README.md to include more 'example usages'

On reading the section in the file which describes Proxy Actions and provides the various proxies (create, modify, disable and delete) there is only one example usage provided which appears to refer to the delete_proxy but is actually for the create_proxy.

Can this be moved below the 'create_proxy' and additional example usages added for the other proxies?

Support any toxiproxy-api url

Chaostoolkit-toxiproxy does not support toxiproxy-api urls of this format: http://mydomain:port/path-to-toxiproxy-api.
Looks like the only supported format is http://{host}:{port}
The first format is generally used if toxiproxy-api is behind a reverse proxy like nginx.

Maybe a toxiproxy_url property can exist also to fit all scenarios like:

"configuration": {
    "toxiproxy_url" : "http://domain:port/path-to-toxiproxy-api",
    "some_environment_variable": {
      "type": "environment",
      "key": "ENVIRONMENT_VARIABLE"
    }
  },

?

Add support for reset endpoint

Toxiproxy HTTP api provides a reset endpoint that enables all proxies and removes any toxics.

Reset can be very handy as a rollback action for an experiment as it ensures that all failure injections added as toxics, are removed and environment is back to normal

Unable to modify proxy error message despite successful modification

I installed this chaostoolkit extension today. I run an experiment to call function enable_proxy and disable_proxy which reports the following error:

[2019-08-16 13:02:24 ERROR] Unable to modify proxy MY_PROXY_NAME
[2019-08-16 13:02:24 ERROR]   => failed: AssertionError

However, I can verify with toxiproxy-cli that the disable_proxy action does toggle the proxy to disabled status.

This is was encountered with toxiproxy version 2.1.4.

Tox tests failures

Tried to run tox tests using $ tox as described in README with no success

Traceback:
tests/test_toxic_actions.py:2: in <module>
    import chaostoxi.toxic.actions as actions
chaostoxi/toxic/actions.py:4: in <module>
    from chaoslib.types import Configuration
E   ModuleNotFoundError: No module named 'chaoslib'

Looking at tox.ini looks like requirements.txt is not used, hence chaoslib module is not loaded.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.