diff --git a/meilisearch/src/analytics/segment_analytics.rs b/meilisearch/src/analytics/segment_analytics.rs index 566770646..818b06240 100644 --- a/meilisearch/src/analytics/segment_analytics.rs +++ b/meilisearch/src/analytics/segment_analytics.rs @@ -249,6 +249,8 @@ impl From for Infos { // to add analytics when we add a field in the Opt. // Thus we must not insert `..` at the end. let Opt { + #[cfg(features = "metrics")] + enable_metrics_route: _, db_path, http_addr, master_key: _, diff --git a/meilisearch/src/lib.rs b/meilisearch/src/lib.rs index f17f93e74..71e7486f1 100644 --- a/meilisearch/src/lib.rs +++ b/meilisearch/src/lib.rs @@ -92,7 +92,8 @@ pub fn create_app( let app = app.configure(|s| configure_metrics_route(s, opt.enable_metrics_route)); #[cfg(feature = "metrics")] - let app = app.wrap(Condition::new(opt.enable_metrics_route, route_metrics::RouteMetrics)); + let app = + app.wrap(middleware::Condition::new(opt.enable_metrics_route, route_metrics::RouteMetrics)); app.wrap( Cors::default() .send_wildcard() diff --git a/meilisearch/src/route_metrics.rs b/meilisearch/src/route_metrics.rs index c1d35cf8d..a23c2b93d 100644 --- a/meilisearch/src/route_metrics.rs +++ b/meilisearch/src/route_metrics.rs @@ -2,21 +2,26 @@ use std::future::{ready, Ready}; use actix_web::dev::{self, Service, ServiceRequest, ServiceResponse, Transform}; use actix_web::http::header; +use actix_web::web::Data; use actix_web::{Error, HttpResponse}; use futures_util::future::LocalBoxFuture; -use meilisearch_auth::actions; -use meilisearch_lib::MeiliSearch; +use index_scheduler::IndexScheduler; +use meilisearch_auth::AuthController; use meilisearch_types::error::ResponseError; +use meilisearch_types::keys::actions; use prometheus::{Encoder, HistogramTimer, TextEncoder}; use crate::extractors::authentication::policies::ActionPolicy; use crate::extractors::authentication::GuardedData; +use crate::routes::create_all_stats; pub async fn get_metrics( - meilisearch: GuardedData, MeiliSearch>, + index_scheduler: GuardedData, Data>, + auth_controller: GuardedData, AuthController>, ) -> Result { - let search_rules = &meilisearch.filters().search_rules; - let response = meilisearch.get_all_stats(search_rules).await?; + let search_rules = &index_scheduler.filters().search_rules; + let response = + create_all_stats((*index_scheduler).clone(), (*auth_controller).clone(), search_rules)?; crate::metrics::MEILISEARCH_DB_SIZE_BYTES.set(response.database_size as i64); crate::metrics::MEILISEARCH_INDEX_COUNT.set(response.indexes.len() as i64);