Class AdaptiveSamplingPolicy

java.lang.Object
com.tnsai.quality.sampling.AdaptiveSamplingPolicy
All Implemented Interfaces:
EventSamplingPolicy

public final class AdaptiveSamplingPolicy extends Object implements 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 delegate
  • utilisation >= highWaterMark — drop everything below criticalLevel
  • otherwise — linear-interpolate the delegate's SamplingDecision.Capture into 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)
  • Constructor Details

  • Method Details

    • sample

      public SamplingDecision sample(SamplingInput input)
      Description copied from interface: EventSamplingPolicy
      Inspect an event's metadata and return whether to capture, drop, or capture-with-downsampling marker.
      Specified by:
      sample in interface EventSamplingPolicy
    • droppedDueToPressureCount

      public long droppedDueToPressureCount()
      How many events did pressure-induced scaling drop? Monitoring counter.