Class AdaptiveSampleFilter


  • public class AdaptiveSampleFilter
    extends SampleFilter
    SampleFilter that changes the sample rate dynamically to meet a given target.
    • Field Detail

      • clock

        protected Clock clock
        The clock to use to get the current time. Absolute time is irrelevant, but this allows relative time to be changed in testing to remove time dependency.
    • Constructor Detail

      • AdaptiveSampleFilter

        public AdaptiveSampleFilter​(double sampleRate,
                                    Integer targetCount,
                                    Integer targetTimeValue,
                                    TimeUnit targetTimeUnit)
        Initialises the sample filter with a specified initial sample rate and target.
        Parameters:
        sampleRate - the initial rate at which to sample requests.
        targetCount - the target number of requests to match in a time frame.
        targetTimeValue - the value for the time frame.
        targetTimeUnit - the unit of the value for the time frame.
    • Method Detail

      • sample

        public boolean sample()
        Description copied from class: SampleFilter
        Whether to sample or not.
        Overrides:
        sample in class SampleFilter
        Returns:
        true if the request should be sampled, or false otherwise.