From 62358bd31c096efc2037d371f614dd0633f13774 Mon Sep 17 00:00:00 2001 From: James Date: Tue, 14 Feb 2023 17:29:38 +0000 Subject: [PATCH 1/4] Fix metrics feature As reported the metrics feature was broken by still using and old reference to `meilisearch_auth::actions`. This commit switches to the new location, `meilisearch_types::keys::actions`. Resolves: #3469 See also: #2763 --- meilisearch/src/route_metrics.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meilisearch/src/route_metrics.rs b/meilisearch/src/route_metrics.rs index c1d35cf8d..96f0b223d 100644 --- a/meilisearch/src/route_metrics.rs +++ b/meilisearch/src/route_metrics.rs @@ -4,9 +4,9 @@ use actix_web::dev::{self, Service, ServiceRequest, ServiceResponse, Transform}; use actix_web::http::header; use actix_web::{Error, HttpResponse}; use futures_util::future::LocalBoxFuture; -use meilisearch_auth::actions; use meilisearch_lib::MeiliSearch; use meilisearch_types::error::ResponseError; +use meilisearch_types::keys::actions; use prometheus::{Encoder, HistogramTimer, TextEncoder}; use crate::extractors::authentication::policies::ActionPolicy; From 91048d209d28a09e2b0ef042d7d7c448a8330515 Mon Sep 17 00:00:00 2001 From: James Date: Fri, 17 Feb 2023 20:11:57 +0000 Subject: [PATCH 2/4] Fix metrics feature Metrics feature was relying on old references. Refactored with inspiration from the `get_stats` method in `meilisearch/src/routes/lib.rs`. `enable_metrics_routes` added to options in `segment_analytics`. Resolves: #3469 See also: #2763 --- meilisearch/src/analytics/segment_analytics.rs | 1 + meilisearch/src/lib.rs | 3 ++- meilisearch/src/route_metrics.rs | 13 +++++++++---- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/meilisearch/src/analytics/segment_analytics.rs b/meilisearch/src/analytics/segment_analytics.rs index 21b6696e7..b3c4b8d07 100644 --- a/meilisearch/src/analytics/segment_analytics.rs +++ b/meilisearch/src/analytics/segment_analytics.rs @@ -249,6 +249,7 @@ 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 { + enable_metrics_route: _, db_path, http_addr, master_key: _, diff --git a/meilisearch/src/lib.rs b/meilisearch/src/lib.rs index 7a7555659..54efaac81 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 96f0b223d..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_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); From 5cff435bf6e44bc2e727ccd1872167f64101a6d6 Mon Sep 17 00:00:00 2001 From: James Date: Tue, 21 Feb 2023 07:41:41 +0000 Subject: [PATCH 3/4] Add feature flags to Opt structure Resolves: #3469 See also: #2763 --- meilisearch/src/analytics/segment_analytics.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/meilisearch/src/analytics/segment_analytics.rs b/meilisearch/src/analytics/segment_analytics.rs index b3c4b8d07..ffd797a48 100644 --- a/meilisearch/src/analytics/segment_analytics.rs +++ b/meilisearch/src/analytics/segment_analytics.rs @@ -249,6 +249,7 @@ 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, From ce807d760b913a0fb5d5b8a42c95266d364f5029 Mon Sep 17 00:00:00 2001 From: James Date: Tue, 21 Feb 2023 09:45:18 +0000 Subject: [PATCH 4/4] Fix formatting issue on Opt struct tab in enable_metrics_route to fix cargo fmt issues Resolves: #3469 See also: #2763 --- meilisearch/src/analytics/segment_analytics.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meilisearch/src/analytics/segment_analytics.rs b/meilisearch/src/analytics/segment_analytics.rs index ffd797a48..ea9baf767 100644 --- a/meilisearch/src/analytics/segment_analytics.rs +++ b/meilisearch/src/analytics/segment_analytics.rs @@ -250,7 +250,7 @@ impl From for Infos { // Thus we must not insert `..` at the end. let Opt { #[cfg(features = "metrics")] - enable_metrics_route: _, + enable_metrics_route: _, db_path, http_addr, master_key: _,