v0.34.0_1

This commit is contained in:
Mateusz Gruszczyński committed 2026-10-18 06:41:20 +02:00
1 parent 9cfc4588cc
commit f20c8da718
25 files changed
+694 -117

No files matched your search

+17 -4
View File
@@ -62,12 +62,25 @@ impl VhostMetrics {
Err(observed) => current = observed,
}
}
for (index, threshold) in DURATION_BUCKETS_US.iter().enumerate() {
if micros <= *threshold {
self.buckets[index].fetch_add(1, Ordering::Relaxed);
// Write exactly one exclusive histogram bin per exchange. Prometheus
// cumulative le=... buckets are reconstructed only when scraped.
// This removes up to 11 contended atomics for short 1 KiB responses.
let bucket = DURATION_BUCKETS_US.partition_point(|threshold| micros > *threshold);
self.buckets[bucket].fetch_add(1, Ordering::Relaxed);
}
/// A scrape-consistent cumulative representation of exclusive bins. The
/// sum of atomic snapshots is monotonic and the final count includes +Inf.
pub fn duration_histogram(&self) -> ([u64; DURATION_BUCKETS_US.len()], u64) {
let mut cumulative = [0u64; DURATION_BUCKETS_US.len()];
let mut count = 0u64;
for (index, bin) in self.buckets.iter().enumerate() {
count = count.saturating_add(bin.load(Ordering::Relaxed));
if index < DURATION_BUCKETS_US.len() {
cumulative[index] = count;
}
}
self.buckets[DURATION_BUCKETS_US.len()].fetch_add(1, Ordering::Relaxed);
(cumulative, count)
}
pub fn view(&self) -> VhostMetricsView {
+24 -1
View File
@@ -1,5 +1,23 @@
mod vhost_tests {
use super::*;
#[test]
fn exclusive_bins_reconstruct_exact_prometheus_cumulative_boundaries() {
let m = VhostMetrics::default();
m.active.store(5, Ordering::Relaxed);
for micros in [1, 5_000, 5_001, 25_000, 5_000_001] {
m.complete(200, false, std::time::Duration::from_micros(micros), 0, 1040);
}
let (cumulative, total) = m.duration_histogram();
assert_eq!(total, 5);
assert_eq!(cumulative, [2, 3, 4, 4, 4, 4, 4, 4, 4, 4]);
assert_eq!(n(&m.buckets[0]), 2);
assert_eq!(n(&m.buckets[1]), 1);
assert_eq!(n(&m.buckets[2]), 1);
assert_eq!(n(&m.buckets[10]), 1);
assert_eq!(n(&m.completed), 5);
assert_eq!(n(&m.active), 0);
}
#[test]
fn streaming_completion_and_histogram() {
let m = VhostMetrics::default();
@@ -10,7 +28,12 @@ mod vhost_tests {
assert_eq!(n(&m.status[4]), 1);
assert_eq!(n(&m.buckets[1]), 0);
assert_eq!(n(&m.buckets[2]), 1);
assert_eq!(n(&m.buckets[10]), 1);
assert_eq!(n(&m.buckets[10]), 0); // exclusive +Inf bin
let (buckets, count) = m.duration_histogram();
assert_eq!(buckets[1], 0);
assert_eq!(buckets[2], 1);
assert_eq!(buckets[9], 1);
assert_eq!(count, 1);
let view = m.view();
assert_eq!(view.requests, 0);
assert_eq!(view.completed, 1);