Skip to content

Commit

Permalink
refactor to use two flags
Browse files Browse the repository at this point in the history
  • Loading branch information
DominicBurkart committed May 30, 2023
1 parent 7975b08 commit 5868aaa
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 17 deletions.
12 changes: 9 additions & 3 deletions src/app.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#![allow(missing_docs)]
use std::{collections::HashMap, num::NonZeroUsize, path::PathBuf};
use std::{collections::HashMap, num::NonZeroUsize, path::PathBuf, time::Duration};

use exitcode::ExitCode;
use futures::StreamExt;
Expand Down Expand Up @@ -62,11 +62,17 @@ impl ApplicationConfig {
) -> Result<Self, ExitCode> {
let config_paths = opts.config_paths_with_formats();

let graceful_shutdown_duration = if opts.no_forced_shutdown {
None
} else {
Some(Duration::from_secs(opts.graceful_shutdown_duration))
};

let config = load_configs(
&config_paths,
opts.watch_config,
opts.require_healthy,
opts.graceful_shutdown_duration,
graceful_shutdown_duration,
signal_handler,
)
.await?;
Expand Down Expand Up @@ -411,7 +417,7 @@ pub async fn load_configs(
config_paths: &[ConfigPath],
watch_config: bool,
require_healthy: Option<bool>,
graceful_shutdown_duration: i64,
graceful_shutdown_duration: Option<Duration>,
signal_handler: &mut SignalHandler,
) -> Result<Config, ExitCode> {
let config_paths = config::process_paths(config_paths).ok_or(exitcode::CONFIG)?;
Expand Down
22 changes: 18 additions & 4 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,24 @@ pub struct RootOpts {
pub internal_log_rate_limit: u64,

/// Set the duration in seconds to wait for graceful shutdown after SIGINT or SIGTERM are received.
/// After the duration has passed, Vector will force shutdown. Default value is 60 seconds. If set
/// to -1, Vector will never force shutdown.
#[arg(long, default_value = "60", env = "VECTOR_GRACEFUL_SHUTDOWN_DURATION", value_parser = clap::value_parser!(i64).range(-1..))]
pub graceful_shutdown_duration: i64,
/// After the duration has passed, Vector will force shutdown.
#[arg(
long,
default_value = "60",
env = "VECTOR_GRACEFUL_SHUTDOWN_DURATION",
group = "graceful-shutdown-duration"
)]
pub graceful_shutdown_duration: u64,

/// Never time out while waiting for graceful shutdown after SIGINT or SIGTERM received. This is useful
/// when you would like for Vector to attempt to send data until terminated by a SIGKILL.
#[arg(
long,
default_value = "false",
env = "VECTOR_GRACEFUL_SHUTDOWN_DURATION",
group = "graceful-shutdown-duration"
)]
pub no_forced_shutdown: bool,

/// Set runtime allocation tracing
#[cfg(feature = "allocation-tracing")]
Expand Down
9 changes: 4 additions & 5 deletions src/config/builder.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#[cfg(feature = "enterprise")]
use std::collections::BTreeMap;
use std::path::Path;
use std::{path::Path, time::Duration};

use indexmap::IndexMap;
#[cfg(feature = "enterprise")]
Expand Down Expand Up @@ -80,12 +80,11 @@ pub struct ConfigBuilder {
pub secret: IndexMap<ComponentKey, SecretBackends>,

/// The duration in seconds to wait for graceful shutdown after SIGINT or SIGTERM are received.
/// After the duration has passed, Vector will force shutdown. Default value is 60 seconds. If set
/// to -1, Vector will never force shutdown. This value can be set using a
/// [cli arg](crate::cli::RootOpts::graceful_shutdown_duration).
/// After the duration has passed, Vector will force shutdown. Default value is 60 seconds. This
/// value can be set using a [cli arg](crate::cli::RootOpts::graceful_shutdown_duration).
#[serde(default, skip)]
#[doc(hidden)]
pub graceful_shutdown_duration: i64,
pub graceful_shutdown_duration: Option<Duration>,
}

#[cfg(feature = "enterprise")]
Expand Down
3 changes: 2 additions & 1 deletion src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::{
hash::Hash,
net::SocketAddr,
path::PathBuf,
time::Duration,
};

use indexmap::IndexMap;
Expand Down Expand Up @@ -103,7 +104,7 @@ pub struct Config {
pub enrichment_tables: IndexMap<ComponentKey, EnrichmentTableOuter>,
tests: Vec<TestDefinition>,
secret: IndexMap<ComponentKey, SecretBackends>,
pub graceful_shutdown_duration: i64,
pub graceful_shutdown_duration: Option<Duration>,
}

impl Config {
Expand Down
5 changes: 1 addition & 4 deletions src/topology/running.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,7 @@ impl RunningTopology {
abort_tx,
watch: watch::channel(TapResource::default()),
running: Arc::new(AtomicBool::new(true)),
graceful_shutdown_duration: match config.graceful_shutdown_duration {
-1 => None,
seconds => Some(Duration::from_secs(seconds as u64)), // clap validator makes sure value is >= -1
},
graceful_shutdown_duration: config.graceful_shutdown_duration,
config,
}
}
Expand Down

0 comments on commit 5868aaa

Please sign in to comment.