Skip to main content

Module toxiproxy

Module toxiproxy 

Source
Expand description

Toxiproxy template for network fault injection.

Toxiproxy is a TCP proxy that injects controllable faults (latency, bandwidth limits, connection drops, …) between a client and an upstream service. This template runs the ghcr.io/shopify/toxiproxy container, publishes its :8474 control API, and exposes a small typed client over that API so you can register proxies and add toxics without hand-rolling HTTP calls.

§Quick Start

use docker_wrapper::template::toxiproxy::{Toxic, ToxiproxyTemplate, ToxicStream};
use docker_wrapper::Template;

// Start Toxiproxy and wait for its control API to be ready.
let toxiproxy = ToxiproxyTemplate::new("chaos")
    .control_port(8474)
    .proxy_port(16379);
toxiproxy.start_and_wait().await?;
toxiproxy.wait_for_control_api().await?;

// Route a published host port through Toxiproxy to an upstream Redis.
// The proxy listens on 0.0.0.0:16379 inside the container, which is published
// to the host, so host clients can connect through the proxy.
toxiproxy
    .create_proxy("redis", "0.0.0.0:16379", "redis:6379")
    .await?;

// Inject 500ms of downstream latency.
toxiproxy
    .add_toxic("redis", "slow", ToxicStream::Downstream, Toxic::latency(500))
    .await?;

// ... run your client against localhost:16379 and observe the fault ...

toxiproxy.remove_toxic("redis", "slow").await?;
toxiproxy.reset().await?;

§Feature Flag

This template requires the template-toxiproxy feature:

[dependencies]
docker-wrapper = { version = "0.11", features = ["template-toxiproxy"] }

Structs§

ProxyInfo
A proxy as returned by the Toxiproxy control API.
ToxiproxyTemplate
Toxiproxy template for TCP fault injection.

Enums§

Toxic
A typed Toxiproxy toxic.
ToxicStream
Direction a toxic applies to.