use crate::core::MetricKey;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum StorageMetricKey {
BytesRead,
RecordsRead,
ParseErrors,
EofReached,
LoopCount,
ReplayLagNs,
ReadLatencyNs,
IoUringSqFull,
IoUringCqOverflow,
}
impl MetricKey for StorageMetricKey {
fn name(&self) -> &'static str {
match self {
Self::BytesRead => "storage.bytes_read",
Self::RecordsRead => "storage.records_read",
Self::ParseErrors => "storage.parse_errors",
Self::EofReached => "storage.eof_reached",
Self::LoopCount => "storage.loop_count",
Self::ReplayLagNs => "storage.replay_lag_ns",
Self::ReadLatencyNs => "storage.read_latency_ns",
Self::IoUringSqFull => "storage.io_uring.sq_full",
Self::IoUringCqOverflow => "storage.io_uring.cq_overflow",
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn names_have_storage_prefix() {
let keys = [
StorageMetricKey::BytesRead,
StorageMetricKey::RecordsRead,
StorageMetricKey::ParseErrors,
StorageMetricKey::EofReached,
StorageMetricKey::LoopCount,
StorageMetricKey::ReplayLagNs,
StorageMetricKey::ReadLatencyNs,
StorageMetricKey::IoUringSqFull,
StorageMetricKey::IoUringCqOverflow,
];
for key in keys {
assert!(
key.name().starts_with("storage."),
"metric {:?} name '{}' does not start with 'storage.'",
key,
key.name(),
);
}
}
#[test]
fn all_names_unique() {
use std::collections::HashSet;
let names: HashSet<_> = [
StorageMetricKey::BytesRead,
StorageMetricKey::RecordsRead,
StorageMetricKey::ParseErrors,
StorageMetricKey::EofReached,
StorageMetricKey::LoopCount,
StorageMetricKey::ReplayLagNs,
StorageMetricKey::ReadLatencyNs,
StorageMetricKey::IoUringSqFull,
StorageMetricKey::IoUringCqOverflow,
]
.iter()
.map(|k| k.name())
.collect();
assert_eq!(names.len(), 9);
}
}