From 1276aa4d661c4227dc4dc9c95df9fa8b1a9deef1 Mon Sep 17 00:00:00 2001 From: Marco Neumann Date: Tue, 3 Aug 2021 17:28:41 +0200 Subject: [PATCH 1/3] fix: fix skip replay env flag --- src/commands/run.rs | 34 ++++++++++++++++++++++++++++++++-- src/influxdb_ioxd.rs | 2 +- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/commands/run.rs b/src/commands/run.rs index 79cf1e429f..449285cb4e 100644 --- a/src/commands/run.rs +++ b/src/commands/run.rs @@ -26,6 +26,36 @@ pub enum Error { pub type Result = std::result::Result; +/// Boolean flag that works with environment variables. +/// +/// Workaround for https://github.com/TeXitoi/structopt/issues/428 +#[derive(Debug)] +pub enum BooleanFlag { + True, + False, +} + +impl std::str::FromStr for BooleanFlag { + type Err = String; + + fn from_str(s: &str) -> Result { + match s.to_ascii_lowercase().as_str() { + "yes" | "y" | "true" | "t" | "1" => Ok(Self::True), + "no" | "n" | "false" | "f" | "0" => Ok(Self::False), + _ => Err(format!( + "Invalid boolean flag '{}'. Valid options: yes, no, y, n, true, false, t, f, 1, 0", + s + )), + } + } +} + +impl From for bool { + fn from(yes_no: BooleanFlag) -> Self { + matches!(yes_no, BooleanFlag::True) + } +} + #[derive(Debug, StructOpt)] #[structopt( name = "run", @@ -241,8 +271,8 @@ Possible values (case insensitive): pub max_http_request_size: usize, /// Skip replaying the write buffer and seek to high watermark instead. - #[structopt(long = "--skip-replay", env = "IOX_SKIP_REPLAY")] - pub skip_replay_and_seek_instead: bool, + #[structopt(long = "--skip-replay", env = "IOX_SKIP_REPLAY", default_value = "no")] + pub skip_replay_and_seek_instead: BooleanFlag, } pub async fn command(config: Config) -> Result<()> { diff --git a/src/influxdb_ioxd.rs b/src/influxdb_ioxd.rs index d63b75a347..f1ed423b5a 100644 --- a/src/influxdb_ioxd.rs +++ b/src/influxdb_ioxd.rs @@ -146,7 +146,7 @@ pub async fn main(config: Config) -> Result<()> { remote_template: config.remote_template.map(RemoteTemplate::new), // TODO: Don't wipe on error (#1522) wipe_catalog_on_error: true, - skip_replay_and_seek_instead: config.skip_replay_and_seek_instead, + skip_replay_and_seek_instead: config.skip_replay_and_seek_instead.into(), }; if config.grpc_bind_address == config.http_bind_address { From c91cb041e7df639e253a337284b1ec4601a425dc Mon Sep 17 00:00:00 2001 From: Marco Neumann Date: Tue, 3 Aug 2021 17:34:59 +0200 Subject: [PATCH 2/3] fix: env prefix --- src/commands/run.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/commands/run.rs b/src/commands/run.rs index 449285cb4e..5cd592a113 100644 --- a/src/commands/run.rs +++ b/src/commands/run.rs @@ -271,7 +271,11 @@ Possible values (case insensitive): pub max_http_request_size: usize, /// Skip replaying the write buffer and seek to high watermark instead. - #[structopt(long = "--skip-replay", env = "IOX_SKIP_REPLAY", default_value = "no")] + #[structopt( + long = "--skip-replay", + env = "INFLUXDB_IOX_SKIP_REPLAY", + default_value = "no" + )] pub skip_replay_and_seek_instead: BooleanFlag, } From 12b8074d9d8e22f6002b63bde4a5a723b6a71660 Mon Sep 17 00:00:00 2001 From: Marco Neumann Date: Tue, 3 Aug 2021 18:11:21 +0200 Subject: [PATCH 3/3] fix: doc link --- src/commands/run.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands/run.rs b/src/commands/run.rs index 5cd592a113..93b3ef682f 100644 --- a/src/commands/run.rs +++ b/src/commands/run.rs @@ -28,7 +28,7 @@ pub type Result = std::result::Result; /// Boolean flag that works with environment variables. /// -/// Workaround for https://github.com/TeXitoi/structopt/issues/428 +/// Workaround for #[derive(Debug)] pub enum BooleanFlag { True,