diff --git a/meilisearch-http/src/lib.rs b/meilisearch-http/src/lib.rs index a4395f606..f0ce0396c 100644 --- a/meilisearch-http/src/lib.rs +++ b/meilisearch-http/src/lib.rs @@ -7,7 +7,6 @@ pub mod task; pub mod extractors; pub mod option; pub mod routes; -pub mod metrics; use std::sync::{atomic::AtomicBool, Arc}; use std::time::Duration; @@ -145,19 +144,21 @@ pub fn dashboard(config: &mut web::ServiceConfig, _enable_frontend: bool) { macro_rules! create_app { ($data:expr, $auth:expr, $enable_frontend:expr, $opt:expr, $analytics:expr) => {{ use actix_cors::Cors; + use actix_web::dev::Service; use actix_web::middleware::TrailingSlash; use actix_web::App; - use actix_web::dev::Service; use actix_web::{middleware, web}; use meilisearch_http::error::MeilisearchHttpError; + use meilisearch_http::metrics; use meilisearch_http::routes; use meilisearch_http::{configure_data, dashboard}; use meilisearch_types::error::ResponseError; - use meilisearch_http::metrics; use lazy_static::lazy_static; - use prometheus::{opts, register_histogram_vec, register_int_counter_vec, register_int_gauge}; - use prometheus::{HistogramVec, IntCounterVec, IntGauge, HistogramTimer}; + use prometheus::{ + opts, register_histogram_vec, register_int_counter_vec, register_int_gauge, + }; + use prometheus::{HistogramTimer, HistogramVec, IntCounterVec, IntGauge}; App::new() .configure(|s| configure_data(s, $data.clone(), $auth.clone(), &$opt, $analytics)) diff --git a/meilisearch-http/src/metrics.rs b/meilisearch-http/src/metrics.rs index b93696dd3..8786d7aeb 100644 --- a/meilisearch-http/src/metrics.rs +++ b/meilisearch-http/src/metrics.rs @@ -1,5 +1,8 @@ use lazy_static::lazy_static; -use prometheus::{opts, register_histogram_vec, register_int_counter_vec, register_int_gauge, register_int_gauge_vec}; +use prometheus::{ + opts, register_histogram_vec, register_int_counter_vec, register_int_gauge, + register_int_gauge_vec, +}; use prometheus::{HistogramVec, IntCounterVec, IntGauge, IntGaugeVec}; const HTTP_RESPONSE_TIME_CUSTOM_BUCKETS: &[f64; 14] = &[ @@ -13,23 +16,21 @@ lazy_static! { &["method", "path"] ) .expect("Can't create a metric"); - - pub static ref MEILISEARCH_DB_SIZE: IntGauge = register_int_gauge!( - opts!("meilisearch_database_size", "MeiliSearch Stats DbSize") - ) + pub static ref MEILISEARCH_DB_SIZE: IntGauge = register_int_gauge!(opts!( + "meilisearch_database_size", + "MeiliSearch Stats DbSize" + )) .expect("Can't create a metric"); - - pub static ref MEILISEARCH_INDEX_COUNT: IntGauge = register_int_gauge!( - opts!("meilisearch_total_index", "MeiliSearch Stats Index Count") - ) + pub static ref MEILISEARCH_INDEX_COUNT: IntGauge = register_int_gauge!(opts!( + "meilisearch_total_index", + "MeiliSearch Stats Index Count" + )) .expect("Can't create a metric"); - pub static ref MEILISEARCH_DOCS_COUNT: IntGaugeVec = register_int_gauge_vec!( opts!("meilisearch_docs_count", "MeiliSearch Stats Docs Count"), &["index"] ) .expect("Can't create a metric"); - pub static ref HTTP_RESPONSE_TIME_SECONDS: HistogramVec = register_histogram_vec!( "http_response_time_seconds", "HTTP response times", @@ -37,4 +38,4 @@ lazy_static! { HTTP_RESPONSE_TIME_CUSTOM_BUCKETS.to_vec() ) .expect("Can't create a metric"); -} \ No newline at end of file +} diff --git a/meilisearch-http/src/routes/mod.rs b/meilisearch-http/src/routes/mod.rs index 987e50aca..469e747d8 100644 --- a/meilisearch-http/src/routes/mod.rs +++ b/meilisearch-http/src/routes/mod.rs @@ -1,5 +1,5 @@ -use actix_web::{web, HttpResponse}; use actix_web::http::header::{self}; +use actix_web::{web, HttpResponse}; use log::debug; use serde::{Deserialize, Serialize}; @@ -276,20 +276,17 @@ pub async fn get_health() -> Result { pub async fn get_metrics( meilisearch: GuardedData, MeiliSearch>, ) -> Result { - let search_rules = &meilisearch.filters().search_rules; let response = meilisearch.get_all_stats(search_rules).await?; - crate::metrics::MEILISEARCH_DB_SIZE - .set(response.database_size as i64); + crate::metrics::MEILISEARCH_DB_SIZE.set(response.database_size as i64); - crate::metrics::MEILISEARCH_INDEX_COUNT - .set(response.indexes.len() as i64); + crate::metrics::MEILISEARCH_INDEX_COUNT.set(response.indexes.len() as i64); for (index, value) in response.indexes.iter() { crate::metrics::MEILISEARCH_DOCS_COUNT - .with_label_values(&[&index]) - .set(value.number_of_documents as i64); + .with_label_values(&[index]) + .set(value.number_of_documents as i64); } let encoder = TextEncoder::new();