Skip to main content

Module canary

Module canary 

Source
Expand description

Weighted canary / A-B traffic splitting middleware.

CanaryLayer implements Middleware and distributes incoming requests across a set of backends according to configurable weights. A backend with weight 3 receives three times as many requests as one with weight 1.

Backends are contacted over plain HTTP/1.1. If a backend is unavailable the next one in the rotation is tried; after exhausting all backends the middleware returns 502 Bad Gateway.

§Example

use rust_web_server::app::App;
use rust_web_server::core::New;
use rust_web_server::canary::{CanaryLayer, WeightedBackend};
use rust_web_server::middleware::WithMiddleware;

// 75 % of traffic → stable, 25 % → canary
let app = WithMiddleware::new(App::new())
    .wrap(
        CanaryLayer::new(vec![
            WeightedBackend::new("http://stable:8080", 3),
            WeightedBackend::new("http://canary:8080", 1),
        ])
        .path_prefix("/api"),
    );

Structs§

CanaryLayer
Weighted traffic-splitting proxy middleware.
WeightedBackend
A backend URL together with a relative traffic weight.