chore(dashboard_gen): add quantile range check

This commit is contained in:
Daniil Polyakov 2026-08-03 19:44:55 +03:00
parent 218955dd19
commit 8bbce62290

View File

@ -494,7 +494,8 @@ impl Dashboard {
/// The dropdown driving every [`selected_percentile`] query, offering /// The dropdown driving every [`selected_percentile`] query, offering
/// `percentiles` (e.g. `[50, 90, 95, 99]`) with `default` pre-selected. /// `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] #[must_use]
pub fn percentile_variable(percentiles: &[u32], default: u32) -> Variable { pub fn percentile_variable(percentiles: &[u32], default: u32) -> Variable {
assert!( 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 /// A percentile as its `histogram_quantile` argument, derived without float
/// math: zero-pad to two digits then drop trailing zeros (50 → `0.5`). /// 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 { 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}"); let quantile = format!("0.{percentile:02}");
quantile.trim_end_matches('0').to_owned() quantile.trim_end_matches('0').to_owned()
} }