Skip to content

Commit f121b4c

Browse files
refactor to use two flags
1 parent 7975b08 commit f121b4c

File tree

5 files changed

+32
-14
lines changed

5 files changed

+32
-14
lines changed

src/app.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#![allow(missing_docs)]
2-
use std::{collections::HashMap, num::NonZeroUsize, path::PathBuf};
2+
use std::{collections::HashMap, num::NonZeroUsize, path::PathBuf, time::Duration};
33

44
use exitcode::ExitCode;
55
use futures::StreamExt;
@@ -62,11 +62,17 @@ impl ApplicationConfig {
6262
) -> Result<Self, ExitCode> {
6363
let config_paths = opts.config_paths_with_formats();
6464

65+
let graceful_shutdown_duration = if opts.no_forced_shutdown {
66+
None
67+
} else {
68+
Some(Duration::from_secs(opts.graceful_shutdown_duration))
69+
};
70+
6571
let config = load_configs(
6672
&config_paths,
6773
opts.watch_config,
6874
opts.require_healthy,
69-
opts.graceful_shutdown_duration,
75+
graceful_shutdown_duration,
7076
signal_handler,
7177
)
7278
.await?;
@@ -411,7 +417,7 @@ pub async fn load_configs(
411417
config_paths: &[ConfigPath],
412418
watch_config: bool,
413419
require_healthy: Option<bool>,
414-
graceful_shutdown_duration: i64,
420+
graceful_shutdown_duration: Option<Duration>,
415421
signal_handler: &mut SignalHandler,
416422
) -> Result<Config, ExitCode> {
417423
let config_paths = config::process_paths(config_paths).ok_or(exitcode::CONFIG)?;

src/cli.rs

+18-4
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,24 @@ pub struct RootOpts {
160160
pub internal_log_rate_limit: u64,
161161

162162
/// Set the duration in seconds to wait for graceful shutdown after SIGINT or SIGTERM are received.
163-
/// After the duration has passed, Vector will force shutdown. Default value is 60 seconds. If set
164-
/// to -1, Vector will never force shutdown.
165-
#[arg(long, default_value = "60", env = "VECTOR_GRACEFUL_SHUTDOWN_DURATION", value_parser = clap::value_parser!(i64).range(-1..))]
166-
pub graceful_shutdown_duration: i64,
163+
/// After the duration has passed, Vector will force shutdown.
164+
#[arg(
165+
long,
166+
default_value = "60",
167+
env = "VECTOR_GRACEFUL_SHUTDOWN_DURATION",
168+
group = "graceful-shutdown-duration"
169+
)]
170+
pub graceful_shutdown_duration: u64,
171+
172+
/// Never time out while waiting for graceful shutdown after SIGINT or SIGTERM received. This is useful
173+
/// when you would like for Vector to attempt to send data until terminated by a SIGKILL.
174+
#[arg(
175+
long,
176+
default_value = "false",
177+
env = "VECTOR_GRACEFUL_SHUTDOWN_DURATION",
178+
group = "graceful-shutdown-duration"
179+
)]
180+
pub no_forced_shutdown: bool,
167181

168182
/// Set runtime allocation tracing
169183
#[cfg(feature = "allocation-tracing")]

src/config/builder.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#[cfg(feature = "enterprise")]
22
use std::collections::BTreeMap;
3-
use std::path::Path;
3+
use std::{path::Path, time::Duration};
44

55
use indexmap::IndexMap;
66
#[cfg(feature = "enterprise")]
@@ -85,7 +85,7 @@ pub struct ConfigBuilder {
8585
/// [cli arg](crate::cli::RootOpts::graceful_shutdown_duration).
8686
#[serde(default, skip)]
8787
#[doc(hidden)]
88-
pub graceful_shutdown_duration: i64,
88+
pub graceful_shutdown_duration: Option<Duration>,
8989
}
9090

9191
#[cfg(feature = "enterprise")]

src/config/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::{
55
hash::Hash,
66
net::SocketAddr,
77
path::PathBuf,
8+
time::Duration,
89
};
910

1011
use indexmap::IndexMap;
@@ -103,7 +104,7 @@ pub struct Config {
103104
pub enrichment_tables: IndexMap<ComponentKey, EnrichmentTableOuter>,
104105
tests: Vec<TestDefinition>,
105106
secret: IndexMap<ComponentKey, SecretBackends>,
106-
pub graceful_shutdown_duration: i64,
107+
pub graceful_shutdown_duration: Option<Duration>,
107108
}
108109

109110
impl Config {

src/topology/running.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,7 @@ impl RunningTopology {
6262
abort_tx,
6363
watch: watch::channel(TapResource::default()),
6464
running: Arc::new(AtomicBool::new(true)),
65-
graceful_shutdown_duration: match config.graceful_shutdown_duration {
66-
-1 => None,
67-
seconds => Some(Duration::from_secs(seconds as u64)), // clap validator makes sure value is >= -1
68-
},
65+
graceful_shutdown_duration: config.graceful_shutdown_duration,
6966
config,
7067
}
7168
}

0 commit comments

Comments
 (0)