From 8c9e51e94fad81737028e8db4edf149289c0fa58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Renault?= Date: Wed, 8 Dec 2021 11:23:16 +0100 Subject: [PATCH 1/3] Make sure that we can also specify the no-analytics flags with a boolean --- meilisearch-http/src/main.rs | 8 ++++---- meilisearch-http/src/option.rs | 12 +++++++++++- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/meilisearch-http/src/main.rs b/meilisearch-http/src/main.rs index 27c310f3a..955321a6f 100644 --- a/meilisearch-http/src/main.rs +++ b/meilisearch-http/src/main.rs @@ -50,7 +50,7 @@ async fn main() -> anyhow::Result<()> { let auth_controller = AuthController::new(&opt.db_path, &opt.master_key)?; #[cfg(all(not(debug_assertions), feature = "analytics"))] - let (analytics, user) = if !opt.no_analytics { + let (analytics, user) = if opt.analytics() { analytics::SegmentAnalytics::new(&opt, &meilisearch).await } else { analytics::MockAnalytics::new(&opt) @@ -125,9 +125,7 @@ pub fn print_launch_resume(opt: &Opt, user: &str) { #[cfg(all(not(debug_assertions), feature = "analytics"))] { - if opt.no_analytics { - eprintln!("Anonymous telemetry:\t\"Disabled\""); - } else { + if opt.analytics() { eprintln!( " Thank you for using MeiliSearch! @@ -136,6 +134,8 @@ We collect anonymized analytics to improve our product and your experience. To l Anonymous telemetry:\t\"Enabled\"" ); + } else { + eprintln!("Anonymous telemetry:\t\"Disabled\""); } } diff --git a/meilisearch-http/src/option.rs b/meilisearch-http/src/option.rs index d6b2a39dd..c6f783074 100644 --- a/meilisearch-http/src/option.rs +++ b/meilisearch-http/src/option.rs @@ -38,7 +38,7 @@ pub struct Opt { /// Do not send analytics to Meili. #[cfg(all(not(debug_assertions), feature = "analytics"))] #[structopt(long, env = "MEILI_NO_ANALYTICS")] - pub no_analytics: bool, + pub no_analytics: Option>, /// The maximum size, in bytes, of the main lmdb database directory #[structopt(long, env = "MEILI_MAX_INDEX_SIZE", default_value = "100 GiB")] @@ -129,6 +129,16 @@ pub struct Opt { } impl Opt { + /// Wether analytics should be enabled or not. + #[cfg(all(not(debug_assertions), feature = "analytics"))] + pub fn analytics(&self) -> bool { + match self.no_analytics { + None => true, + Some(None) => false, + Some(Some(disabled)) => !disabled, + } + } + pub fn get_ssl_config(&self) -> anyhow::Result> { if let (Some(cert_path), Some(key_path)) = (&self.ssl_cert_path, &self.ssl_key_path) { let client_auth = match &self.ssl_auth_path { From 47d5f659e0efca070333366555bee4848dd3ca88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Renault?= Date: Wed, 8 Dec 2021 11:24:40 +0100 Subject: [PATCH 2/3] Bump the structopt crate to 0.3.25 --- meilisearch-http/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meilisearch-http/Cargo.toml b/meilisearch-http/Cargo.toml index a4a6ef5a1..35a035c74 100644 --- a/meilisearch-http/Cargo.toml +++ b/meilisearch-http/Cargo.toml @@ -67,7 +67,7 @@ serde_json = { version = "1.0.67", features = ["preserve_order"] } sha2 = "0.9.6" siphasher = "0.3.7" slice-group-by = "0.2.6" -structopt = "0.3.23" +structopt = "0.3.25" sysinfo = "0.20.2" tar = "0.4.37" tempfile = "3.2.0" From 6ac2475abaa5877c40c62bed0be27992d39132ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Renault?= Date: Wed, 8 Dec 2021 12:02:18 +0100 Subject: [PATCH 3/3] Fix the no-analytics flag in the tests --- meilisearch-http/tests/common/server.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meilisearch-http/tests/common/server.rs b/meilisearch-http/tests/common/server.rs index 51c7b5611..7116833f5 100644 --- a/meilisearch-http/tests/common/server.rs +++ b/meilisearch-http/tests/common/server.rs @@ -98,7 +98,7 @@ pub fn default_settings(dir: impl AsRef) -> Opt { master_key: None, env: "development".to_owned(), #[cfg(all(not(debug_assertions), feature = "analytics"))] - no_analytics: true, + no_analytics: Some(Some(true)), max_index_size: Byte::from_unit(4.0, ByteUnit::GiB).unwrap(), max_task_db_size: Byte::from_unit(4.0, ByteUnit::GiB).unwrap(), http_payload_size_limit: Byte::from_unit(10.0, ByteUnit::MiB).unwrap(),