Skip to content

Commit

Permalink
source graceful_shutdown_duration flag from prepare_from_opts
Browse files Browse the repository at this point in the history
  • Loading branch information
DominicBurkart committed May 24, 2023
1 parent 54556b1 commit 3903882
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 19 deletions.
9 changes: 8 additions & 1 deletion lib/vector-core/src/config/global_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,16 @@ pub struct GlobalOptions {
skip_serializing_if = "crate::serde::skip_serializing_if_default"
)]
pub expire_metrics_secs: Option<f64>,

/// 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.
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
Expand Down Expand Up @@ -227,6 +233,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)
Expand Down
3 changes: 3 additions & 0 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ impl ApplicationConfig {
&config_paths,
opts.watch_config,
opts.require_healthy,
opts.graceful_shutdown_duration,
signal_handler,
)
.await?;
Expand Down Expand Up @@ -410,6 +411,7 @@ pub async fn load_configs(
config_paths: &[ConfigPath],
watch_config: bool,
require_healthy: Option<bool>,
graceful_shutdown_duration: i64,
signal_handler: &mut SignalHandler,
) -> Result<Config, ExitCode> {
let config_paths = config::process_paths(config_paths).ok_or(exitcode::CONFIG)?;
Expand Down Expand Up @@ -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)
}
Expand Down
24 changes: 6 additions & 18 deletions src/topology/running.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -56,30 +55,19 @@ 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(),
tasks: HashMap::new(),
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,
}
}

Expand Down

0 comments on commit 3903882

Please sign in to comment.