export bao client-cert not_before/not_after gauges and alert past 80% of lifetime
This commit is contained in:
parent
daea7a56be
commit
078696aaee
1 changed files with 604 additions and 53 deletions
|
|
@ -63,6 +63,32 @@ pub fn body(runs: &[RunSamples]) -> Value {
|
|||
})
|
||||
}
|
||||
|
||||
/// The request body for the two `bao.client_cert.*` gauges of the certificate
|
||||
/// reported as `cert`, stamped `at_unix_nanos`, named as in
|
||||
/// [`swarm_secret_client::cert`] so the alert rule and every exporter agree.
|
||||
pub fn cert_body(cert: &str, not_before: i64, not_after: i64, at_unix_nanos: i128) -> Value {
|
||||
let point = |value: i64| {
|
||||
json!({
|
||||
"attributes": [attribute("cert", cert)],
|
||||
"timeUnixNano": at_unix_nanos.to_string(),
|
||||
"asInt": value.to_string(),
|
||||
})
|
||||
};
|
||||
let gauge = |name: &str, value: i64| json!({ "name": name, "unit": "s", "gauge": { "dataPoints": [point(value)] } });
|
||||
json!({
|
||||
"resourceMetrics": [{
|
||||
"resource": { "attributes": [attribute("service.name", SERVICE_NAME)] },
|
||||
"scopeMetrics": [{
|
||||
"scope": { "name": SERVICE_NAME },
|
||||
"metrics": [
|
||||
gauge(swarm_secret_client::cert::NOT_BEFORE_METRIC, not_before),
|
||||
gauge(swarm_secret_client::cert::NOT_AFTER_METRIC, not_after),
|
||||
],
|
||||
}],
|
||||
}],
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
|
@ -135,4 +161,26 @@ mod tests {
|
|||
assert_eq!(waits[0]["asDouble"], 279.0);
|
||||
assert_eq!(waits[0]["timeUnixNano"], "1792163610000000000");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_cert_gauges_carry_the_window_under_the_cert_label() {
|
||||
let b = cert_body(
|
||||
"ci-metrics",
|
||||
1_767_225_600,
|
||||
1_775_001_600,
|
||||
1_792_163_610_000_000_000,
|
||||
);
|
||||
let metrics = &b["resourceMetrics"][0]["scopeMetrics"][0]["metrics"];
|
||||
assert_eq!(metrics[0]["name"], "bao.client_cert.not_before");
|
||||
assert_eq!(metrics[1]["name"], "bao.client_cert.not_after");
|
||||
for (i, value) in [(0, "1767225600"), (1, "1775001600")] {
|
||||
let point = &metrics[i]["gauge"]["dataPoints"][0];
|
||||
assert_eq!(point["asInt"], value);
|
||||
assert_eq!(point["timeUnixNano"], "1792163610000000000");
|
||||
assert_eq!(
|
||||
point["attributes"],
|
||||
json!([{"key": "cert", "value": {"stringValue": "ci-metrics"}}])
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue