TimelessMetrics.Aggregation (timeless_metrics v6.2.2)

Copy Markdown View Source

Shared aggregation helpers for the actor engine.

Extracted from TimelessMetrics.Query — bucket_to_seconds, compute_aggregate, and bucket_points are needed by both the sharded query engine and the actor engine's in-process aggregation.

Summary

Functions

Group points into time buckets and compute an aggregate per bucket.

Per-bucket counter rate with carry-in.

Convert a bucket spec to seconds.

Compute an aggregate value from a list of values.

Functions

bucket_points(points, bucket_seconds, agg_fn)

Group points into time buckets and compute an aggregate per bucket.

Returns [{bucket_timestamp, aggregate_value}, ...] sorted by timestamp.

bucket_rate(sorted_points, align_fun)

Per-bucket counter rate with carry-in.

Takes timestamp-sorted points and an alignment function ts -> bucket_ts. Each bucket's rate is computed from pairwise deltas over the bucket's points plus the last point of the previous bucket (so one-sample-per-bucket data — the common scrape case — still yields rates). Negative deltas (counter resets) are skipped. Buckets with no computable delta are omitted, matching Prometheus/VM (no rate at the first sample).

Returns [{bucket_timestamp, rate_per_second}, ...] sorted by timestamp.

bucket_to_seconds(n)

Convert a bucket spec to seconds.

compute_aggregate(atom, values, points)

Compute an aggregate value from a list of values.