use std::time::Duration;
use vise::{Buckets, Counter, EncodeLabelSet, EncodeLabelValue, Family, Gauge, Histogram, Metrics};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, EncodeLabelSet, EncodeLabelValue)]
#[metrics(label = "stage", rename_all = "snake_case")]
pub(super) enum ValuesUpdateStage {
LoadKeys,
RemoveStaleKeys,
}
#[derive(Debug, Metrics)]
#[metrics(prefix = "server_state_cache")]
pub(super) struct ValuesCacheMetrics {
pub stale_values: Counter,
pub values_emptied: Counter,
#[metrics(buckets = Buckets::LATENCIES)]
pub values_update: Family<ValuesUpdateStage, Histogram<Duration>>,
#[metrics(buckets = &[10.0, 20.0, 50.0, 100.0, 200.0, 500.0, 1_000.0])]
pub values_update_modified_keys: Histogram<usize>,
pub values_valid_for_miniblock: Gauge<u64>,
pub effective_values: Counter,
}
#[vise::register]
pub(super) static CACHE_METRICS: vise::Global<ValuesCacheMetrics> = vise::Global::new();
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, EncodeLabelSet, EncodeLabelValue)]
#[metrics(label = "method", rename_all = "snake_case")]
pub(super) enum Method {
ReadValue,
IsWriteInitial,
LoadFactoryDep,
}
#[derive(Debug, Metrics)]
#[metrics(prefix = "state_postgres")]
pub(super) struct PostgresStorageMetrics {
#[metrics(buckets = Buckets::LATENCIES)]
pub storage: Family<Method, Histogram<Duration>>,
}
#[vise::register]
pub(super) static STORAGE_METRICS: vise::Global<PostgresStorageMetrics> = vise::Global::new();