Skip to main content

ErrorBudget

Struct ErrorBudget 

Source
pub struct ErrorBudget { /* private fields */ }
Expand description

错误预算(Error Budget),基于 SLO 目标和滑动时间窗口。

核心模型:每个错误消耗 (1 - slo_target) 单位的预算,预算容量为 1.0。 因此预算耗尽所需的错误数 = 1 / (1 - slo_target)(例如 SLO=0.999 时为 1000 个错误)。 该模型假设窗口内基线流量为 1/(1-SLO) 个请求;这是金融级 SLA 监控中 常用的简化模型,适用于独立于流量统计的错误预算追踪。

窗口外的 consume 调用会在下一次记录时被驱逐。

Implementations§

Source§

impl ErrorBudget

Source

pub fn new(slo_target: f64, window: Duration) -> Self

Source

pub fn consume(&mut self, error_count: usize)

Source

pub fn remaining(&self) -> f64

Source

pub fn is_exhausted(&self) -> bool

Trait Implementations§

Source§

impl Debug for ErrorBudget

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.