forked from vectordotdev/vector
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Move transform configuration into vector-core (vectordotdev#8584)
* Move transform configuration into vector-core This commit moves the `TransformConfig` down into vector-core. The ambition I've got is to work closer to the architecture described in Architecture Revisit and to allow for me to experiment with transforms that directly produce into streams etc etc. Motivation here being an observation in vectordotdev#8512 that we spend a good deal of time making small vecs, which happens in the topology. Signed-off-by: Brian L. Troutwine <brian@troutwine.us> * Add env-test-util dep for Windows Signed-off-by: Brian L. Troutwine <brian@troutwine.us> * Satisfy clippy Signed-off-by: Brian L. Troutwine <brian@troutwine.us> Signed-off-by: dbcfd <bdbrowning2@gmail.com>
- Loading branch information
Showing
15 changed files
with
422 additions
and
384 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
use crate::config::proxy::ProxyConfig; | ||
use crate::config::LogSchema; | ||
use serde::{Deserialize, Serialize}; | ||
use shared::TimeZone; | ||
use snafu::{ResultExt, Snafu}; | ||
use std::fs::DirBuilder; | ||
use std::path::PathBuf; | ||
|
||
#[derive(Debug, Snafu)] | ||
pub enum DataDirError { | ||
#[snafu(display("data_dir option required, but not given here or globally"))] | ||
MissingDataDir, | ||
#[snafu(display("data_dir {:?} does not exist", data_dir))] | ||
DoesNotExist { data_dir: PathBuf }, | ||
#[snafu(display("data_dir {:?} is not writable", data_dir))] | ||
NotWritable { data_dir: PathBuf }, | ||
#[snafu(display( | ||
"Could not create subdirectory {:?} inside of data dir {:?}: {}", | ||
subdir, | ||
data_dir, | ||
source | ||
))] | ||
CouldNotCreate { | ||
subdir: PathBuf, | ||
data_dir: PathBuf, | ||
source: std::io::Error, | ||
}, | ||
} | ||
|
||
#[derive(Clone, Debug, Default, Deserialize, Serialize, PartialEq)] | ||
#[serde(default)] | ||
pub struct GlobalOptions { | ||
#[serde(default = "crate::default_data_dir")] | ||
pub data_dir: Option<PathBuf>, | ||
#[serde(skip_serializing_if = "crate::serde::skip_serializing_if_default")] | ||
pub log_schema: LogSchema, | ||
#[serde(skip_serializing_if = "crate::serde::skip_serializing_if_default")] | ||
pub timezone: TimeZone, | ||
#[serde(skip_serializing_if = "crate::serde::skip_serializing_if_default")] | ||
pub proxy: ProxyConfig, | ||
} | ||
|
||
impl GlobalOptions { | ||
/// Resolve the `data_dir` option in either the global or local config, and | ||
/// validate that it exists and is writable. | ||
/// | ||
/// # Errors | ||
/// | ||
/// Function will error if it is unable to make data directory. | ||
pub fn resolve_and_validate_data_dir( | ||
&self, | ||
local_data_dir: Option<&PathBuf>, | ||
) -> crate::Result<PathBuf> { | ||
let data_dir = local_data_dir | ||
.or_else(|| self.data_dir.as_ref()) | ||
.ok_or(DataDirError::MissingDataDir) | ||
.map_err(Box::new)? | ||
.clone(); | ||
if !data_dir.exists() { | ||
return Err(DataDirError::DoesNotExist { data_dir }.into()); | ||
} | ||
let readonly = std::fs::metadata(&data_dir) | ||
.map(|meta| meta.permissions().readonly()) | ||
.unwrap_or(true); | ||
if readonly { | ||
return Err(DataDirError::NotWritable { data_dir }.into()); | ||
} | ||
Ok(data_dir) | ||
} | ||
|
||
/// Resolve the `data_dir` option using `resolve_and_validate_data_dir` and | ||
/// then ensure a named subdirectory exists. | ||
/// | ||
/// # Errors | ||
/// | ||
/// Function will error if it is unable to make data subdirectory. | ||
pub fn resolve_and_make_data_subdir( | ||
&self, | ||
local: Option<&PathBuf>, | ||
subdir: &str, | ||
) -> crate::Result<PathBuf> { | ||
let data_dir = self.resolve_and_validate_data_dir(local)?; | ||
|
||
let mut data_subdir = data_dir.clone(); | ||
data_subdir.push(subdir); | ||
|
||
DirBuilder::new() | ||
.recursive(true) | ||
.create(&data_subdir) | ||
.with_context(|| CouldNotCreate { subdir, data_dir })?; | ||
Ok(data_subdir) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
mod global_options; | ||
mod log_schema; | ||
pub mod proxy; | ||
|
||
pub use global_options::GlobalOptions; | ||
pub use log_schema::{init_log_schema, log_schema, LogSchema}; |
Oops, something went wrong.