Lines
92.31 %
Functions
100 %
Branches
//! Metric names and recorder setup.
//!
//! Names carry the `nomisync_` prefix because the series land in a
//! VictoriaMetrics shared with every other app on the cluster: a bare
//! `http_requests_total` would collide with anything else exporting the obvious
//! name, and an ad-hoc query without a namespace filter would silently mix them.
//! Keeping the names here as constants means the exporter and any test that
//! asserts on them cannot drift apart. The recorder itself is
//! `server::telemetry::recorder`.
/// Requests served, labelled by method, matched path and status.
pub const HTTP_REQUESTS: &str = "nomisync_http_requests_total";
/// Request latency in seconds, same labels; buckets live in `server::telemetry::recorder`.
pub use server::telemetry::recorder::HTTP_REQUEST_DURATION;
/// Auth attempts refused by the per-address throttle.
pub const AUTH_THROTTLED: &str = "nomisync_auth_throttled_total";
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn names_carry_the_app_prefix() {
for name in [HTTP_REQUESTS, HTTP_REQUEST_DURATION] {
assert!(
name.starts_with("nomisync_"),
"{name} would collide with other apps in the shared VictoriaMetrics"
);
}
fn recorder_renders_the_registered_series() {
let Ok(handle) = server::telemetry::recorder::install_recorder() else {
// A recorder is global and install-once; another test in this binary
// may already hold it. Nothing to assert then.
return;
};
metrics::counter!(HTTP_REQUESTS, &[("method", "GET")]).increment(1);
let rendered = handle.render();
rendered.contains(HTTP_REQUESTS),
"exporter did not render {HTTP_REQUESTS}"