Package org.mockserver.slo
Class SloSampleStore
java.lang.Object
org.mockserver.slo.SloSampleStore
Process-wide store of recent request samples used to evaluate
SloCriteria into an SloVerdict. Mirrors the singleton +
reset() pattern of ServiceChaosRegistry /
ChaosAutoHaltMonitor.
Each sample is one upstream round-trip (v1 records only Scope.FORWARD
traffic): its wall-clock end time, latency, whether it was an error
(status null or >= 500), the Scope, and the upstream
host. Samples are bounded two ways:
- By count — at most
sloWindowMaxSamples(default 50 000); the oldest is evicted when full. - By age — samples older than
sloWindowRetentionMillis(default 600 000 ms) relative to the newest recorded sample are evicted lazily on record and on query.
When sloTrackingEnabled is false (the default),
record(long, long, boolean, org.mockserver.slo.Scope, java.lang.String) is a no-op so the forward hot path pays nothing. Queries
always work against whatever samples exist.
Latency percentiles use the same algorithm as
org.mockserver.mock.drift.PercentileTracker: sort the in-window
latencies ascending and take the ceil(p/100 * n) - 1 index (clamped).
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classResult of an error-rate query over a window: error and total sample counts. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionerrorCountsInWindow(long fromEpochMillis, long toEpochMillis, Scope scope, Set<String> hosts) static SloSampleStorelong[]latenciesInWindow(long fromEpochMillis, long toEpochMillis, Scope scope, Set<String> hosts) static Doublepercentile(long[] ascendingLatencies, int pct) The latency percentile (0-100) over the supplied ascending latencies, using the same algorithm asPercentileTracker.percentile.voidRecord one sample.voidreset()Clears all samples.intsize()The total number of samples currently held (across all scopes/hosts).
-
Constructor Details
-
SloSampleStore
public SloSampleStore()
-
-
Method Details
-
getInstance
-
record
Record one sample. No-op whensloTrackingEnabledis false so the forward hot path pays nothing when the feature is off.- Parameters:
epochMillis- the sample's wall-clock end time (epoch millis)latencyMillis- upstream round-trip latency in millisecondsisError- true when the response was an error (status null or>= 500)scope- which traffic the sample belongs to (v1 recordsScope.FORWARD)host- the upstream host label, may be null
-
latenciesInWindow
public long[] latenciesInWindow(long fromEpochMillis, long toEpochMillis, Scope scope, Set<String> hosts) - Returns:
- the in-window, in-scope, in-host latencies (ascending order ready for percentile selection), or an empty array when none match.
-
errorCountsInWindow
public SloSampleStore.ErrorCounts errorCountsInWindow(long fromEpochMillis, long toEpochMillis, Scope scope, Set<String> hosts) - Returns:
- error and total sample counts for the in-window, in-scope, in-host samples.
-
percentile
The latency percentile (0-100) over the supplied ascending latencies, using the same algorithm asPercentileTracker.percentile. Returnsnullwhen there are no samples (so the caller can mark the objective INCONCLUSIVE rather than reporting a misleading zero). -
size
public int size()The total number of samples currently held (across all scopes/hosts). -
reset
public void reset()Clears all samples. Called on server reset and for test isolation.
-