public class SamplingUtils extends Object
Modifier and Type | Class and Description |
---|---|
static class |
SamplingUtils.MetricsWindow
This represents a window of time for which metrics are collected.
|
Modifier and Type | Method and Description |
---|---|
static SamplingUtils.MetricsWindow |
currentWindow(long nowMs,
long windowSizeMs)
Returns the given start/end boundaries of the current metric window we are in, according to the passed-in current time.
|
static long |
windowIndex(long timeMs,
long windowMs)
Computes the absolute window index for the given timestamp
timeMs . |
public static SamplingUtils.MetricsWindow currentWindow(long nowMs, long windowSizeMs)
nowMs
- - the current time, in milliseconds since the unix epoch.windowSizeMs
- - the size of the window, in milliseconds.SamplingUtils.MetricsWindow
instance denoting the start/end of the window.public static long windowIndex(long timeMs, long windowMs)
timeMs
.
SBC buckets metrics into windows of size windowMs
in deterministic buckets based on the time in milliseconds since the unix epoch.
The window index for a timestamp T is in between: windowMs * (windowIndex-1) <= t < windowMs * windowIndex.
e.g. for a 120_000ms window (2 minutes), any timestamp between 1689927960000 and 1689928079999 is for the same window.
windowIndex(1689927960000, 120000) => 14082734, windowIndex(1689928079999, 120000) => 14082734
windowIndex(1689928080000, 120000) => 14082735, windowIndex(1689928080001, 120000) => 14082735,
The first window always starts from 1.
Also see currentWindow(long, long)
.