Skip to main content

Module traffic_split

Module traffic_split 

Source
Expand description

Traffic-split plugin (traffic-split) — a port of Apache APISIX’s traffic-split plugin for weighted / conditional traffic steering (canary, blue-green, A/B).

A request is matched against an ordered list of rules; the first rule whose match condition passes selects a set of weighted_upstreams. One weighted slot is then picked by weighted round-robin. A slot either names a concrete target set (upstream.targets) or carries only a weight (the “default” slot, meaning “use the route’s normal upstream”).

Split-node wiring (featherbit design — read this before wiring the graph). This node sits before the route’s normal upstream node. It exposes the usual success / error ports and the caller wires them so that the two outcomes reach the right place:

  • Default slot picked (or no rule matched): the plugin returns Ok(ctx) unchanged. Wire success → the rest of the pipeline (the normal upstream node). The request is proxied by the route as usual.
  • Target slot picked: the plugin proxies the request itself to the chosen target (reusing the shared outbound client), writes the backend’s reply onto Context.response, and short-circuits by returning Err(code TRAFFIC_SPLIT_ROUTED) with the response already populated. Wire errorclient.in (the same convention fault-injection and mocking use for “stop here, send this response”). If the split target itself is unreachable the node fails with TRAFFIC_SPLIT_UPSTREAM_ERROR and a prepared 502 body — also routed through error.

This makes canary/blue-green trivial: give the default slot weight 90 and a canary target set weight 10, and 10% of matching traffic is proxied to the canary while the other 90% falls through to the normal upstream.

Structs§

Rule 🔒
Slot 🔒
Target 🔒
A single backend address (host:port) a split slot forwards to.
TrafficSplitPlugin
Steers matching requests to a weighted set of upstream targets, or lets them fall through to the route’s normal upstream.

Functions§

parse_targets 🔒
Parses a {targets: [{host, port}], ...} upstream object into a target list. Entries missing host/port are skipped; an empty result is an error (an upstream block must name at least one reachable target).