Expand description
The metrics query API — the data-access service boundary (SRD-86 §“The metric-reader surface”).
nmbrs-metrics is the foundational data-access library; this module
exposes its query surface as a service. It provides the native
result shape (Vector — multiple Series, each with sample
points), the selector semantics (Matcher), and a small access
contract (MetricAccess) whose signatures map 1:1 onto a
MetricsQL parsed selector:
- a bare / instant selector →
MetricAccess::select_instant; - a range selector (
m[w]) →MetricAccess::select_range.
Deliberately not here: aggregation, rollups, arithmetic — the “bells and whistles” of the query language. Those stay in the MetricsQL engine, layered over this access surface. Keeping the contract this thin is what lets the engine sit on any data service.
§Service location (a “data service object”)
Consumers (the MetricsQL engine) locate a service at runtime rather than binding a concrete impl:
- the live in-process service wraps the session’s
MetricsQuery(which is not static), so the runnerinstall_live_accesses it per session and consumers read it vialive_access; - file / external backends (e.g. the sqlite reader) register an
AccessProviderviainventory, so a consumer canproviderone by scheme and open it — without the engine depending on the backend’s crate or features.
Re-exports§
pub use catalog::CachedCatalog;pub use catalog::ExemplarPoint;pub use catalog::LabelSet;pub use catalog::MetricCatalog;pub use catalog::MetricFamilyMeta;pub use catalog::MetricType;
Modules§
- catalog
- Catalog: enumerable backend introspection for metrics.
Structs§
- Access
Provider - A pluggable access backend, discovered at runtime via
inventory. A consumer opens a service for a scheme-specifictarget(e.g. a db path). The sqlite reader registers one; future backends can too, without the query engine depending on them. - Exec
Scoped Access - SRD-89 §3b / SRD-90 §M6 — scope every read to its reading execution by
injecting
exec_idas a uniform dimensional-label matcher, so each interior backend applies it whereverexec_idlives (the in-memory tier’s label set, the sqlite tier’sexec_idcolumn) with the same value. This replaces the per-backend special-casing (the live tier’s bespoke post-filter, a sqlite selection mode) with one mechanism:exec_idis just a label. - Hybrid
Store - Composite read backend over an ordered tier list (finest first).
- Matcher
- A single label matcher in a selector — one MetricsQL label filter.
- Metrics
Query Access - The live in-process access backend. Cheap to construct (wraps the
shared
Arc). - Query
Error - Error from a metrics access backend. Backends own their taxonomy; the engine treats these as opaque from a flow-control standpoint.
- Sample
- One observation: a value at a point in time (Unix epoch ms).
- Series
- One time series: an identifying label set plus its observed
samples (ascending by timestamp).
__name__lives inlabels. - Tier
- One tier of a
HybridStore: a backend plus its horizon advertiser. - Vector
- A vector result: zero or more series, each with one or more sample points. The content distinguishes the MetricsQL result shapes —
Enums§
Traits§
- Horizon
Aware - A horizon-advertising backend: the oldest sample-time it still holds, in
Unix-ms.
None⇒ unbounded (covers back as far as the query asks) — the natural answer for a durable tail tier. - Metric
Access - The metrics data-access service. Backends implement it; a query
layer locates one at runtime and reads
Vectors through it. See the module docs for the access/aggregation cut line.
Functions§
- current_
read_ exec_ id - The reading execution’s
exec_id, if a hook is installed and a scope is active.None⇒ live reads are unscoped (A1 single-run). - install_
live_ access - Install the live in-process access service. Called once by the
runner when the session’s
MetricsQueryis built. - install_
read_ exec_ id_ hook - Install the reading-execution
exec_idresolver (idempotent — first wins). The runtime calls this once with a fn that reads its task-local execution context. - live_
access - The live in-process access service, if a session has installed one.
Lock-free: one atomic
ArcSwapload. - provider
- Locate a registered
AccessProviderby scheme. - uninstall_
live_ access - Drop the installed live-access service and everything it owns —
crucially the HybridStore’s sqlite “cold tier” reader connection on
metrics.db. The runner calls this at session shutdown BEFORE the SQLite reporter consolidates the WAL:PRAGMA journal_mode=DELETEneeds an EXCLUSIVE lock on the db, which a still-open reader connection on the same file blocks (“database is locked”).swap+ explicitdropso the holder’s Arc chain is released here rather than deferred to the nextstore. Idempotent; a no-op if nothing was installed.