pub struct AdaptiveController { /* private fields */ }Expand description
EWMA-feedback-driven limiter tuning (DW-089). Compiled once per
config generation from the policies[].adaptive blocks; shared via
Arc from the dataplane generation. record_outcome runs on the
response path (after the upstream exchange resolves) and factor_for
runs on the request path (inside the rate-limit check) — both
lock-free. Policies without an enabled adaptive block are absent
from the map; factor_for returns 1.0 for them (no adaptive
tuning, the configured quotas apply as-is).
Implementations§
Source§impl AdaptiveController
impl AdaptiveController
Sourcepub fn new() -> Self
pub fn new() -> Self
New empty controller (no adaptive policies). The fast path:
factor_for returns 1.0 for every policy.
Sourcepub fn compile(gateway: &Gateway, obs: Option<Arc<Observability>>) -> Self
pub fn compile(gateway: &Gateway, obs: Option<Arc<Observability>>) -> Self
Compile the controller from a gateway’s policies. Only policies
with an adaptive block whose enabled is true contribute
state; the rest are absent (their factor_for returns 1.0).
The observability handle wires the metric families; pass None
for direct unit-test construction (metrics are then a no-op).
Sourcepub fn compile_with_clock(
gateway: &Gateway,
obs: Option<Arc<Observability>>,
now_ns: fn() -> u64,
) -> Self
pub fn compile_with_clock( gateway: &Gateway, obs: Option<Arc<Observability>>, now_ns: fn() -> u64, ) -> Self
Self::compile with a caller-supplied nanosecond clock (Unix
epoch). Intended for tests that need to advance time deterministically
(the same pattern as Breaker::with_clock); production keeps the
system clock via Self::compile.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Whether any adaptive policy is compiled in at all (the fast path: configs with no adaptive policies skip the per-request factor lookup entirely).
Sourcepub fn factor_for(&self, policy_name: &str) -> f64
pub fn factor_for(&self, policy_name: &str) -> f64
The current adaptive factor for policy_name. Returns 1.0
(no tuning) when the policy has no adaptive block. Within an
active Retry-After backoff window the factor is min_factor.
Sourcepub fn record_outcome(
&self,
policy_name: &str,
status: u16,
latency: Duration,
retry_after: Option<Duration>,
)
pub fn record_outcome( &self, policy_name: &str, status: u16, latency: Duration, retry_after: Option<Duration>, )
Record one upstream outcome for policy_name (DW-089): update
the error and latency EWMAs, apply any Retry-After backoff, and
recompute the adaptive factor. A no-op when the policy has no
adaptive block. status is the upstream HTTP status (5xx counts
as an error); latency is the upstream round-trip; retry_after
is the parsed Retry-After duration (only honored when
retry_after is in the policy’s origin_signals).
Trait Implementations§
Source§impl Debug for AdaptiveController
impl Debug for AdaptiveController
Auto Trait Implementations§
impl Freeze for AdaptiveController
impl !RefUnwindSafe for AdaptiveController
impl Send for AdaptiveController
impl Sync for AdaptiveController
impl Unpin for AdaptiveController
impl !UnwindSafe for AdaptiveController
Blanket Implementations§
§impl<T> AnyExt for T
impl<T> AnyExt for T
§fn downcast_ref<T>(this: &Self) -> Option<&T>where
T: Any,
fn downcast_ref<T>(this: &Self) -> Option<&T>where
T: Any,
T behind reference§fn downcast_mut<T>(this: &mut Self) -> Option<&mut T>where
T: Any,
fn downcast_mut<T>(this: &mut Self) -> Option<&mut T>where
T: Any,
T behind mutable reference§fn downcast_rc<T>(this: Rc<Self>) -> Result<Rc<T>, Rc<Self>>where
T: Any,
fn downcast_rc<T>(this: Rc<Self>) -> Result<Rc<T>, Rc<Self>>where
T: Any,
T behind Rc pointer§fn downcast_arc<T>(this: Arc<Self>) -> Result<Arc<T>, Arc<Self>>where
T: Any,
fn downcast_arc<T>(this: Arc<Self>) -> Result<Arc<T>, Arc<Self>>where
T: Any,
T behind Arc pointer§fn downcast_box<T>(this: Box<Self>) -> Result<Box<T>, Box<Self>>where
T: Any,
fn downcast_box<T>(this: Box<Self>) -> Result<Box<T>, Box<Self>>where
T: Any,
T behind Box pointer§fn downcast_move<T>(this: Self) -> Option<T>
fn downcast_move<T>(this: Self) -> Option<T>
Self to T,
useful only in generic context as a workaround for specializationSource§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
§impl<T, X> CoerceTo<T> for Xwhere
T: CoerceFrom<X> + ?Sized,
impl<T, X> CoerceTo<T> for Xwhere
T: CoerceFrom<X> + ?Sized,
fn coerce_rc_to(self: Rc<X>) -> Rc<T>
fn coerce_box_to(self: Box<X>) -> Box<T>
fn coerce_ref_to(&self) -> &T
fn coerce_mut_to(&mut self) -> &mut T
§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>
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>
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