pub struct ClickHouseMetricsBackend(/* private fields */);Expand description
Remote ClickHouse metrics storage.
connect opens the ClickHouse client and creates the Spectra metrics table
when needed. A running Spectra instance requires both this backend and
ClickHouseEventsBackend; remote storage does not use .embedded().
§Examples
Facade wiring through Spectra::builder() (requires the spectra crate with the
clickhouse feature):
ⓘ
use std::sync::Arc;
use spectra::{ClickHouseEventsBackend, ClickHouseMetricsBackend, Spectra};
let url = "http://127.0.0.1:8123";
let spectra = Spectra::builder()
.metrics_backend(Arc::new(ClickHouseMetricsBackend::connect(url).await?))
.events_backend(Arc::new(ClickHouseEventsBackend::connect(url).await?))
.build()?;Implementations§
Source§impl ClickHouseMetricsBackend
impl ClickHouseMetricsBackend
Sourcepub async fn connect(url: &str) -> Result<ClickHouseMetricsBackend, Error>
pub async fn connect(url: &str) -> Result<ClickHouseMetricsBackend, Error>
Connect to ClickHouse over HTTP or native protocol and ensure metrics tables exist.
url is typically http://host:8123. The call is async and executes DDL, so the
ClickHouse credentials need table-creation permission.
§Examples
ⓘ
use spectra_backend_clickhouse::ClickHouseMetricsBackend;
let backend = ClickHouseMetricsBackend::connect("http://127.0.0.1:8123").await?;Sourcepub fn in_memory_stub() -> ClickHouseMetricsBackend
pub fn in_memory_stub() -> ClickHouseMetricsBackend
In-memory stub that preserves the ClickHouse engine type for storage-contract tests.
§Examples
use spectra_backend_clickhouse::ClickHouseMetricsBackend;
use spectra_core::{MetricsStorageBackend, StorageEngineType};
let backend = ClickHouseMetricsBackend::in_memory_stub();
assert_eq!(backend.engine_type(), StorageEngineType::ClickHouse);Trait Implementations§
Source§impl MetricsStorageBackend for ClickHouseMetricsBackend
impl MetricsStorageBackend for ClickHouseMetricsBackend
Source§fn engine_type(&self) -> StorageEngineType
fn engine_type(&self) -> StorageEngineType
Returns the engine type for this backend.
Source§fn record_counter<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
name: &'life1 str,
labels: &'life2 Value,
delta: i64,
ts: DateTime<Utc>,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
ClickHouseMetricsBackend: 'async_trait,
fn record_counter<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
name: &'life1 str,
labels: &'life2 Value,
delta: i64,
ts: DateTime<Utc>,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
ClickHouseMetricsBackend: 'async_trait,
Records a counter increment.
Source§fn record_gauge<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
name: &'life1 str,
labels: &'life2 Value,
value: f64,
ts: DateTime<Utc>,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
ClickHouseMetricsBackend: 'async_trait,
fn record_gauge<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
name: &'life1 str,
labels: &'life2 Value,
value: f64,
ts: DateTime<Utc>,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
ClickHouseMetricsBackend: 'async_trait,
Records a gauge sample.
Source§fn record_metrics_batch<'life0, 'life1, 'async_trait>(
&'life0 self,
rows: &'life1 [MetricWriteRow],
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
ClickHouseMetricsBackend: 'async_trait,
fn record_metrics_batch<'life0, 'life1, 'async_trait>(
&'life0 self,
rows: &'life1 [MetricWriteRow],
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
ClickHouseMetricsBackend: 'async_trait,
Batch write metrics (default: per-row dispatch).
Source§fn query_range<'life0, 'async_trait>(
&'life0 self,
query: MetricsQueryRange,
) -> Pin<Box<dyn Future<Output = Result<Vec<MetricPoint>, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
ClickHouseMetricsBackend: 'async_trait,
fn query_range<'life0, 'async_trait>(
&'life0 self,
query: MetricsQueryRange,
) -> Pin<Box<dyn Future<Output = Result<Vec<MetricPoint>, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
ClickHouseMetricsBackend: 'async_trait,
Queries a time range of metric points.
Auto Trait Implementations§
impl !RefUnwindSafe for ClickHouseMetricsBackend
impl !UnwindSafe for ClickHouseMetricsBackend
impl Freeze for ClickHouseMetricsBackend
impl Send for ClickHouseMetricsBackend
impl Sync for ClickHouseMetricsBackend
impl Unpin for ClickHouseMetricsBackend
impl UnsafeUnpin for ClickHouseMetricsBackend
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more