TimelessMetrics.RustEngine (timeless_metrics v6.2.2)

Copy Markdown View Source

Rust-native storage engine backend for TimelessMetrics.

Handles the hot path for raw point writes and queries through a single Rust NIF resource. The Elixir application still owns supervision, HTTP routing, alerts, annotations, scrape targets, and rollup metadata.

Started as a child of the store's supervisor. The engine reference is stored in persistent_term for zero-cost access on the hot path.

Summary

Functions

Returns a specification to start this module under a supervisor.

Force a compaction pass: merge raw and undersized chunks older than cutoff_ts into large pco chunks (:all compacts regardless of age). Runs automatically on the cold-flush timer when the store uses defer_compression: true, sparing the last hour so narrow recent queries stay on small chunks. Returns {:ok, series, chunks_replaced}.

Fused Prometheus ingest: parse exposition text and write all samples in a single NIF call — no per-sample terms cross the boundary. Samples without a timestamp get default_ts (epoch seconds).

Latest point per series matching a label filter, regardless of age.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

compact(store, cutoff_ts \\ :all)

Force a compaction pass: merge raw and undersized chunks older than cutoff_ts into large pco chunks (:all compacts regardless of age). Runs automatically on the cold-flush timer when the store uses defer_compression: true, sparing the last hour so narrow recent queries stay on small chunks. Returns {:ok, series, chunks_replaced}.

delete_before(store, before_ts)

find_series(store, metric_name, label_filter)

flush(store)

info(store)

ingest_prometheus(store, body, default_ts \\ nil)

Fused Prometheus ingest: parse exposition text and write all samples in a single NIF call — no per-sample terms cross the boundary. Samples without a timestamp get default_ts (epoch seconds).

Returns {:ok, count, errors} where count is samples written and errors is malformed line count. Note: labels are stored exactly as scraped; no relabeling is applied. Callers needing relabel rules must use PrometheusNif.parse/1 + write_batch/2 instead.

label_values(store, metric_name, label_key)

latest(store, metric_name, labels)

latest_multi(store, metric_name, label_filter)

Latest point per series matching a label filter, regardless of age.

The NIF has no dedicated latest-point query yet, so this reads the full range and keeps the newest sample per series.

list_metrics(store)

list_series(store, metric_name)

query_aggregate(store, metric_name, labels, opts)

query_aggregate_multi(store, metric_name, label_filter, opts)

query_multi(store, metric_name, label_filter, opts)

query_raw(store, metric_name, labels, opts)

ref(store)

resolve_series(store, metric_name, labels)

resolve_series_batch(store, pairs)

start_link(opts)

write(store, metric_name, labels, value, timestamp)

write_batch(store, entries)

write_resolved(store, series_id, value, timestamp)