adapter
Module[Adapter]: where metrics are stored, and the values crossing it.
Contents
6 submodules, and what the module defines itself.
use utopia_usage::Entry;pub struct EntryOne metric to write.
use utopia_usage::Point;pub struct PointOne point of a time series.
use utopia_usage::Series;pub struct SeriesOne metric's time series and its total.
use utopia_usage::Time;pub enum TimeWhen a metric was emitted: a DateTime, or a string a DateTime is
made from.
use utopia_usage::Adapter;pub trait Adapter: Send + SyncA storage backend for usage metrics. Implement it to store metrics elsewhere; the provided methods refuse what a backend does not support.
pub type TimeSeries = IndexMap<String, Series>Time series by metric name, in the order the metrics were asked for.
pub type Totals = IndexMap<String, i64>Totals by metric name, in the order the metrics were asked for.
adapter::clickhouse
Own pageThe ClickHouse adapter: events, gauges, a daily rollup of events and canonical samples in ClickHouse tables, over its HTTP interface.
Tables (<namespace>_usage_*, or usage_* without a namespace):
| Table | Holds |
|---|---|
_events (MergeTree) | raw events with their dimension columns, projections per dimension on an hourly bucket |
_events_daily (SummingMergeTree) and _events_daily_mv | events summed per day, metric and resource |
_gauges (MergeTree) | gauge samples, windowed and latest-value projections |
_samples (MergeTree) | canonical samples |
Reads pick the cheapest source: closed days from the rollup, partial
hours and days from the raw table, grouped reads through projections the
server matches; ClickHouse::route_log records each decision.
use utopia_usage::adapter::clickhouse::ClickHouse;pub struct ClickHouse<A: utopia_client::Adapter = Http>Usage metrics in ClickHouse, through a utopia-client transport.
Debug.use utopia_usage::adapter::clickhouse::Config;pub struct ConfigHow to reach ClickHouse and lay out the tables.
use utopia_usage::adapter::clickhouse::RouteEntry;pub struct RouteEntryOne routing decision.
use utopia_usage::adapter::clickhouse::Stats;pub struct StatsRequest statistics.
adapter::clickhouse::read
Own pageReads: query parsing and validation, rows, aggregates, counts, sums, time series, the daily table, and purges.
adapter::clickhouse::route
Own pageRouting of event totals: raw events, the daily rollup, or both.
adapter::clickhouse::samples
Own pageCanonical samples: the immutable ledger, watermarks and evidence reads.
adapter::clickhouse::setup
Own pageHealth, the schema (setup()), and the daily rollup's backfill.
adapter::database
Own pageThe Database adapter: every metric in one collection (usage) of a
utopia-database database, events and gauges told apart by a type
attribute.
use utopia_usage::adapter::database::Database;pub struct DatabaseUsage metrics in a utopia-database collection. The adapter owns the
database's tenant: every call sets it (a numeric tenant), none restores
it, so give it a database dedicated to usage.
Time series are not implemented (every metric reads as empty), and the daily methods read the collection itself.
Debug.pub const COLLECTION: &str = "usage"The collection metrics are stored in.