Skip to content

//misk-metrics-digester/misk.metrics.digester/SlidingWindowDigest

SlidingWindowDigest

[jvm]\ class SlidingWindowDigest<T : TDigest<T>>@JvmOverloadsconstructor(windower: Windower, tDigest: () -> T, utcNowClock: Clock = Clock.systemUTC())

SlidingWindowDigest approximates quantiles of data for a trailing time period. It is thread-safe.

To efficiently store observed data in a mergeable way, t-openDigests are used. As t-openDigests do not support discarding older data points, the sliding window aspect is approximated by keeping multiple separate t-openDigests scoped to discrete overlapping time windows. As a result, quantile data is reported from the most recent window that has ended.

The following example creates a 1 minute sliding window where there are 6 overlapping windows at a given time. Reported quantiles are at most 10 seconds out of date. SlidingWindowDigest(Windower(60, 6), fun() = VeneurDigest())

The following example creates a 10 second sliding window where there are 2 overlapping windows at a given time. Reported quantiles are at most 5 seconds out of date: NewSlidingWindowDigest(Windower(10, 2), fun() = VeneurDigest())

Constructors

SlidingWindowDigest [jvm]
@JvmOverloads
constructor(windower: Windower, tDigest: () -> T, utcNowClock: Clock = Clock.systemUTC())

Functions

Name Summary
closedDigests [jvm]
@Synchronized
fun closedDigests(from: ZonedDateTime): List<WindowDigest<T>>
Returns all WindowDigests that ended starting from the given time (inclusive). The returned WindowDigest are ordered by their start time.
mergeIn [jvm]
@Synchronized
fun mergeIn(windowDigests: List<WindowDigest<T>>)
Merges in the data from the given WindowDigests. The given windowDigests should use the same windowing boundaries as this; if they do not then quantiles reported by this sliding window digest may be incorrect.
observe [jvm]
@Synchronized
fun observe(value: Double)
Adds the given value to all currently open t-openDigests. It is important to note that an observed value is not immediately reflected in calls to Quantile.
openDigests [jvm]
fun openDigests(gc: Boolean): List<WindowDigest<T>>
Returns all WindowDigests that are currently open, creating new windows if necessary. Older openDigests that ended more than 1 minute earlier are discarded if gc is true.
quantile [jvm]
@Synchronized
fun quantile(quantile: Double): Double
Returns estimated value for a quantile. The returned value may not include recently observed values due to how sliding windows are approximated. If no data has been observed then NaN is returned.
snapshot [jvm]
@Synchronized
fun snapshot(quantiles: List<Double>): Snapshot
Returns a snapshot of estimated values for quantiles, along with the count of observations and their sum. The returned values may not include recent observations due to how sliding windows are approximated. If no data has been observed then a slice of NaNs of having quantiles.count() is returned and NaN is returned for the sum.