fix: harden typed metrics review findings
This commit is contained in:
@@ -2,7 +2,7 @@ use std::time::Duration;
|
||||
|
||||
use crank_metrics::{
|
||||
ExemplarTraceId, HttpMethod, HttpRoute, HttpStatusClass, exemplar_snapshot,
|
||||
record_http_request_with_exemplar, reset_exemplars_for_test,
|
||||
record_http_request_with_exemplar,
|
||||
};
|
||||
use metrics_util::debugging::DebuggingRecorder;
|
||||
|
||||
@@ -12,10 +12,16 @@ fn trace_id_is_validated_and_never_becomes_an_ordinary_label() {
|
||||
assert!(ExemplarTraceId::parse("0123456789ABCDEF0123456789ABCDEF").is_none());
|
||||
assert!(ExemplarTraceId::parse("short").is_none());
|
||||
|
||||
reset_exemplars_for_test();
|
||||
let recorder = DebuggingRecorder::new();
|
||||
let snapshotter = recorder.snapshotter();
|
||||
metrics::with_local_recorder(&recorder, || {
|
||||
record_http_request_with_exemplar(
|
||||
HttpRoute::from_matched_path("/health"),
|
||||
HttpMethod::Get,
|
||||
HttpStatusClass::Success,
|
||||
Duration::ZERO,
|
||||
ExemplarTraceId::parse("0123456789abcdef0123456789abcdef"),
|
||||
);
|
||||
record_http_request_with_exemplar(
|
||||
HttpRoute::from_matched_path("/health"),
|
||||
HttpMethod::Get,
|
||||
@@ -23,6 +29,20 @@ fn trace_id_is_validated_and_never_becomes_an_ordinary_label() {
|
||||
Duration::from_millis(10),
|
||||
ExemplarTraceId::parse("0123456789abcdef0123456789abcdef"),
|
||||
);
|
||||
record_http_request_with_exemplar(
|
||||
HttpRoute::from_matched_path("/health"),
|
||||
HttpMethod::Get,
|
||||
HttpStatusClass::Success,
|
||||
Duration::from_secs(61),
|
||||
ExemplarTraceId::parse("0123456789abcdef0123456789abcdef"),
|
||||
);
|
||||
record_http_request_with_exemplar(
|
||||
HttpRoute::from_matched_path("/health"),
|
||||
HttpMethod::Get,
|
||||
HttpStatusClass::Success,
|
||||
Duration::from_millis(10),
|
||||
None,
|
||||
);
|
||||
});
|
||||
|
||||
let aggregate = snapshotter.snapshot().into_vec();
|
||||
@@ -32,9 +52,17 @@ fn trace_id_is_validated_and_never_becomes_an_ordinary_label() {
|
||||
.all(|(key, _, _, _)| { key.key().labels().all(|label| label.key() != "trace_id") })
|
||||
);
|
||||
let exemplars = exemplar_snapshot();
|
||||
assert_eq!(exemplars.len(), 1);
|
||||
assert_eq!(
|
||||
exemplars[0].trace_id.as_str(),
|
||||
"0123456789abcdef0123456789abcdef"
|
||||
assert_eq!(exemplars.len(), 3);
|
||||
assert!(
|
||||
exemplars
|
||||
.iter()
|
||||
.all(|exemplar| exemplar.trace_id.as_str() == "0123456789abcdef0123456789abcdef")
|
||||
);
|
||||
let bounds = exemplars
|
||||
.iter()
|
||||
.map(|exemplar| exemplar.bucket_upper_bound)
|
||||
.collect::<Vec<_>>();
|
||||
assert!(bounds.contains(&Some(0.005)));
|
||||
assert!(bounds.contains(&Some(0.01)));
|
||||
assert!(bounds.contains(&None));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user