Skip to content

Instantly share code, notes, and snippets.

@johngian
Last active November 3, 2021 08:03
Show Gist options
  • Save johngian/3f2e906f05204245e47283f654fb158a to your computer and use it in GitHub Desktop.
Save johngian/3f2e906f05204245e47283f654fb158a to your computer and use it in GitHub Desktop.

Chaos engineering + toxiproxy

Test setup

version: "3.3"
services:
  toxiproxy:
    image: "shopify/toxiproxy:latest"
    ports:
      - "8474:8474"
      - "8080:8080"
  httpbin:
    image: "kennethreitz/httpbin:latest"

Orchestration commands (CLI)

  • Run testbed
    • docker-compose up
  • Create service
    • docker-compose exec toxiproxy sh
    • cd /go/bin/
    • ./toxiproxy-cli create httpbin-service -l 0.0.0.0:8080 -u httpbin:80
  • Test service without toxics
    • salvo "http://127.0.0.1:8080" -c 10 -n 100
  • Add some toxics
    • ./toxiproxy-cli toxic add httpbin-service --type latency --toxicName httpbin-latency --attribute latency=1000 --attribute jitter=100 --toxicity=0.7
  • Run a quick test using a simple load testing tool
    • salvo "http://127.0.0.1:8080/get" -c 10 -n 100
  • Add some more toxics
    • ./toxiproxy-cli toxic add httpbin-service --type limit_data --toxicName httpbin-limit-data --attribute bytes=500 --toxicity=0.7
  • Run a quick test using a simple load testing tool
    • salvo "http://127.0.0.1:8080/get" -c 10 -n 100
  • Add some more toxics
    • ./toxiproxy-cli toxic add httpbin-service --type timeout --toxicName httpbin-timeout --attribute timeout=1 --toxicity=0.6
  • Run a quick test using a simple load testing tool
    • salvo "http://127.0.0.1:8080/get" -c 10 -n 100
  • Run testbed
    • docker-compose up
  • Create service
    • docker-compose exec toxiproxy sh
    • cd /go/bin/
    • ./toxiproxy-cli create httpbin-service -l 0.0.0.0:8080 -u httpbin:80
  • Test service without toxics
    • salvo "http://127.0.0.1:8080" -c 10 -n 100
  • Add some toxics
    • ./toxiproxy-cli toxic add httpbin-service --type latency --toxicName httpbin-latency --attribute latency=1000 --attribute jitter=100 --toxicity=0.7
  • Run a quick test using a simple load testing tool
    • salvo "http://127.0.0.1:8080/get" -c 10 -n 100
  • Add some more toxics
    • ./toxiproxy-cli toxic add httpbin-service --type limit_data --toxicName httpbin-limit-data --attribute bytes=500 --toxicity=0.7
  • Run a quick test using a simple load testing tool
    • salvo "http://127.0.0.1:8080/get" -c 10 -n 100
  • Add some more toxics
    • ./toxiproxy-cli toxic add httpbin-service --type timeout --toxicName httpbin-timeout --attribute timeout=1 --toxicity=0.6
  • Run a quick test using a simple load testing tool
    • salvo "http://127.0.0.1:8080/get" -c 10 -n 100

API

https://github.com/Shopify/toxiproxy#http-api

Endpoints

All endpoints are JSON.

  • GET /proxies - List existing proxies and their toxics
  • POST /proxies - Create a new proxy
  • POST /populate - Create or replace a list of proxies
  • GET /proxies/{proxy} - Show the proxy with all its active toxics
  • POST /proxies/{proxy} - Update a proxy's fields
  • DELETE /proxies/{proxy} - Delete an existing proxy
  • GET /proxies/{proxy}/toxics - List active toxics
  • POST /proxies/{proxy}/toxics - Create a new toxic
  • GET /proxies/{proxy}/toxics/{toxic} - Get an active toxic's fields
  • POST /proxies/{proxy}/toxics/{toxic} - Update an active toxic
  • DELETE /proxies/{proxy}/toxics/{toxic} - Remove an active toxic
  • POST /reset - Enable all proxies and remove all active toxics
  • GET /version - Returns the server version number

Example of using API for load testing orchestration

https://github.com/johngian/mw-push-notifications-profiler/blob/master/src/push_notifications.py#L11

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment