From 7ae6dda03f42cf3a0b199528858ab07f10c4208a Mon Sep 17 00:00:00 2001 From: Louis Dureuil Date: Thu, 30 Jan 2025 11:30:04 +0100 Subject: [PATCH] Add new experimental feature --- crates/index-scheduler/src/features.rs | 13 +++++++++++++ crates/meilisearch-types/src/features.rs | 1 + .../meilisearch/src/analytics/segment_analytics.rs | 3 +++ crates/meilisearch/src/routes/features.rs | 11 +++++++++++ 4 files changed, 28 insertions(+) diff --git a/crates/index-scheduler/src/features.rs b/crates/index-scheduler/src/features.rs index c6c17b2d5..7d8bc86d3 100644 --- a/crates/index-scheduler/src/features.rs +++ b/crates/index-scheduler/src/features.rs @@ -86,6 +86,19 @@ impl RoFeatures { .into()) } } + + pub fn check_network(&self, disabled_action: &'static str) -> Result<()> { + if self.runtime.network { + Ok(()) + } else { + Err(FeatureNotEnabledError { + disabled_action, + feature: "network", + issue_link: "https://github.com/orgs/meilisearch/discussions/805", + } + .into()) + } + } } impl FeatureData { diff --git a/crates/meilisearch-types/src/features.rs b/crates/meilisearch-types/src/features.rs index ba67f996b..7b629bfb5 100644 --- a/crates/meilisearch-types/src/features.rs +++ b/crates/meilisearch-types/src/features.rs @@ -7,6 +7,7 @@ pub struct RuntimeTogglableFeatures { pub logs_route: bool, pub edit_documents_by_function: bool, pub contains_filter: bool, + pub network: bool, } #[derive(Default, Debug, Clone, Copy)] diff --git a/crates/meilisearch/src/analytics/segment_analytics.rs b/crates/meilisearch/src/analytics/segment_analytics.rs index a09d2ead3..388644884 100644 --- a/crates/meilisearch/src/analytics/segment_analytics.rs +++ b/crates/meilisearch/src/analytics/segment_analytics.rs @@ -196,6 +196,7 @@ struct Infos { experimental_reduce_indexing_memory_usage: bool, experimental_max_number_of_batched_tasks: usize, experimental_limit_batched_tasks_total_size: u64, + experimental_network: bool, gpu_enabled: bool, db_path: bool, import_dump: bool, @@ -286,6 +287,7 @@ impl Infos { logs_route, edit_documents_by_function, contains_filter, + network, } = features; // We're going to override every sensible information. @@ -303,6 +305,7 @@ impl Infos { experimental_replication_parameters, experimental_enable_logs_route: experimental_enable_logs_route | logs_route, experimental_reduce_indexing_memory_usage, + experimental_network: network, gpu_enabled: meilisearch_types::milli::vector::is_cuda_enabled(), db_path: db_path != PathBuf::from("./data.ms"), import_dump: import_dump.is_some(), diff --git a/crates/meilisearch/src/routes/features.rs b/crates/meilisearch/src/routes/features.rs index f46bda5a0..6c01e74bc 100644 --- a/crates/meilisearch/src/routes/features.rs +++ b/crates/meilisearch/src/routes/features.rs @@ -50,6 +50,7 @@ pub fn configure(cfg: &mut web::ServiceConfig) { logs_route: Some(false), edit_documents_by_function: Some(false), contains_filter: Some(false), + network: Some(false), })), (status = 401, description = "The authorization header is missing", body = ResponseError, content_type = "application/json", example = json!( { @@ -88,6 +89,8 @@ pub struct RuntimeTogglableFeatures { pub edit_documents_by_function: Option, #[deserr(default)] pub contains_filter: Option, + #[deserr(default)] + pub network: Option, } impl From for RuntimeTogglableFeatures { @@ -97,6 +100,7 @@ impl From for RuntimeTogg logs_route, edit_documents_by_function, contains_filter, + network, } = value; Self { @@ -104,6 +108,7 @@ impl From for RuntimeTogg logs_route: Some(logs_route), edit_documents_by_function: Some(edit_documents_by_function), contains_filter: Some(contains_filter), + network: Some(network), } } } @@ -114,6 +119,7 @@ pub struct PatchExperimentalFeatureAnalytics { logs_route: bool, edit_documents_by_function: bool, contains_filter: bool, + network: bool, } impl Aggregate for PatchExperimentalFeatureAnalytics { @@ -127,6 +133,7 @@ impl Aggregate for PatchExperimentalFeatureAnalytics { logs_route: new.logs_route, edit_documents_by_function: new.edit_documents_by_function, contains_filter: new.contains_filter, + network: new.network, }) } @@ -149,6 +156,7 @@ impl Aggregate for PatchExperimentalFeatureAnalytics { logs_route: Some(false), edit_documents_by_function: Some(false), contains_filter: Some(false), + network: Some(false), })), (status = 401, description = "The authorization header is missing", body = ResponseError, content_type = "application/json", example = json!( { @@ -181,6 +189,7 @@ async fn patch_features( .edit_documents_by_function .unwrap_or(old_features.edit_documents_by_function), contains_filter: new_features.0.contains_filter.unwrap_or(old_features.contains_filter), + network: new_features.0.network.unwrap_or(old_features.network), }; // explicitly destructure for analytics rather than using the `Serialize` implementation, because @@ -191,6 +200,7 @@ async fn patch_features( logs_route, edit_documents_by_function, contains_filter, + network, } = new_features; analytics.publish( @@ -199,6 +209,7 @@ async fn patch_features( logs_route, edit_documents_by_function, contains_filter, + network, }, &req, );