public class RawMetricValues extends WindowIndexedArrays
This class is responsible for bookkeeping raw values of each kind of metrics defined in the
MetricDef
. It also performs the Extrapolation
if some of the values are missing from the
metrics samples.
INVALID_INDEX, oldestWindowIndex
Constructor and Description |
---|
RawMetricValues(int numWindowsToKeep,
byte minSamplesPerWindow,
int numMetricTypesInSample)
Construct a RawMetricValues.
|
Modifier and Type | Method and Description |
---|---|
void |
addSample(MetricSample<?> sample,
long windowIndex,
MetricDef metricDef)
Add a
MetricSample to the raw metric values. |
ValuesAndExtrapolations |
aggregate(SortedSet<Long> windowIndices,
MetricDef metricDef)
Get the aggregated values of the given sorted set of windows.
|
boolean |
isExtrapolatedAtWindowIndex(long windowIndex)
Check if the window at the given window index is extrapolated.
|
boolean |
isValid(int maxAllowedWindowsWithExtrapolation)
Check whether this raw metric value is valid or not.
|
boolean |
isValidAtWindowIndex(long windowIndex)
Check if the window at the given window index is valid.
|
protected int |
length() |
int |
numSamples() |
int |
numWindowsWithExtrapolation() |
ValuesAndExtrapolations |
peekCurrentWindow(long currentWindowIndex,
MetricDef metricDef)
Peek the value for the current window.
|
int |
resetWindowIndices(long startingWindowIndex,
int numWindowIndicesToReset)
Clear the state of a given number of windows starting at the given window index.
|
byte |
sampleCountsAtWindowIndex(long windowIndex)
Assumes
sanityCheckWindowIndex(long) is called before this function. |
void |
sanityCheckWindowIndex(long windowIndex) |
void |
sanityCheckWindowRangeReset(long startingWindowIndex,
int numWindowIndicesToReset)
Check whether the given window range can be reset.
|
void |
updateOldestWindowIndex(long newOldestWindowIndex)
Update the oldest window index.
|
arrayIndex, currentWindowIndex, firstArrayIndex, inValidWindowRange, lastArrayIndex, lastWindowIndex, nextArrayIndex, prevArrayIndex, validateWindowIndex
public RawMetricValues(int numWindowsToKeep, byte minSamplesPerWindow, int numMetricTypesInSample)
numWindowsToKeep
- the total number of windows to keep track of.minSamplesPerWindow
- the minimum required samples for a window to not involve any Extrapolation
.numMetricTypesInSample
- the total number of raw metric types stored by windowValuesByMetricId
protected int length()
length
in class WindowIndexedArrays
public void addSample(MetricSample<?> sample, long windowIndex, MetricDef metricDef)
MetricSample
to the raw metric values.sample
- The metric sample to add.windowIndex
- the window index of the metric sample.metricDef
- the metric definitions.public void updateOldestWindowIndex(long newOldestWindowIndex)
updateOldestWindowIndex
in class WindowIndexedArrays
newOldestWindowIndex
- the new oldest window index.public boolean isValid(int maxAllowedWindowsWithExtrapolation)
MetricSampleAggregator
, AND
2. The number of windows with extrapolation is less than the given maxAllowedWindowsWithExtrapolation.maxAllowedWindowsWithExtrapolation
- the maximum number of allowed windows with extrapolation.public int numWindowsWithExtrapolation()
public boolean isValidAtWindowIndex(long windowIndex)
sanityCheckWindowIndex(long)
is called before this function.windowIndex
- the window index to check.public boolean isExtrapolatedAtWindowIndex(long windowIndex)
sanityCheckWindowIndex(long)
is called before this function.windowIndex
- the index of the window to check.public byte sampleCountsAtWindowIndex(long windowIndex)
sanityCheckWindowIndex(long)
is called before this function.public void sanityCheckWindowIndex(long windowIndex)
public void sanityCheckWindowRangeReset(long startingWindowIndex, int numWindowIndicesToReset)
startingWindowIndex
- the starting index of the windows to reset.numWindowIndicesToReset
- the number of windows to reset.public int resetWindowIndices(long startingWindowIndex, int numWindowIndicesToReset)
sanityCheckWindowRangeReset(long, int)
is satisfied -- this prevents repetitive sanity checks
within this function.startingWindowIndex
- the starting index of the windows to reset.numWindowIndicesToReset
- the number of windows to reset.public ValuesAndExtrapolations aggregate(SortedSet<Long> windowIndices, MetricDef metricDef)
ValuesAndExtrapolations
contains
the windows in the same order.windowIndices
- the sorted set of windows to get values for.metricDef
- the metric definitions.public ValuesAndExtrapolations peekCurrentWindow(long currentWindowIndex, MetricDef metricDef)
metricDef
- the metric definitions.public int numSamples()