Skip to main content

Module aggregator

Module aggregator 

Source
Expand description

In-memory usage counter store.

Counters are keyed by (tenant_id, period_yyyy_mm, entity_type) and stored as lock-free AtomicU64 values inside a DashMap.

§Memory growth

This is a v1, unbounded store: entries are never evicted. Growth is proportional to the product of #tenants × #periods × #entity_types. For a deployment with 100 tenants, 12 months retention, and 50 entity types that is at most 60 000 entries — approximately 5 MB. Eviction policies and persistent storage are out of scope for v1.

§Restarts

Counters are in-memory only; they reset to zero on process restart. The aggregator is wired into AppState and exposed via GET /api/v1/admin/usage.

Structs§

NoopBackend
No-op backend — counters are in-memory only, lost on restart.
PostgresBackend
PostgreSQL-backed usage persistence.
UsageAggregator
Thread-safe, in-memory usage counter store with optional persistence backend.
UsageSummary
Per-period mutation counts for a single tenant.

Traits§

UsageBackend
Persistence backend for usage counters.

Functions§

global_aggregator
Return a reference to the process-wide UsageAggregator.
validate_period
Validate a usage period string in "YYYY-MM" format.