Skip to main content

fraiseql_server/usage/
mod.rs

1//! Usage aggregation subsystem.
2//!
3//! Subscribes to `fraiseql::mutation_audit` tracing events (emitted by the
4//! runtime after every successful mutation) and maintains in-memory per-tenant,
5//! per-period, per-entity-type counters.
6//!
7//! # Architecture
8//!
9//! ```text
10//! fraiseql-core runtime
11//!   └── tracing::info!(target: "fraiseql::mutation_audit", ...)
12//!         │
13//!         ▼
14//! MutationAuditLayer (tracing_subscriber::Layer)
15//!   └── UsageAggregator (DashMap<(tenant, period, entity), AtomicU64>)
16//!         │
17//!         ▼
18//! HTTP query endpoint
19//!   GET /api/v1/admin/usage?tenant_id=…&period=…
20//! ```
21//!
22//! # Limitations (v1)
23//!
24//! - **In-memory only**: counters reset to zero on process restart.
25//! - **Unbounded**: no eviction; see [`aggregator`] module docs for growth bounds.
26
27pub mod aggregator;
28pub mod events;
29pub mod layer;
30
31#[cfg(test)]
32mod tests;