-
Notifications
You must be signed in to change notification settings - Fork 2.2k
feat(cli): add --data-dir flag and VECTOR_DATA_DIR env var #25537
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| Added a `--data-dir` command-line flag (and corresponding `VECTOR_DATA_DIR` environment variable) to override the `data_dir` global configuration option. When set, it takes precedence over any `data_dir` value in the configuration file. This is useful for keeping deployment-specific paths out of the configuration file, for example when validating a configuration in a CI environment where the configured `data_dir` may not exist. | ||
|
|
||
| authors: xfocus3 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -85,6 +85,7 @@ impl ApplicationConfig { | |
| &config_paths, | ||
| watcher_conf, | ||
| opts.require_healthy, | ||
| opts.data_dir.clone(), | ||
| opts.allow_empty_config, | ||
| !opts.disable_env_var_interpolation, | ||
| graceful_shutdown_duration, | ||
|
|
@@ -555,10 +556,12 @@ pub fn build_runtime(threads: Option<usize>, thread_name: &str) -> Result<Runtim | |
| Ok(rt_builder.build().expect("Unable to create async runtime")) | ||
| } | ||
|
|
||
| #[allow(clippy::too_many_arguments)] | ||
| pub async fn load_configs( | ||
| config_paths: &[ConfigPath], | ||
| watcher_conf: Option<config::watcher::WatcherConfig>, | ||
| require_healthy: Option<bool>, | ||
| data_dir: Option<PathBuf>, | ||
| allow_empty_config: bool, | ||
| interpolate_env: bool, | ||
| graceful_shutdown_duration: Option<Duration>, | ||
|
|
@@ -648,6 +651,13 @@ pub async fn load_configs( | |
| info!("Health checks are disabled."); | ||
| } | ||
| config.healthchecks.set_require_healthy(require_healthy); | ||
| if let Some(data_dir) = data_dir { | ||
| debug!( | ||
| message = "Overriding data_dir from command line.", | ||
| ?data_dir | ||
| ); | ||
| config.global.data_dir = Some(data_dir); | ||
|
Comment on lines
+654
to
+659
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The override happens only after Useful? React with 👍 / 👎. |
||
| } | ||
| config.graceful_shutdown_duration = graceful_shutdown_duration; | ||
|
|
||
| Ok(config) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -125,6 +125,15 @@ pub struct RootOpts { | |
| #[arg(short, long, env = "VECTOR_REQUIRE_HEALTHY")] | ||
| pub require_healthy: Option<bool>, | ||
|
|
||
| /// The directory used for persisting Vector state data. | ||
| /// | ||
| /// This overrides the `data_dir` global option set in the configuration file. It is | ||
| /// useful for keeping deployment-specific paths out of the configuration file, for | ||
| /// example when validating a configuration in a CI environment where the configured | ||
| /// `data_dir` may not exist. | ||
| #[arg(long, env = "VECTOR_DATA_DIR")] | ||
| pub data_dir: Option<PathBuf>, | ||
|
Comment on lines
+134
to
+135
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This option is added only to Useful? React with 👍 / 👎.
Comment on lines
+134
to
+135
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because this is a top-level Useful? React with 👍 / 👎. |
||
|
|
||
| /// Number of threads to use for processing (default is number of available cores) | ||
| #[arg(short, long, env = "VECTOR_THREADS")] | ||
| pub threads: Option<usize>, | ||
|
|
@@ -424,3 +433,24 @@ pub fn handle_config_errors(errors: Vec<String>) -> exitcode::ExitCode { | |
|
|
||
| exitcode::CONFIG | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use std::path::PathBuf; | ||
|
|
||
| use clap::Parser; | ||
|
|
||
| use super::RootOpts; | ||
|
|
||
| #[test] | ||
| fn data_dir_defaults_to_none() { | ||
| let opts = RootOpts::try_parse_from(["vector"]).unwrap(); | ||
| assert_eq!(opts.data_dir, None); | ||
| } | ||
|
|
||
| #[test] | ||
| fn data_dir_parsed_from_flag() { | ||
| let opts = RootOpts::try_parse_from(["vector", "--data-dir", "/tmp/vector"]).unwrap(); | ||
| assert_eq!(opts.data_dir, Some(PathBuf::from("/tmp/vector"))); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This override is applied only to the initial config returned by
load_configs; reloads inhandle_signalcallconfig::load_from_paths_with_provider_and_secretsdirectly andTopologyController::reloadrejects changes to global options. With--watch-config/SIGHUP and a CLI/envdata_dirthat differs from the file (or default), the reloaded config loses this assignment, differs from the running global options, and reload fails withGlobalOptionsChangedinstead of continuing to use the requested deployment-level data directory.Useful? React with 👍 / 👎.