Skip to main content

KpiStore

Trait KpiStore 

Source
pub trait KpiStore: Send + Sync {
    // Required methods
    fn record<'life0, 'async_trait>(
        &'life0 self,
        sample: KpiSample,
    ) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn samples<'life0, 'life1, 'async_trait>(
        &'life0 self,
        site: Uuid,
        kpi: &'life1 str,
        from: DateTime<Utc>,
        to: DateTime<Utc>,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<KpiSample>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn state<'life0, 'life1, 'async_trait>(
        &'life0 self,
        site: Uuid,
        kpi: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<Option<KpiState>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn put_state<'life0, 'async_trait>(
        &'life0 self,
        state: KpiState,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn guardrail<'life0, 'life1, 'async_trait>(
        &'life0 self,
        site: Uuid,
        guardrail: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<Option<GuardrailState>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn put_guardrail<'life0, 'async_trait>(
        &'life0 self,
        state: GuardrailState,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;

    // Provided method
    fn aggregates<'life0, 'life1, 'async_trait>(
        &'life0 self,
        site: Uuid,
        kpi: &'life1 str,
        period: KpiPeriod,
        from: NaiveDate,
        to_inclusive: NaiveDate,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<KpiAggregate>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
}
Expand description

The KPI time series of every site and the tracker’s state (spec 3.5 §7.11), on in-memory, SQLite, PostgreSQL and Redis.

§Example

use chrono::{NaiveDate, TimeZone, Utc};
use adk_kernel::charter::{InMemoryKpiStore, KpiPeriod, KpiSample, KpiStore};

let store = InMemoryKpiStore::new();
let site = uuid::Uuid::nil();
let at = Utc.with_ymd_and_hms(2026, 10, 20, 9, 0, 0).unwrap();
assert!(store.record(KpiSample::new(site, "leads", at, 3.0, "commerce")).await?);
assert!(!store.record(KpiSample::new(site, "leads", at, 9.0, "commerce")).await?, "one sample per instant");
let day = NaiveDate::from_ymd_opt(2026, 10, 20).unwrap();
let week = store.aggregates(site, "leads", KpiPeriod::Week, day, day).await?;
assert_eq!((week.len(), week[0].sum), (1, 3.0));

Required Methods§

Source

fn record<'life0, 'async_trait>( &'life0 self, sample: KpiSample, ) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Records sample; false, keeping the stored one, when the KPI already has a sample at that instant (to the microsecond).

§Errors

Returns KernelError::Config for a sample KpiSample::validate refuses, or KernelError::Store when the backend fails.

Source

fn samples<'life0, 'life1, 'async_trait>( &'life0 self, site: Uuid, kpi: &'life1 str, from: DateTime<Utc>, to: DateTime<Utc>, ) -> Pin<Box<dyn Future<Output = Result<Vec<KpiSample>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

The samples of kpi on site measured in [from, to), oldest first.

§Errors

Returns KernelError::Store when the backend fails.

Source

fn state<'life0, 'life1, 'async_trait>( &'life0 self, site: Uuid, kpi: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Option<KpiState>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

The tracker’s state of kpi on site, or None.

§Errors

Returns KernelError::Store when the backend fails.

Source

fn put_state<'life0, 'async_trait>( &'life0 self, state: KpiState, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Writes the tracker’s state of one KPI over the stored one.

§Errors

Returns KernelError::Store when the backend fails.

Source

fn guardrail<'life0, 'life1, 'async_trait>( &'life0 self, site: Uuid, guardrail: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Option<GuardrailState>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

The state of guardrail on site, or None.

§Errors

Returns KernelError::Store when the backend fails.

Source

fn put_guardrail<'life0, 'async_trait>( &'life0 self, state: GuardrailState, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Writes the state of one guardrail over the stored one.

§Errors

Returns KernelError::Store when the backend fails.

Provided Methods§

Source

fn aggregates<'life0, 'life1, 'async_trait>( &'life0 self, site: Uuid, kpi: &'life1 str, period: KpiPeriod, from: NaiveDate, to_inclusive: NaiveDate, ) -> Pin<Box<dyn Future<Output = Result<Vec<KpiAggregate>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

The aggregates of kpi per period from the period holding from through the one holding to_inclusive: one per period, in order, empty periods included (aggregate).

§Errors

Returns KernelError::Store when the backend fails.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§