From 8bbce62290e8dacc55ca565ec9c2aa9a3d4a5460 Mon Sep 17 00:00:00 2001 From: Daniil Polyakov Date: Mon, 3 Aug 2026 19:44:55 +0300 Subject: [PATCH] chore(dashboard_gen): add quantile range check --- tools/dashboard_gen/src/lib.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tools/dashboard_gen/src/lib.rs b/tools/dashboard_gen/src/lib.rs index 06104582..113592c0 100644 --- a/tools/dashboard_gen/src/lib.rs +++ b/tools/dashboard_gen/src/lib.rs @@ -494,7 +494,8 @@ impl Dashboard { /// The dropdown driving every [`selected_percentile`] query, offering /// `percentiles` (e.g. `[50, 90, 95, 99]`) with `default` pre-selected. /// -/// Panics if `default` is not one of `percentiles`. +/// Panics if `default` is not one of `percentiles`, or if any of them falls +/// outside `p1..=p99`. #[must_use] pub fn percentile_variable(percentiles: &[u32], default: u32) -> Variable { assert!( @@ -562,7 +563,15 @@ pub fn selected_percentile(metric: &str, labels: &[&str], legend: &str) -> Targe /// A percentile as its `histogram_quantile` argument, derived without float /// math: zero-pad to two digits then drop trailing zeros (50 → `0.5`). +/// +/// Panics outside `1..=99`, the only range two digits render: p100 would come +/// out as `0.1` and p0 as `0.`, neither of them loudly. fn quantile(percentile: u32) -> String { + assert!( + (1..=99).contains(&percentile), + "p{percentile} is outside the supported range p1..=p99", + ); + let quantile = format!("0.{percentile:02}"); quantile.trim_end_matches('0').to_owned() }