From 57d53de40255afd45ea1f6add7ecf32a3434bc97 Mon Sep 17 00:00:00 2001 From: Tamo Date: Wed, 24 May 2023 10:47:05 +0200 Subject: [PATCH] Increase the number of buckets --- meilisearch/src/metrics.rs | 15 +++++++++++---- meilisearch/src/routes/metrics.rs | 5 ++--- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/meilisearch/src/metrics.rs b/meilisearch/src/metrics.rs index f6fdf756d..c518db941 100644 --- a/meilisearch/src/metrics.rs +++ b/meilisearch/src/metrics.rs @@ -4,12 +4,19 @@ use prometheus::{ register_int_gauge_vec, HistogramVec, IntCounterVec, IntGauge, IntGaugeVec, }; -const HTTP_RESPONSE_TIME_CUSTOM_BUCKETS: &[f64; 14] = &[ - 0.0005, 0.0008, 0.00085, 0.0009, 0.00095, 0.001, 0.00105, 0.0011, 0.00115, 0.0012, 0.0015, - 0.002, 0.003, 1.0, -]; +/// Create evenly distributed buckets +fn create_buckets() -> [f64; N] { + let mut array = [0.0; N]; + + for i in 0..N { + array[i] = ((i + 1) as f64) / N as f64; + } + + array +} lazy_static! { + pub static ref HTTP_RESPONSE_TIME_CUSTOM_BUCKETS: [f64; 100] = create_buckets(); pub static ref HTTP_REQUESTS_TOTAL: IntCounterVec = register_int_counter_vec!( opts!("http_requests_total", "HTTP requests total"), &["method", "path"] diff --git a/meilisearch/src/routes/metrics.rs b/meilisearch/src/routes/metrics.rs index 874a1a5a5..83cd50542 100644 --- a/meilisearch/src/routes/metrics.rs +++ b/meilisearch/src/routes/metrics.rs @@ -17,7 +17,7 @@ pub fn configure(config: &mut web::ServiceConfig) { pub async fn get_metrics( index_scheduler: GuardedData, Data>, - auth_controller: GuardedData, Data>, + auth_controller: Data, ) -> Result { let auth_filters = index_scheduler.filters(); if !auth_filters.all_indexes_authorized() { @@ -28,8 +28,7 @@ pub async fn get_metrics( return Err(error); } - let response = - create_all_stats((*index_scheduler).clone(), (*auth_controller).clone(), auth_filters)?; + let response = create_all_stats((*index_scheduler).clone(), auth_controller, auth_filters)?; crate::metrics::MEILISEARCH_DB_SIZE_BYTES.set(response.database_size as i64); crate::metrics::MEILISEARCH_INDEX_COUNT.set(response.indexes.len() as i64);