Skip to main content

liminal_server/tap/
mod.rs

1//! The tap (SRV-011 R2): a sampled, bounded view of live traffic.
2//!
3//! A [`TapSubscription`] names the traffic it wants with a [`TapFilter`] and
4//! holds a [`BoundedRing`] of kept messages. The server samples `1 in N` per
5//! subscription: N doubles whenever the subscriber's ring is more than half
6//! full after a push and halves each time the subscriber drains. Every kept
7//! message remembers the N it was kept under, and a drain closes a batch
8//! wherever N changed, so each [`TapBatch`] has one divisor that is true of
9//! every message in it. The ring drops its oldest message with a count when
10//! full, so a slow subscriber costs at most `capacity` messages of memory, and
11//! each batch says how many were lost since the one before.
12//!
13//! The hook is [`Tap::observe`], called once at the server's publish return.
14//! With no subscriber it costs one atomic load.
15
16pub mod error;
17pub mod message;
18pub mod ring;
19pub mod subscription;
20
21pub use error::TapError;
22pub use message::{
23    Hop, PayloadGrant, PublishFact, Reached, Recorded, TapBatch, TapFilter, TapIdent, TapMessage,
24    TapOutcome, TapSource,
25};
26pub use ring::BoundedRing;
27pub use subscription::{DEFAULT_TAP_CAPACITY, MAX_SAMPLE_ONE_IN, Tap, TapSubscription, TapWaker};
28
29#[cfg(test)]
30mod tests;