Skip to main content

Module fault_injection

Module fault_injection 

Source
Expand description

Fault injection plugin (fault-injection) — a faithful subset of Apache APISIX’s fault-injection plugin for chaos/resilience testing.

Injects an artificial delay and/or an abort response into matching requests. Both faults are gated independently by a percentage sample and a vars condition (APISIX triple-array expressions, see crate::vars).

Early-exit wiring: an aborted request has the configured response already written onto Context.response and exits through the node’s error port with code FAULT_INJECTED; non-aborted requests continue through the success port. Wire error to a pass-through path (e.g. straight to client.in, or an error-handler that preserves the prepared response) so the injected status/body reach the client, and wire success to the rest of the pipeline. This deviates mechanically from APISIX (where abort is a direct exit, not an error) because featherbit pipelines need a distinct port for “stop here” versus “keep going”.

Structs§

AbortRule 🔒
DelayRule 🔒
FaultInjectionPlugin
Injects delays and/or abort responses into matching requests.

Functions§

parse_headers 🔒
Accepts headers as a map ({name: value}) or as the UI editor’s array form ([{name, value}]); scalar values are stringified, other shapes are rejected. Header names are lowercased.
parse_or_vars 🔒
Parses the APISIX vars shape for this plugin: an array whose items are each a full expression (OR-ed together). Two leniencies over the strict shape, both resolved at config load:
parse_percentage 🔒
Parses percentage as an integer in 0..=100.
roll_percent 🔒
Draws a pseudo-random number in 0..100.
sample_hit 🔒
APISIX sample_hit: no percentage means always hit; 0 never hits and 100 always hits.
vars_match 🔒
True when vars is unset, or when any expression in the list matches (APISIX ORs across the vars items and ANDs within each).