Package com.tnsai.quality.slo
Class InMemorySLOEvaluator
java.lang.Object
com.tnsai.quality.slo.InMemorySLOEvaluator
- All Implemented Interfaces:
SLOEvaluator
Process-local
SLOEvaluator that holds attempt records in an
in-memory rolling buffer (issue #92). Suitable for dev, tests, and
single-process deployments; production multi-process deployments
should swap in a metric-store-backed evaluator (Prometheus
implementation lands in a follow-up PR).
How it works
- Callers push
InMemorySLOEvaluator.Attemptrecords viarecord(Attempt). evaluate(SLODefinition, Instant)filters the buffer by the SLO'sSLOScope.matches(EventScope)andSLODefinition.window(), then computes compliance / budget / burn-rate perSLODefinition.type().- Records older than
retainForare evicted on eachrecord(Attempt)call so the buffer can't grow unbounded.
Concurrency
Backed by aReentrantReadWriteLock: many concurrent evaluations
but exclusive writes during record(Attempt). Per-SLO
evaluation is O(N) over the live buffer — acceptable for the
dev-scale buffer size this evaluator is meant for.- Since:
- 0.5.0 (issue #92)
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordOne observed attempt feeding the SLO calculation. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionevaluate(SLODefinition def, Instant now) Compute the current state ofdefinitionas ofnow.voidPush an attempt into the rolling buffer.intsize()Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.tnsai.quality.slo.SLOEvaluator
evaluate
-
Constructor Details
-
InMemorySLOEvaluator
- Parameters:
retainFor- how far back to keep attempts. Must be at least as long as the longest SLOwindowthe evaluator will be asked about — older records are evicted.
-
-
Method Details
-
record
Push an attempt into the rolling buffer. -
size
public int size()- Returns:
- current live attempt count (after eviction). For tests / monitoring.
-
evaluate
Description copied from interface:SLOEvaluatorCompute the current state ofdefinitionas ofnow. Implementations MUST be safe for concurrent calls; an SLO dashboard may evaluate dozens of definitions in parallel.- Specified by:
evaluatein interfaceSLOEvaluator
-