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 ReservoirEvaluator<'_>
impl ReservoirEvaluator<'_>
sourcepub fn new(counters: ReservoirCounters) -> Self
pub fn new(counters: ReservoirCounters) -> Self
Constructor for ReservoirEvaluator
.
sourcepub fn counters(&self) -> ReservoirCounters
pub fn counters(&self) -> ReservoirCounters
Gets shared ownership of the reservoir counters.
sourcepub fn incr_local(&self, rule: RuleId, limit: i64) -> bool
pub fn incr_local(&self, rule: RuleId, limit: i64) -> bool
Evaluates a reservoir rule, returning true
if it should be sampled.
source§impl<'a> ReservoirEvaluator<'a>
impl<'a> ReservoirEvaluator<'a>
sourcepub fn set_redis(&mut self, org_id: OrganizationId, redis_pool: &'a RedisPool)
pub fn set_redis(&mut self, org_id: OrganizationId, redis_pool: &'a RedisPool)
Sets the Redis pool and organization ID for the ReservoirEvaluator
.
These values are needed to synchronize with Redis.
Trait Implementations§
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> 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> 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