Class InMemorySLOEvaluator

java.lang.Object
com.tnsai.quality.slo.InMemorySLOEvaluator
All Implemented Interfaces:
SLOEvaluator

public final class InMemorySLOEvaluator extends Object implements 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

Concurrency

Backed by a ReentrantReadWriteLock: 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)
  • Constructor Details

    • InMemorySLOEvaluator

      public InMemorySLOEvaluator(Duration retainFor)
      Parameters:
      retainFor - how far back to keep attempts. Must be at least as long as the longest SLO window the evaluator will be asked about — older records are evicted.
  • Method Details

    • record

      public void record(InMemorySLOEvaluator.Attempt a)
      Push an attempt into the rolling buffer.
    • size

      public int size()
      Returns:
      current live attempt count (after eviction). For tests / monitoring.
    • evaluate

      public SLOState evaluate(SLODefinition def, Instant now)
      Description copied from interface: SLOEvaluator
      Compute the current state of definition as of now. Implementations MUST be safe for concurrent calls; an SLO dashboard may evaluate dozens of definitions in parallel.
      Specified by:
      evaluate in interface SLOEvaluator