use std::{collections::BTreeMap, fmt::Write};
use super::escape_label;
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub struct CacheMetricLabels {
pub component: String,
pub operation: String,
pub result: String,
}
impl CacheMetricLabels {
pub fn new(
component: impl Into<String>,
operation: impl Into<String>,
result: impl Into<String>,
) -> Self {
Self {
component: component.into(),
operation: operation.into(),
result: result.into(),
}
}
}
pub(crate) fn render(output: &mut String, metrics: &BTreeMap<CacheMetricLabels, u64>) {
output.push_str(
"# HELP rs_zero_cache_events_total Cache events by component, operation and result.\n",
);
output.push_str("# TYPE rs_zero_cache_events_total counter\n");
for (labels, value) in metrics {
writeln!(
output,
"rs_zero_cache_events_total{{component=\"{}\",operation=\"{}\",result=\"{}\"}} {}",
escape_label(&labels.component),
escape_label(&labels.operation),
escape_label(&labels.result),
value
)
.ok();
}
}