pub struct ApiBreakerPlugin {
role: Role,
id: String,
unhealthy_statuses: Vec<u16>,
unhealthy_failures: u32,
healthy_statuses: Vec<u16>,
healthy_successes: u32,
break_base_sec: u64,
max_breaker_sec: u64,
break_response_code: u16,
break_response_body: Option<String>,
resources: Arc<PluginResources>,
}Expand description
One node of an api-breaker check/observe pair.
Holds a handle to the process-wide crate::traffic::BreakerRegistry; the
shared breaker is resolved by the configured id.
Fields§
§role: Role§id: StringShared breaker identity — links the check and observe nodes.
unhealthy_statuses: Vec<u16>Statuses that count as unhealthy (open the breaker).
unhealthy_failures: u32Consecutive unhealthy responses before the breaker opens.
healthy_statuses: Vec<u16>Statuses that count as healthy (close the breaker).
healthy_successes: u32Consecutive healthy responses before the breaker fully closes.
break_base_sec: u64Base cooldown seconds; doubles each successive trip (APISIX 2^n).
max_breaker_sec: u64Upper bound on the cooldown.
break_response_code: u16Status returned while the breaker is open.
break_response_body: Option<String>Optional body returned while the breaker is open.
resources: Arc<PluginResources>Implementations§
Source§impl ApiBreakerPlugin
impl ApiBreakerPlugin
Sourcepub fn from_config(
config: &HashMap<String, Value>,
resources: &Arc<PluginResources>,
) -> Result<Self, String>
pub fn from_config( config: &HashMap<String, Value>, resources: &Arc<PluginResources>, ) -> Result<Self, String>
Builds one node of the pair from node config.
Accepted keys:
phase/role(string, required):check(before upstream) orobserve(after upstream).id(string, required): shared breaker identity; the check and observe nodes of one pair must use the sameid.unhealthy.http_statuses(array, default[500]): statuses counted as failures.unhealthy.failures(integer, default3): consecutive failures before the breaker opens.healthy.http_statuses(array, default[200]): statuses counted as successes.healthy.successes(integer, default3): consecutive successes before the breaker fully closes.break_response_code(integer, default502): status returned while the breaker is open.break_response_body(string, optional): body returned while open.break_base_sec(integer, default2): base cooldown; the open window grows asbreak_base_sec * 2^trip(APISIX’s2^nbackoff).max_breaker_sec(integer, default300, min3): cooldown ceiling.
# before upstream
type: api-breaker
config:
phase: check
id: orders-api
break_response_code: 502
unhealthy: { http_statuses: [500, 503], failures: 3 }
healthy: { http_statuses: [200], successes: 3 }
---
# after upstream
type: api-breaker
config:
phase: observe
id: orders-api
unhealthy: { http_statuses: [500, 503], failures: 3 }
healthy: { http_statuses: [200], successes: 3 }Trait Implementations§
Source§impl Plugin for ApiBreakerPlugin
impl Plugin for ApiBreakerPlugin
Source§fn plugin_type(&self) -> &str
fn plugin_type(&self) -> &str
Unique identifier for the plugin type (e.g., “proxy-rewrite”, “upstream”).
Source§fn execute<'life0, 'life1, 'async_trait>(
&'life0 self,
ctx: Context,
_named_inputs: &'life1 HashMap<String, Value>,
) -> Pin<Box<dyn Future<Output = Result<PluginOutput, PluginExecutionError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn execute<'life0, 'life1, 'async_trait>(
&'life0 self,
ctx: Context,
_named_inputs: &'life1 HashMap<String, Value>,
) -> Pin<Box<dyn Future<Output = Result<PluginOutput, PluginExecutionError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Executes the plugin logic against the request/response context. Read more
Auto Trait Implementations§
impl Freeze for ApiBreakerPlugin
impl !RefUnwindSafe for ApiBreakerPlugin
impl Send for ApiBreakerPlugin
impl Sync for ApiBreakerPlugin
impl Unpin for ApiBreakerPlugin
impl UnsafeUnpin for ApiBreakerPlugin
impl !UnwindSafe for ApiBreakerPlugin
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more