From 58db8d85ec78f2099f6d055465b74168dda84544 Mon Sep 17 00:00:00 2001 From: Kerollmops Date: Mon, 25 Sep 2023 14:28:54 +0200 Subject: [PATCH] Add the `exportPuffinReports` option to the runtime features route --- index-scheduler/src/features.rs | 13 +++++++++++++ meilisearch-types/src/features.rs | 1 + meilisearch/src/routes/features.rs | 15 ++++++++++++--- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/index-scheduler/src/features.rs b/index-scheduler/src/features.rs index 5a663fe67..ddb7f31d7 100644 --- a/index-scheduler/src/features.rs +++ b/index-scheduler/src/features.rs @@ -67,6 +67,19 @@ impl RoFeatures { .into()) } } + + pub fn check_puffin(&self) -> Result<()> { + if self.runtime.export_puffin_reports { + Ok(()) + } else { + Err(FeatureNotEnabledError { + disabled_action: "Outputting Puffin reports to disk", + feature: "export puffin reports", + issue_link: "https://github.com/meilisearch/product/discussions/693", + } + .into()) + } + } } impl FeatureData { diff --git a/meilisearch-types/src/features.rs b/meilisearch-types/src/features.rs index f62300485..a8a3646f6 100644 --- a/meilisearch-types/src/features.rs +++ b/meilisearch-types/src/features.rs @@ -5,6 +5,7 @@ use serde::{Deserialize, Serialize}; pub struct RuntimeTogglableFeatures { pub score_details: bool, pub vector_store: bool, + pub export_puffin_reports: bool, } #[derive(Default, Debug, Clone, Copy)] diff --git a/meilisearch/src/routes/features.rs b/meilisearch/src/routes/features.rs index a2822b4d4..6f68b5b3c 100644 --- a/meilisearch/src/routes/features.rs +++ b/meilisearch/src/routes/features.rs @@ -44,6 +44,8 @@ pub struct RuntimeTogglableFeatures { pub score_details: Option, #[deserr(default)] pub vector_store: Option, + #[deserr(default)] + pub export_puffin_reports: Option, } async fn patch_features( @@ -58,23 +60,30 @@ async fn patch_features( let features = index_scheduler.features()?; let old_features = features.runtime_features(); - let new_features = meilisearch_types::features::RuntimeTogglableFeatures { score_details: new_features.0.score_details.unwrap_or(old_features.score_details), vector_store: new_features.0.vector_store.unwrap_or(old_features.vector_store), + export_puffin_reports: new_features + .0 + .export_puffin_reports + .unwrap_or(old_features.export_puffin_reports), }; // explicitly destructure for analytics rather than using the `Serialize` implementation, because // the it renames to camelCase, which we don't want for analytics. // **Do not** ignore fields with `..` or `_` here, because we want to add them in the future. - let meilisearch_types::features::RuntimeTogglableFeatures { score_details, vector_store } = - new_features; + let meilisearch_types::features::RuntimeTogglableFeatures { + score_details, + vector_store, + export_puffin_reports, + } = new_features; analytics.publish( "Experimental features Updated".to_string(), json!({ "score_details": score_details, "vector_store": vector_store, + "export_puffin_reports": export_puffin_reports, }), Some(&req), );