Package com.tnsai.quality.sampling
Class AdaptiveSamplingPolicy
java.lang.Object
com.tnsai.quality.sampling.AdaptiveSamplingPolicy
- All Implemented Interfaces:
EventSamplingPolicy
Backpressure-aware
EventSamplingPolicy (issue #82). Wraps a
delegate policy and reduces effective sample rate when an external
AdaptiveSamplingPolicy.BackpressureSignal reports that the publisher chain is
overloaded.
The signal is intentionally minimal — a double in
[0.0, 1.0] representing "fraction of capacity in use". The
publisher / aggregator owns measurement (queue depth, ack lag,
Resilience4j RateLimiter saturation). This class consumes that
signal:
utilisation < lowWaterMark— pass through to delegateutilisation >= highWaterMark— drop everything belowcriticalLevel- otherwise — linear-interpolate the delegate's
SamplingDecision.Captureinto a downsampled capture
Gives operators a way to gracefully degrade event volume under sustained load without losing critical events.
- Since:
- 0.10.0 (issue #82 closeout)
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceExternally-supplied utilisation signal. -
Constructor Summary
ConstructorsConstructorDescriptionAdaptiveSamplingPolicy(EventSamplingPolicy delegate, AdaptiveSamplingPolicy.BackpressureSignal signal) Defaults: low=0.5, high=0.9, criticalLevel=ERROR.AdaptiveSamplingPolicy(EventSamplingPolicy delegate, AdaptiveSamplingPolicy.BackpressureSignal signal, double lowWaterMark, double highWaterMark, com.tnsai.observability.events.EventLevel criticalLevel) -
Method Summary
Modifier and TypeMethodDescriptionlongHow many events did pressure-induced scaling drop?sample(SamplingInput input) Inspect an event's metadata and return whether to capture, drop, or capture-with-downsampling marker.
-
Constructor Details
-
AdaptiveSamplingPolicy
public AdaptiveSamplingPolicy(EventSamplingPolicy delegate, AdaptiveSamplingPolicy.BackpressureSignal signal, double lowWaterMark, double highWaterMark, com.tnsai.observability.events.EventLevel criticalLevel) -
AdaptiveSamplingPolicy
public AdaptiveSamplingPolicy(EventSamplingPolicy delegate, AdaptiveSamplingPolicy.BackpressureSignal signal) Defaults: low=0.5, high=0.9, criticalLevel=ERROR. Below 50% load the delegate runs unchanged; between 50-90% load the capture rate scales down linearly; above 90% only ERROR-and-above survive.
-
-
Method Details
-
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
-
droppedDueToPressureCount
public long droppedDueToPressureCount()How many events did pressure-induced scaling drop? Monitoring counter.
-