pub struct ReservoirEvaluator<'a> { /* private fields */ }
Expand description

Utility for evaluating reservoir-based sampling rules.

A “reservoir limit” rule samples every match until its limit is reached, after which the rule is disabled.

This utility uses a dual-counter system for enforcing this limit:

  • Local Counter: Each relay instance maintains a local counter to track sampled events.

  • Redis Counter: For processing relays, a Redis-based counter provides synchronization across multiple relay-instances. When incremented, the Redis counter returns the current global count for the given rule, which is then used to update the local counter.

Implementations§

source§

impl<'a> ReservoirEvaluator<'a>

source

pub fn new(counters: ReservoirCounters) -> Self

Constructor for ReservoirEvaluator.

source

pub fn counters(&self) -> ReservoirCounters

Gets shared ownership of the reservoir counters.

source

pub fn set_redis(&mut self, org_id: u64, redis_pool: &'a RedisPool)

Sets the Redis pool and organiation ID for the ReservoirEvaluator.

These values are needed to synchronize with Redis.

source

pub fn incr_local(&self, rule: RuleId, limit: i64) -> bool

Evaluates a reservoir rule, returning true if it should be sampled.

source

pub fn evaluate( &self, rule: RuleId, limit: i64, _rule_expiry: Option<&DateTime<Utc>> ) -> bool

Evaluates a reservoir rule, returning true if it should be sampled.

Trait Implementations§

source§

impl<'a> Debug for ReservoirEvaluator<'a>

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for ReservoirEvaluator<'a>

§

impl<'a> !RefUnwindSafe for ReservoirEvaluator<'a>

§

impl<'a> Send for ReservoirEvaluator<'a>

§

impl<'a> Sync for ReservoirEvaluator<'a>

§

impl<'a> Unpin for ReservoirEvaluator<'a>

§

impl<'a> !UnwindSafe for ReservoirEvaluator<'a>

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> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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>,

§

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>,

§

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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more