From c66baced0314ea486245123b1a990cd103802093 Mon Sep 17 00:00:00 2001 From: michaelfeil <63565275+michaelfeil@users.noreply.github.com> Date: Fri, 20 Mar 2026 13:43:28 -0700 Subject: [PATCH] better buckets --- router/src/prometheus.rs | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/router/src/prometheus.rs b/router/src/prometheus.rs index d011efbad..6d0c64bba 100644 --- a/router/src/prometheus.rs +++ b/router/src/prometheus.rs @@ -22,20 +22,33 @@ pub(crate) fn prometheus_builer( duration_buckets.push(value); } - // Input Length buckets + // Input Length buckets: half-steps up to 32k, then powers of 2 let input_length_matcher = Matcher::Full(String::from("te_request_input_length")); - let input_length_buckets: Vec = (0..20) - .map(|x| 2.0_f64.powi(x)) - .filter(|x| (*x as usize) <= max_input_length) - .collect(); + let input_length_buckets: Vec = [ + 1.0, 2.0, 4.0, 8.0, 16.0, 32.0, 64.0, 128.0, 256.0, 512.0, 768.0, 1024.0, 1536.0, 2048.0, + 3072.0, 4096.0, 6144.0, 8192.0, 12288.0, 16384.0, 24576.0, 32768.0, 65536.0, 131072.0, + 262144.0, 524288.0, + ] + .into_iter() + .filter(|x| (*x as usize) <= max_input_length) + .collect(); - // Batch size buckets + // Batch size buckets: 1-32 (all integers), then powers of 2 let batch_size_matcher = Matcher::Full(String::from("te_batch_next_size")); - let batch_size_buckets: Vec = (0..13).map(|x| 2.0_f64.powi(x)).collect(); + let batch_size_buckets: Vec = (1..=32) + .map(|x| x as f64) + .chain((7..13).map(|x| 2.0_f64.powi(x))) + .collect(); - // Batch tokens buckets + // Batch tokens buckets: half-steps up to 32k, then powers of 2 let batch_tokens_matcher = Matcher::Full(String::from("te_batch_next_tokens")); - let batch_tokens_buckets: Vec = (0..21).map(|x| 2.0_f64.powi(x)).collect(); + let batch_tokens_buckets: Vec = [ + 1.0, 2.0, 4.0, 8.0, 16.0, 32.0, 64.0, 128.0, 256.0, 512.0, 768.0, 1024.0, 1536.0, 2048.0, + 3072.0, 4096.0, 6144.0, 8192.0, 12288.0, 16384.0, 24576.0, 32768.0, 65536.0, 131072.0, + 262144.0, 524288.0, 1048576.0, + ] + .into_iter() + .collect(); // Prometheus handler PrometheusBuilder::new()