Skip to main content

KpiSource

Trait KpiSource 

Source
pub trait KpiSource: Send + Sync {
    // Required methods
    fn name(&self) -> &str;
    fn read<'life0, 'life1, 'async_trait>(
        &'life0 self,
        site: Uuid,
        metric: &'life1 str,
        from: DateTime<Utc>,
        to: DateTime<Utc>,
    ) -> Pin<Box<dyn Future<Output = Result<Option<f64>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
}
Expand description

A source of KPI measurements (spec 3.5 §7.11, §7.12): the edge beacon, host logs, an analytics driver, the commerce or spend ledger, the email driver. The product and the edge implement them; the tracker reads each KPI’s source by its name, the KPI’s SourceRef.

§Example

use adk_kernel::charter::KpiSource;
use chrono::{DateTime, Utc};

struct Fixed(f64);

#[async_trait::async_trait]
impl KpiSource for Fixed {
    fn name(&self) -> &str {
        "commerce"
    }

    async fn read(&self, _: uuid::Uuid, _: &str, _: DateTime<Utc>, _: DateTime<Utc>) -> adk_kernel::Result<Option<f64>> {
        Ok(Some(self.0))
    }
}

Required Methods§

Source

fn name(&self) -> &str

The source’s name, as KPIs name it in their source.

Source

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

The value of metric on site over [from, to); None when the source has nothing for the window yet.

§Errors

Returns the error that kept the source from answering; the tracker records nothing for the KPI and reads it again on the next tick.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§