Skip to main content

ObservationLog

Struct ObservationLog 

Source
pub struct ObservationLog {
    pub max_age_secs: u64,
    /* private fields */
}
Expand description

Append-only, TTL-pruned observation log backed by redb.

Fields§

§max_age_secs: u64

Implementations§

Source§

impl ObservationLog

Source

pub fn open(path: &Path, max_age_secs: u64) -> Result<Self, ObsLogError>

Open or create an observation log at the given path.

Source

pub fn append( &self, source: &str, value: f64, metadata: BTreeMap<String, String>, ) -> Result<(), ObsLogError>

Append a single observation.

Source

pub fn append_batch( &self, observations: &[(String, f64, BTreeMap<String, String>)], ) -> Result<(), ObsLogError>

Append a batch of observations in a single transaction.

Source

pub fn query( &self, source: &str, since_ts_ms: u64, ) -> Result<Vec<Observation>, ObsLogError>

Query observations for a source since a given timestamp.

Source

pub fn query_latest( &self, source: &str, ) -> Result<Option<Observation>, ObsLogError>

Get the most recent observation for a source.

Source

pub fn sources(&self) -> Result<Vec<String>, ObsLogError>

List distinct sources that have observations.

Source

pub fn truncate(&self, before_ts_ms: u64) -> Result<u64, ObsLogError>

Delete all observations older than before_ts_ms. Returns count deleted.

Source

pub fn count(&self) -> Result<u64, ObsLogError>

Total number of observations.

Source

pub fn size_bytes(&self) -> u64

Size of the redb file in bytes.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.