1
//! Metric names and recorder setup.
2
//!
3
//! Names carry the `nomisync_` prefix because the series land in a
4
//! VictoriaMetrics shared with every other app on the cluster: a bare
5
//! `http_requests_total` would collide with anything else exporting the obvious
6
//! name, and an ad-hoc query without a namespace filter would silently mix them.
7
//! Keeping the names here as constants means the exporter and any test that
8
//! asserts on them cannot drift apart. The recorder itself is
9
//! `server::telemetry::recorder`.
10

            
11
/// Requests served, labelled by method, matched path and status.
12
pub const HTTP_REQUESTS: &str = "nomisync_http_requests_total";
13

            
14
/// Request latency in seconds, same labels; buckets live in `server::telemetry::recorder`.
15
pub use server::telemetry::recorder::HTTP_REQUEST_DURATION;
16

            
17
/// Auth attempts refused by the per-address throttle.
18
pub const AUTH_THROTTLED: &str = "nomisync_auth_throttled_total";
19

            
20
#[cfg(test)]
21
mod tests {
22
    use super::*;
23

            
24
    #[test]
25
2
    fn names_carry_the_app_prefix() {
26
2
        for name in [HTTP_REQUESTS, HTTP_REQUEST_DURATION] {
27
4
            assert!(
28
4
                name.starts_with("nomisync_"),
29
                "{name} would collide with other apps in the shared VictoriaMetrics"
30
            );
31
        }
32
2
    }
33

            
34
    #[test]
35
2
    fn recorder_renders_the_registered_series() {
36
2
        let Ok(handle) = server::telemetry::recorder::install_recorder() else {
37
            // A recorder is global and install-once; another test in this binary
38
            // may already hold it. Nothing to assert then.
39
            return;
40
        };
41
2
        metrics::counter!(HTTP_REQUESTS, &[("method", "GET")]).increment(1);
42
2
        let rendered = handle.render();
43
2
        assert!(
44
2
            rendered.contains(HTTP_REQUESTS),
45
            "exporter did not render {HTTP_REQUESTS}"
46
        );
47
2
    }
48
}