Package com.tnsai.quality.sampling
Class HeadBasedSamplingPolicy
java.lang.Object
com.tnsai.quality.sampling.HeadBasedSamplingPolicy
- All Implemented Interfaces:
EventSamplingPolicy
Coin-flip-per-event sampling at a fixed rate (issue #82). Each call
to
sample(com.tnsai.quality.sampling.SamplingInput) draws a fresh random and captures with probability
rate; otherwise drops.
Pros: trivially fast (single double comparison + RNG draw), stateless, requires no per-event coordination across threads. Cons: no per-session affinity (a captured chat can have some chunks captured and others not — tail-based sampling is the answer when that matters; out of scope here).
Captured events are returned as SamplingDecision.CaptureDownsampled
with the configured rate so downstream aggregators can extrapolate
volume correctly.
- Since:
- 0.5.0 (issue #82)
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondoublerate()sample(SamplingInput input) Inspect an event's metadata and return whether to capture, drop, or capture-with-downsampling marker.
-
Constructor Details
-
HeadBasedSamplingPolicy
public HeadBasedSamplingPolicy(double rate) - Parameters:
rate- fraction in (0, 1].1.0= capture all (functionally equivalent toAlwaysCapturePolicybut with a downsampled marker still emitted — useAlwaysCapturePolicyinstead when you don't want the marker).
-
-
Method Details
-
rate
public double rate() -
sample
Description copied from interface:EventSamplingPolicyInspect an event's metadata and return whether to capture, drop, or capture-with-downsampling marker.- Specified by:
samplein interfaceEventSamplingPolicy
-