Struct relay_sampling::evaluation::ReservoirEvaluator
source · 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>
impl<'a> ReservoirEvaluator<'a>
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 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.
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.