Rust

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;
Rust
pub struct Entry

One metric to write.

use utopia_usage::Point;
Rust
pub struct Point

One point of a time series.

use utopia_usage::Series;
Rust
pub struct Series

One metric's time series and its total.

use utopia_usage::Time;
Rust
pub enum Time

When a metric was emitted: a DateTime, or a string a DateTime is made from.

use utopia_usage::Adapter;
Rust
pub trait Adapter: Send + Sync

A storage backend for usage metrics. Implement it to store metrics elsewhere; the provided methods refuse what a backend does not support.

Implemented byClickHouseDatabase
Rust
pub type TimeSeries = IndexMap<String, Series>

Time series by metric name, in the order the metrics were asked for.

Rust
pub type Totals = IndexMap<String, i64>

Totals by metric name, in the order the metrics were asked for.

adapter::clickhouse

Own page

The 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):

TableHolds
_events (MergeTree)raw events with their dimension columns, projections per dimension on an hourly bucket
_events_daily (SummingMergeTree) and _events_daily_mvevents 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;
Rust
pub struct ClickHouse<A: utopia_client::Adapter = Http>

Usage metrics in ClickHouse, through a utopia-client transport.

Also implements Debug.
use utopia_usage::adapter::clickhouse::Config;
Rust
pub struct Config

How to reach ClickHouse and lay out the tables.

use utopia_usage::adapter::clickhouse::RouteEntry;
Rust
pub struct RouteEntry

One routing decision.

use utopia_usage::adapter::clickhouse::Stats;
Rust
pub struct Stats

Request statistics.

adapter::clickhouse::read

Own page

Reads: query parsing and validation, rows, aggregates, counts, sums, time series, the daily table, and purges.

adapter::clickhouse::route

Own page

Routing of event totals: raw events, the daily rollup, or both.

adapter::clickhouse::samples

Own page

Canonical samples: the immutable ledger, watermarks and evidence reads.

adapter::clickhouse::setup

Own page

Health, the schema (setup()), and the daily rollup's backfill.

adapter::database

Own page

The 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;
Rust
pub struct Database

Usage 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.

Also implements Debug.
Rust
pub const COLLECTION: &str = "usage"

The collection metrics are stored in.