pub use crate::proxy_wasm::types::MetricType;
use crate::proxy_wasm::hostcalls;
use crate::{function, unwrap_or_default};
pub trait MetricsHost {
fn define_metric(&self, metric_type: MetricType, name: &str) -> u32;
fn get_metric(&self, metric_id: u32) -> u64;
fn record_metric(&self, metric_id: u32, value: u64);
fn increment_metric(&self, metric_id: u32, offset: i64);
}
pub struct DefaultMetricsHost;
impl MetricsHost for DefaultMetricsHost {
fn define_metric(&self, metric_type: MetricType, name: &str) -> u32 {
unwrap_or_default!(hostcalls::define_metric(metric_type, name))
}
fn get_metric(&self, metric_id: u32) -> u64 {
unwrap_or_default!(hostcalls::get_metric(metric_id))
}
fn record_metric(&self, metric_id: u32, value: u64) {
unwrap_or_default!(hostcalls::record_metric(metric_id, value))
}
fn increment_metric(&self, metric_id: u32, offset: i64) {
unwrap_or_default!(hostcalls::increment_metric(metric_id, offset))
}
}