Skip to content

Commit 673e3f5

Browse files
committed
Add check for quantile range
Signed-off-by: Palash Nigam <[email protected]>
1 parent 4d3e362 commit 673e3f5

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/metrics/summary.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ impl Summary {
5757
let stream_duration = Duration::from_secs(max_age_seconds / max_age_buckets);
5858
let last_rotated_timestamp = Instant::now();
5959

60+
if target_quantile.iter().any(|&x| x > 1.0 || x < 0.0) {
61+
panic!("Quantile value out of range");
62+
}
63+
6064
Summary{
6165
max_age_buckets,
6266
max_age_seconds,
@@ -128,7 +132,7 @@ mod tests {
128132
use super::*;
129133

130134
#[test]
131-
fn basic() {
135+
fn summary() {
132136
let summary = Summary::new(5, 10, vec![0.5, 0.9, 0.99], 0.01);
133137
summary.observe(1.0);
134138
summary.observe(5.0);
@@ -139,4 +143,10 @@ mod tests {
139143
assert_eq!(3, c);
140144
assert_eq!(vec![(0.5, 5.0), (0.9, 10.0), (0.99, 10.0)], q);
141145
}
146+
147+
#[test]
148+
#[should_panic(expected="Quantile value out of range")]
149+
fn summary_panic() {
150+
Summary::new(5, 10, vec![1.0, 5.0, 9.0], 0.01);
151+
}
142152
}

0 commit comments

Comments
 (0)