Skip to content

Commit

Permalink
chore: Move transform configuration into vector-core (vectordotdev#8584)
Browse files Browse the repository at this point in the history
* 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
blt authored and dbcfd committed Aug 18, 2021
1 parent a10df50 commit 3985c8a
Show file tree
Hide file tree
Showing 15 changed files with 422 additions and 384 deletions.
6 changes: 5 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,6 @@ approx = "0.5.0"
assert_cmd = "1.0.7"
base64 = "0.13.0"
criterion = { version = "0.3.5", features = ["html_reports", "async_tokio"] }
env-test-util = "1.0.1"
httpmock = { version = "0.5.8", default-features = false }
libc = "0.2.98"
libz-sys = "1.1.3"
Expand Down
7 changes: 6 additions & 1 deletion lib/vector-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ edition = "2018"
publish = false

[dependencies]
async-trait = { version = "0.1", default-features = false }
async-graphql = { version = "=2.6.4", default-features = false, optional = true }
async-trait = { version = "0.1", default-features = false }
atomig = { version = "0.3.1", features = ["derive", "serde"] }
buffers = { path = "buffers", default-features = false }
bytes = { version = "1.0.1", default-features = false, features = ["serde"] }
Expand All @@ -17,13 +17,16 @@ derivative = { version = "2.2.0", default-features = false }
dyn-clone = { version = "1.0.4", default-features = false }
futures = { version = "0.3.16", default-features = false, features = ["std"] }
getset = { version = "0.1.1", default-features = false }
http = { version = "0.2.4", default-features = false }
hyper-proxy = { version = "0.9.1", default-features = false, features = ["openssl-tls"] }
indexmap = { version = "1.7.0", default-features = false, features = ["serde"] }
lazy_static = { version = "1.4.0", default-features = false }
lookup = { path = "../lookup", features = ["arbitrary"] }
metrics = { version = "0.17.0", default-features = false, features = ["std"]}
metrics-tracing-context = { version = "0.8.0", default-features = false }
metrics-util = { version = "0.10.0", default-features = false, features = ["std"] }
mlua = { version = "0.6.2", default-features = false, features = ["lua54", "send", "vendored"], optional = true }
no-proxy = { version = "0.3.1", default-features = false, features = ["serialize"] }
once_cell = { version = "1.8", default-features = false }
pest = { version = "2.1.3", default-features = false }
pest_derive = { version = "2.1.0", default-features = false }
Expand All @@ -42,6 +45,7 @@ tracing = { version = "0.1.26", default-features = false }
tracing-core = { version = "0.1.17", default-features = false }
tracing-log = { version = "0.1.2", default-features = false }
tracing-subscriber = { version = "0.2.19", default-features = false }
typetag = { version = "0.1.7", default-features = false }
twox-hash = { version = "1.6.0", default-features = false }
vrl-core = { package = "vrl", path = "../vrl/core", optional = true }

Expand All @@ -50,6 +54,7 @@ prost-build = "0.7.0"

[dev-dependencies]
criterion = { version = "0.3.5", features = ["html_reports"] }
env-test-util = "1.0.1"
quickcheck = "1.0.3"
pretty_assertions = "0.7.2"
tokio-test = "0.4.2"
Expand Down
93 changes: 93 additions & 0 deletions lib/vector-core/src/config/global_options.rs
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)
}
}
3 changes: 3 additions & 0 deletions lib/vector-core/src/config/mod.rs
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};
Loading

0 comments on commit 3985c8a

Please sign in to comment.