From ffa2515fe1fb718e6b48cafbf75d0ad4e27fe800 Mon Sep 17 00:00:00 2001 From: Dominic Burkart Date: Wed, 24 May 2023 17:18:24 +0200 Subject: [PATCH] source graceful_shutdown_duration flag from prepare_from_opts --- lib/vector-core/src/config/global_options.rs | 10 +++++++- src/app.rs | 3 +++ src/topology/running.rs | 24 +++++--------------- 3 files changed, 18 insertions(+), 19 deletions(-) diff --git a/lib/vector-core/src/config/global_options.rs b/lib/vector-core/src/config/global_options.rs index 3e63d863f5ab06..38a0dc0627f6e8 100644 --- a/lib/vector-core/src/config/global_options.rs +++ b/lib/vector-core/src/config/global_options.rs @@ -115,10 +115,17 @@ pub struct GlobalOptions { skip_serializing_if = "crate::serde::skip_serializing_if_default" )] pub expire_metrics_secs: Option, + + /// The amount of time, in seconds, that Vector waits for internal processes to stop gracefully + /// after a SIGINT or SIGTERM is received. Default is 60 seconds. Set to -1 to never force + /// shutdown after SIGINT/SIGTERM received. + #[serde(default)] + pub graceful_shutdown_duration: i64, } impl GlobalOptions { - /// Resolve the `data_dir` option in either the global or local config, and + /// Resolve the `data_dir` option in either the g + /// lobal or local config, and /// validate that it exists and is writable. /// /// # Errors @@ -227,6 +234,7 @@ impl GlobalOptions { proxy: self.proxy.merge(&with.proxy), expire_metrics: self.expire_metrics.or(with.expire_metrics), expire_metrics_secs: self.expire_metrics_secs.or(with.expire_metrics_secs), + graceful_shutdown_duration: self.graceful_shutdown_duration, }) } else { Err(errors) diff --git a/src/app.rs b/src/app.rs index c66adb2463375f..24a8d4ea9caf16 100644 --- a/src/app.rs +++ b/src/app.rs @@ -66,6 +66,7 @@ impl ApplicationConfig { &config_paths, opts.watch_config, opts.require_healthy, + opts.graceful_shutdown_duration, signal_handler, ) .await?; @@ -410,6 +411,7 @@ pub async fn load_configs( config_paths: &[ConfigPath], watch_config: bool, require_healthy: Option, + graceful_shutdown_duration: i64, signal_handler: &mut SignalHandler, ) -> Result { let config_paths = config::process_paths(config_paths).ok_or(exitcode::CONFIG)?; @@ -440,6 +442,7 @@ pub async fn load_configs( info!("Health checks are disabled."); } config.healthchecks.set_require_healthy(require_healthy); + config.global.graceful_shutdown_duration = graceful_shutdown_duration; Ok(config) } diff --git a/src/topology/running.rs b/src/topology/running.rs index 94746b4432f526..93cd5ce667cc85 100644 --- a/src/topology/running.rs +++ b/src/topology/running.rs @@ -17,7 +17,6 @@ use vector_common::trigger::DisabledTrigger; use super::{TapOutput, TapResource}; use crate::{ - cli::Opts, config::{ComponentKey, Config, ConfigDiff, HealthcheckOptions, Inputs, OutputId, Resource}, event::EventArray, shutdown::SourceShutdownCoordinator, @@ -56,7 +55,6 @@ impl RunningTopology { inputs_tap_metadata: HashMap::new(), outputs: HashMap::new(), outputs_tap_metadata: HashMap::new(), - config, shutdown_coordinator: SourceShutdownCoordinator::default(), detach_triggers: HashMap::new(), source_tasks: HashMap::new(), @@ -64,22 +62,12 @@ impl RunningTopology { abort_tx, watch: watch::channel(TapResource::default()), running: Arc::new(AtomicBool::new(true)), - graceful_shutdown_duration: { - if let Ok(opts) = Opts::get_matches().map_err(|error| { - // Printing to stdout/err can itself fail; ignore it. - _ = error.print(); - error!("could not access flags while instantiating RunningTopology"); - () - }) { - match opts.root.graceful_shutdown_duration { - -1 => None, - seconds => Some(Duration::from_secs(seconds as u64)) // clap validator makes sure value is >= -1 - } - } else { - // TODO should this be unreachable!() since the opts have already been validated? - Some(Duration::from_secs(60)) - } - } + graceful_shutdown_duration: + match config.global.graceful_shutdown_duration { + -1 => None, + seconds => Some(Duration::from_secs(seconds as u64)) // clap validator makes sure value is >= -1 + }, + config, } }