Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/config/api.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![warn(clippy::pedantic)]

use std::net::{Ipv4Addr, SocketAddr};

use url::Url;
Expand Down Expand Up @@ -44,18 +46,24 @@ const fn default_enabled() -> bool {
/// By default, the API binds to 127.0.0.1:8686. This function should remain public;
/// `vector top` will use it to determine which to connect to by default, if no URL
/// override is provided.
#[must_use]
pub fn default_address() -> Option<SocketAddr> {
Some(SocketAddr::new(Ipv4Addr::LOCALHOST.into(), 8686))
}

/// Default gRPC API address for `vector top` and other API clients
#[must_use]
// https://github.com/vectordotdev/vector/issues/23659
#[allow(clippy::missing_panics_doc, reason = "Panic documentation deferred")]
pub fn default_grpc_url() -> Url {
let addr = default_address().unwrap();
Url::parse(&format!("http://{addr}"))
.expect("Couldn't parse default API URL. Please report this.")
}

impl Options {
// https://github.com/vectordotdev/vector/issues/23659
#[allow(clippy::missing_errors_doc, reason = "Error documentation deferred")]
pub fn merge(&mut self, other: Self) -> Result<(), String> {
// Merge options

Expand Down
20 changes: 17 additions & 3 deletions src/config/builder.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![warn(clippy::pedantic)]

use std::{path::Path, time::Duration};

use indexmap::IndexMap;
Expand Down Expand Up @@ -132,6 +134,8 @@ impl From<Config> for ConfigBuilder {
}

impl ConfigBuilder {
// https://github.com/vectordotdev/vector/issues/23659
#[allow(clippy::missing_errors_doc, reason = "Error documentation deferred")]
pub fn build(self) -> Result<Config, Vec<String>> {
let (config, warnings) = self.build_with_warnings()?;

Expand All @@ -142,6 +146,8 @@ impl ConfigBuilder {
Ok(config)
}

// https://github.com/vectordotdev/vector/issues/23659
#[allow(clippy::missing_errors_doc, reason = "Error documentation deferred")]
pub fn build_with_warnings(self) -> Result<(Config, Vec<String>), Vec<String>> {
compiler::compile(self)
}
Expand All @@ -154,7 +160,7 @@ impl ConfigBuilder {
) {
let inputs = inputs
.iter()
.map(|value| value.to_string())
.map(std::string::ToString::to_string)
.collect::<Vec<_>>();
self.enrichment_tables.insert(
ComponentKey::from(key.into()),
Expand All @@ -175,7 +181,7 @@ impl ConfigBuilder {
) {
let inputs = inputs
.iter()
.map(|value| value.to_string())
.map(std::string::ToString::to_string)
.collect::<Vec<_>>();
let sink = SinkOuter::new(inputs, sink);
self.add_sink_outer(key, sink);
Expand All @@ -195,7 +201,7 @@ impl ConfigBuilder {
) {
let inputs = inputs
.iter()
.map(|value| value.to_string())
.map(std::string::ToString::to_string)
.collect::<Vec<_>>();
let transform = TransformOuter::new(inputs, transform);

Expand All @@ -207,6 +213,8 @@ impl ConfigBuilder {
self.global.data_dir = Some(path.to_owned());
}

// https://github.com/vectordotdev/vector/issues/23659
#[allow(clippy::missing_errors_doc, reason = "Error documentation deferred")]
pub fn append(&mut self, with: Self) -> Result<(), Vec<String>> {
let mut errors = Vec::new();

Expand Down Expand Up @@ -273,11 +281,17 @@ impl ConfigBuilder {
}

#[cfg(test)]
#[must_use]
// https://github.com/vectordotdev/vector/issues/23659
#[allow(clippy::missing_panics_doc, reason = "Panic documentation deferred")]
pub fn from_toml(input: &str) -> Self {
crate::config::format::deserialize(input, crate::config::format::Format::Toml).unwrap()
}

#[cfg(test)]
#[must_use]
// https://github.com/vectordotdev/vector/issues/23659
#[allow(clippy::missing_panics_doc, reason = "Panic documentation deferred")]
pub fn from_json(input: &str) -> Self {
crate::config::format::deserialize(input, crate::config::format::Format::Json).unwrap()
}
Expand Down
35 changes: 21 additions & 14 deletions src/config/compiler.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![warn(clippy::pedantic)]

use indexmap::{IndexMap, IndexSet};
use std::sync::Arc;
use vector_lib::config::ComponentKey;
Expand All @@ -8,6 +10,8 @@ use super::{
sink::SinkOuter, transform::get_transform_output_ids, validation,
};

// https://github.com/vectordotdev/vector/issues/23659
#[allow(clippy::too_many_lines, reason = "Preserve existing control flow")]
pub fn compile(mut builder: ConfigBuilder) -> Result<(Config, Vec<String>), Vec<String>> {
let mut errors = Vec::new();

Expand Down Expand Up @@ -112,15 +116,15 @@ pub fn compile(mut builder: ConfigBuilder) -> Result<(Config, Vec<String>), Vec<

if errors.is_empty() {
let mut config = Config {
global,
#[cfg(feature = "api")]
api,
schema,
global,
healthchecks,
enrichment_tables,
sources,
sinks,
transforms,
enrichment_tables,
tests,
secret,
graceful_shutdown_duration,
Expand Down Expand Up @@ -166,11 +170,11 @@ pub(crate) fn expand_globs(config: &mut ConfigBuilder) {
.map(|output_id| output_id.to_string())
.collect::<IndexSet<String>>();

for (id, transform) in config.transforms.iter_mut() {
for (id, transform) in &mut config.transforms {
expand_globs_inner(&mut transform.inputs, &id.to_string(), &candidates);
}

for (id, sink) in config.sinks.iter_mut() {
for (id, sink) in &mut config.sinks {
expand_globs_inner(&mut sink.inputs, &id.to_string(), &candidates);
}
}
Expand All @@ -184,7 +188,7 @@ fn validate_sinks(config: &mut Config) -> Vec<String> {
let mut errors = Vec::new();

// Validate direct sinks
for (key, sink) in config.sinks.iter_mut() {
for (key, sink) in &mut config.sinks {
let dyn_sink: &dyn DynValidatedSink = sink.inner.as_ref();
match dyn_sink.validate_dyn() {
Ok(state) => sink.validated = Some(Arc::from(state)),
Expand All @@ -193,7 +197,7 @@ fn validate_sinks(config: &mut Config) -> Vec<String> {
}

// Validate enrichment table sinks with resolved inputs.
for (key, table) in config.enrichment_tables.iter_mut() {
for (key, table) in &mut config.enrichment_tables {
if let Some((_, sink)) = table.as_sink(key) {
let dyn_sink: &dyn DynValidatedSink = sink.inner.as_ref();
match dyn_sink.validate_dyn() {
Expand All @@ -215,7 +219,7 @@ enum InputMatcher {

impl InputMatcher {
fn matches(&self, candidate: &str) -> bool {
use InputMatcher::*;
use InputMatcher::{Pattern, String};

match self {
Pattern(pattern) => pattern.matches(candidate),
Expand All @@ -224,26 +228,29 @@ impl InputMatcher {
}
}

// https://github.com/vectordotdev/vector/issues/23659
#[allow(clippy::similar_names, reason = "Naming cleanup deferred")]
fn expand_globs_inner(inputs: &mut Inputs<String>, id: &str, candidates: &IndexSet<String>) {
let raw_inputs = std::mem::take(inputs);
for raw_input in raw_inputs {
let matcher = glob::Pattern::new(&raw_input)
.map(InputMatcher::Pattern)
.unwrap_or_else(|error| {
let matcher = glob::Pattern::new(&raw_input).map_or_else(
|error| {
warn!(message = "Invalid glob pattern for input.", component_id = %id, %error);
InputMatcher::String(raw_input.to_string())
});
InputMatcher::String(raw_input.clone())
},
InputMatcher::Pattern,
);
let mut matched = false;
for input in candidates {
if matcher.matches(input) && input != id {
matched = true;
inputs.extend(Some(input.to_string()))
inputs.extend(Some(input.clone()));
}
}
// If it didn't work as a glob pattern, leave it in the inputs as-is. This lets us give
// more accurate error messages about nonexistent inputs.
if !matched {
inputs.extend(Some(raw_input))
inputs.extend(Some(raw_input));
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/config/component.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![warn(clippy::pedantic)]

use serde::Serialize;
use strum::EnumDiscriminants;
use vector_lib::configurable::{Configurable, ToValue};
Expand Down Expand Up @@ -64,6 +66,7 @@ impl<'a, T> Component<'a, T>
where
T: Configurable + Serialize + ToValue + Clone + 'static,
{
#[must_use]
pub fn kind(&self) -> ComponentKind {
self.into()
}
Expand All @@ -72,6 +75,7 @@ where
///
/// Enrichment table inputs belong to the table's derived sink. A derived
/// source is a separate component, whose key may differ from the table key.
#[must_use]
pub fn inputs(&self) -> Option<&'a [T]> {
match self {
Self::Source(_) => None,
Expand Down
19 changes: 16 additions & 3 deletions src/config/diff.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![warn(clippy::pedantic)]

use std::collections::HashSet;

use indexmap::IndexMap;
Expand All @@ -15,10 +17,12 @@ pub struct ConfigDiff {
}

impl ConfigDiff {
#[must_use]
pub fn initial(initial: &Config) -> Self {
Self::new(&Config::default(), initial, HashSet::new())
}

#[must_use]
pub fn new(old: &Config, new: &Config, components_to_reload: HashSet<ComponentKey>) -> Self {
ConfigDiff {
sources: Difference::new(&old.sources, &new.sources, &components_to_reload),
Expand All @@ -34,6 +38,7 @@ impl ConfigDiff {
}

/// Swaps removed with added in Differences.
#[must_use]
pub const fn flip(mut self) -> Self {
self.sources.flip();
self.transforms.flip();
Expand All @@ -43,6 +48,7 @@ impl ConfigDiff {
}

/// Checks whether the given component is present at all.
#[must_use]
pub fn contains(&self, key: &ComponentKey) -> bool {
self.sources.contains(key)
|| self.transforms.contains(key)
Expand All @@ -51,6 +57,7 @@ impl ConfigDiff {
}

/// Checks whether the given component is changed.
#[must_use]
pub fn is_changed(&self, key: &ComponentKey) -> bool {
self.sources.is_changed(key)
|| self.transforms.is_changed(key)
Expand All @@ -59,6 +66,7 @@ impl ConfigDiff {
}

/// Checks whether the given component is removed.
#[must_use]
pub fn is_removed(&self, key: &ComponentKey) -> bool {
self.sources.is_removed(key)
|| self.transforms.is_removed(key)
Expand Down Expand Up @@ -147,6 +155,11 @@ impl EnrichmentTableDiff {
}

#[derive(Debug)]
// https://github.com/vectordotdev/vector/issues/23659
#[allow(
clippy::struct_field_names,
reason = "Preserve field names and API contracts"
)]
pub struct Difference {
pub to_remove: HashSet<ComponentKey>,
pub to_change: HashSet<ComponentKey>,
Expand Down Expand Up @@ -402,7 +415,7 @@ mod tests {
let diff = EnrichmentTableDiff::new(
&old_config.enrichment_tables,
&new_config.enrichment_tables,
&Default::default(),
&HashSet::default(),
);

assert_eq!(
Expand Down Expand Up @@ -482,7 +495,7 @@ mod tests {
let diff = EnrichmentTableDiff::new(
&old_config.enrichment_tables,
&new_config.enrichment_tables,
&Default::default(),
&HashSet::default(),
);
let table_key = ComponentKey::from("file_table");

Expand Down Expand Up @@ -547,7 +560,7 @@ mod tests {
let diff = EnrichmentTableDiff::new(
&old_config.enrichment_tables,
&new_config.enrichment_tables,
&Default::default(),
&HashSet::default(),
);

assert_eq!(
Expand Down
16 changes: 15 additions & 1 deletion src/config/enrichment_table.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![warn(clippy::pedantic)]

use std::{any::Any, sync::Arc};

use enum_dispatch::enum_dispatch;
Expand Down Expand Up @@ -50,7 +52,7 @@ where
{
Self {
inner: inner.into(),
graph: Default::default(),
graph: GraphConfig::default(),
inputs: Inputs::from_iter(inputs),
validated: None,
}
Expand All @@ -68,6 +70,12 @@ where
// components to deserialization and build up the components and the topology in a more granular
// way, with each having "modules" for inputs (making them valid as sinks), for healthchecks,
// for providing outputs, etc.
#[must_use]
// https://github.com/vectordotdev/vector/issues/23659
#[allow(
clippy::default_trait_access,
reason = "Preserve inferred default types"
)]
pub fn as_sink(&self, default_key: &ComponentKey) -> Option<(ComponentKey, SinkOuter<T>)> {
self.inner.sink_config(default_key).map(|(key, sink)| {
(
Expand All @@ -86,6 +94,12 @@ where
})
}

#[must_use]
// https://github.com/vectordotdev/vector/issues/23659
#[allow(
clippy::default_trait_access,
reason = "Preserve inferred default types"
)]
pub fn as_source(&self, default_key: &ComponentKey) -> Option<(ComponentKey, SourceOuter)> {
self.inner.source_config(default_key).map(|(key, source)| {
(
Expand Down
Loading
Loading