kumulant

stat.event

Stats whose output is discrete-temporal in shape: last-seen timestamps, level crossings, and run lengths. They share the streaming-stats discipline but their results carry counts of state changes and timestamps rather than numeric aggregates.

Picking an event stat

StatResultQuestion
RunLengthStatRunLengthResultWhat's the current and longest consecutive truthy-run length?
CrossingStatCrossingResultHow often does the input cross a configured level?
RecencyStatRecencyResultHow long since the most recent observation?

When to reach for what

  • RunLengthStat for the classic "longest streak" diagnostic. Truthy means a nonzero, non-NaN value, so feeding it the output of a predicate produces consecutive-match-count metrics. Tracks both the current run and the longest observed run.

  • CrossingStat when the useful signal is "how active is this around a threshold"; zero-crossings of a centred series, threshold-touch counts on an SLO, transitions through any level. Reports up-crossings and down-crossings separately.

  • RecencyStat for staleness checks and last-error-seen monitors. Compose with com.eignex.kumulant.schema.ops.filter on the spec side for "time since the last matching event" diagnostics. The result reads elapsed time at snapshot time, not at update time, so a stale stream still reports a growing elapsed time even without new updates.

Compose patterns

  • Mean.transform(ifThenElse(X gt threshold, 1.0, 0.0)).windowed(window) for windowed fraction-meeting-threshold (SLO compliance).

  • RunLength.filter(predicate) for "longest consecutive run satisfying a predicate".

  • Recency.filter(predicate) for "time since last matching event".

Merge

CrossingStat and RecencyStat merge exactly: crossing counts sum cell-wise and recency takes the later last-seen timestamp. RunLengthStat merges approximately; run-length state is order-dependent, so the merge combines the extremes (longest run) without reconstructing the exact sequence.

Concurrency

CrossingStat and RecencyStat keep a single coupled "previous value

Types

Link copied to clipboard
@Serializable
@SerialName(value = "CrossingResult")
data class CrossingResult(val level: Double, val upCrossings: Long, val downCrossings: Long, val endedAtOrAboveLevel: Boolean? = null) : Result

Counts of upward and downward crossings of a fixed level.

Link copied to clipboard
class CrossingStat(val level: Double, val concurrency: Concurrency = Concurrency.None) : SeriesStat<CrossingResult>

Counts strict upward and downward crossings of a configured level.

Link copied to clipboard
@Serializable
@SerialName(value = "RecencyResult")
data class RecencyResult(val lastObservedTimestampNanos: Long, val timestampNanos: Long, val hasObservation: Boolean) : Result

Time since the most recent observation; hasObservation is false until the first update.

Link copied to clipboard
class RecencyStat(val concurrency: Concurrency = Concurrency.None) : SeriesStat<RecencyResult>

Reports the time elapsed since the most recent observation. Compose with .filter(...) to track recency of observations matching a predicate (for example: "how long since the last error").

Link copied to clipboard
@Serializable
@SerialName(value = "RunLengthResult")
data class RunLengthResult(val current: Long, val longest: Long, val leading: Long = current, val anyFalsy: Boolean = false) : Result

Current and longest consecutive truthy-run lengths.

Link copied to clipboard
class RunLengthStat(val concurrency: Concurrency = Concurrency.None) : SeriesStat<RunLengthResult>

Tracks the length of the current consecutive truthy run and the longest observed run. A value is treated as truthy when it is non-zero and not NaN; compose with .transform(...) upstream to project arbitrary predicates onto 0.0 / 1.0 before they reach the stat.