Skip to content

Commit 1c05ce3

Browse files
authored
chore(config): Enable pedantic lints for validation and watchers (#26595)
1 parent ed27857 commit 1c05ce3

5 files changed

Lines changed: 73 additions & 34 deletions

File tree

‎src/config/unit_test/mod.rs‎

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![warn(clippy::pedantic)]
2+
13
// should match vector-unit-test-tests feature
24
#[cfg(all(
35
test,
@@ -64,6 +66,8 @@ pub struct UnitTestResult {
6466
}
6567

6668
impl UnitTest {
69+
// https://github.com/vectordotdev/vector/issues/23659
70+
#[allow(clippy::missing_panics_doc, reason = "Panic documentation deferred")]
6771
pub async fn run(self) -> UnitTestResult {
6872
let diff = config::ConfigDiff::initial(&self.config);
6973
let (topology, _) = RunningTopology::start_validated(self.config, diff, self.pieces)
@@ -102,6 +106,8 @@ fn init_log_schema_from_paths(
102106
Ok(())
103107
}
104108

109+
// https://github.com/vectordotdev/vector/issues/23659
110+
#[allow(clippy::missing_errors_doc, reason = "Error documentation deferred")]
105111
pub async fn build_unit_tests_main(
106112
paths: &[ConfigPath],
107113
signal_handler: &mut signal::SignalHandler,
@@ -121,12 +127,14 @@ pub async fn build_unit_tests_main(
121127
build_unit_tests(config_builder).await
122128
}
123129

130+
// https://github.com/vectordotdev/vector/issues/23659
131+
#[allow(clippy::missing_errors_doc, reason = "Error documentation deferred")]
124132
pub async fn build_unit_tests(
125133
mut config_builder: ConfigBuilder,
126134
) -> Result<Vec<UnitTest>, Vec<String>> {
127135
// Sanitize config by removing existing sources and sinks
128-
config_builder.sources = Default::default();
129-
config_builder.sinks = Default::default();
136+
config_builder.sources = IndexMap::default();
137+
config_builder.sinks = IndexMap::default();
130138

131139
let test_definitions = std::mem::take(&mut config_builder.tests);
132140
let mut tests = Vec::new();
@@ -172,6 +180,9 @@ pub struct UnitTestBuildMetadata {
172180
}
173181

174182
impl UnitTestBuildMetadata {
183+
// https://github.com/vectordotdev/vector/issues/23659
184+
#[allow(clippy::missing_errors_doc, reason = "Error documentation deferred")]
185+
#[allow(clippy::missing_panics_doc, reason = "Panic documentation deferred")]
175186
pub fn initialize(config_builder: &mut ConfigBuilder) -> Result<Self, Vec<String>> {
176187
// A unique id used to name test sources and sinks to avoid name clashes
177188
let random_id = Uuid::new_v4().to_string();
@@ -189,7 +200,7 @@ impl UnitTestBuildMetadata {
189200

190201
// Map a test source to every transform
191202
let mut template_sources = IndexMap::new();
192-
for (key, transform) in config_builder.transforms.iter_mut() {
203+
for (key, transform) in &mut config_builder.transforms {
193204
let test_source_id = source_ids
194205
.get(key)
195206
.expect("Missing test source for a transform")
@@ -235,6 +246,9 @@ impl UnitTestBuildMetadata {
235246
}
236247

237248
/// Convert test inputs into sources for use in a unit testing topology
249+
// https://github.com/vectordotdev/vector/issues/23659
250+
#[allow(clippy::missing_errors_doc, reason = "Error documentation deferred")]
251+
#[allow(clippy::missing_panics_doc, reason = "Panic documentation deferred")]
238252
pub fn hydrate_into_sources(
239253
&self,
240254
inputs: &[TestInput],
@@ -268,6 +282,9 @@ impl UnitTestBuildMetadata {
268282
}
269283

270284
/// Convert test outputs into sinks for use in a unit testing topology
285+
// https://github.com/vectordotdev/vector/issues/23659
286+
#[allow(clippy::missing_errors_doc, reason = "Error documentation deferred")]
287+
#[allow(clippy::missing_panics_doc, reason = "Panic documentation deferred")]
271288
pub fn hydrate_into_sinks(
272289
&self,
273290
test_name: &str,
@@ -296,7 +313,7 @@ impl UnitTestBuildMetadata {
296313
let sink_ids = ids.clone();
297314
let sink_config = UnitTestSinkConfig {
298315
test_name: test_name.to_string(),
299-
transform_ids: ids.iter().map(|id| id.to_string()).collect(),
316+
transform_ids: ids.iter().map(std::string::ToString::to_string).collect(),
300317
result_tx: Arc::new(Mutex::new(Some(tx))),
301318
check: UnitTestSinkCheck::Checks {
302319
conditions: built.conditions,
@@ -327,7 +344,7 @@ impl UnitTestBuildMetadata {
327344
.map(|(transform_ids, sink_config)| {
328345
let transform_ids_str = transform_ids
329346
.iter()
330-
.map(|s| s.to_string())
347+
.map(std::string::ToString::to_string)
331348
.collect::<Vec<_>>();
332349
let sink_ids = transform_ids
333350
.iter()
@@ -446,7 +463,7 @@ async fn build_unit_test(
446463
config_builder.global.wildcard_matching.unwrap_or_default(),
447464
)?;
448465
let valid_outputs = graph.output_map()?;
449-
for (_, transform) in config_builder.transforms.iter_mut() {
466+
for (_, transform) in &mut config_builder.transforms {
450467
let inputs = std::mem::take(&mut transform.inputs);
451468
transform.inputs = inputs
452469
.into_iter()
@@ -476,7 +493,7 @@ async fn build_unit_test(
476493
/// consumed but its other outputs are left unconsumed.
477494
///
478495
/// To avoid warning logs that occur when building such topologies, we construct
479-
/// a NoOp sink here whose sole purpose is to consume any "loose end" outputs.
496+
/// a `NoOp` sink here whose sole purpose is to consume any "loose end" outputs.
480497
fn get_loose_end_outputs_sink(config: &ConfigBuilder) -> Option<SinkOuter<String>> {
481498
let config = config.clone();
482499
let transform_ids = config.transforms.iter().flat_map(|(key, transform)| {
@@ -508,7 +525,7 @@ fn get_loose_end_outputs_sink(config: &ConfigBuilder) -> Option<SinkOuter<String
508525
None
509526
} else {
510527
let noop_sink = UnitTestSinkConfig {
511-
test_name: "".to_string(),
528+
test_name: String::new(),
512529
transform_ids: vec![],
513530
result_tx: Arc::new(Mutex::new(None)),
514531
check: UnitTestSinkCheck::NoOp,
@@ -545,7 +562,7 @@ fn build_and_validate_inputs(
545562
errors.push(format!(
546563
"inputs[{index}]: unable to locate target transform '{}'",
547564
input.insert_at
548-
))
565+
));
549566
}
550567
}
551568

@@ -562,6 +579,11 @@ pub(super) struct BuiltOutput {
562579
pub(super) conditions: Vec<Vec<Condition>>,
563580
}
564581

582+
// https://github.com/vectordotdev/vector/issues/23659
583+
#[allow(
584+
clippy::default_trait_access,
585+
reason = "Preserve inferred default types"
586+
)]
565587
fn build_outputs(
566588
test_outputs: &[TestOutput],
567589
) -> Result<IndexMap<Vec<OutputId>, BuiltOutput>, Vec<String>> {

‎src/config/unit_test/unit_test_components.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,9 @@ impl StreamSink<Event> for UnitTestSink {
240240
let mut check_errors = Vec::new();
241241
for (j, condition) in check.iter().enumerate() {
242242
let mut condition_errors = Vec::new();
243-
for event in output_events.iter() {
243+
for event in &output_events {
244244
match condition.check_with_context(event.clone()).0 {
245-
Ok(_) => {
245+
Ok(()) => {
246246
condition_errors.clear();
247247
break;
248248
}

‎src/config/unix.rs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![warn(clippy::pedantic)]
2+
13
use std::cell::RefCell;
24

35
use serde::{Deserialize, Serialize};
@@ -41,6 +43,8 @@ impl<T> UnixOnly<T> {
4143
/// Pass the closure with `#[cfg(unix)]` so Unix-only APIs in its body are not
4244
/// compiled on other targets. Context is accepted on every target and is
4345
/// dropped, together with the configuration, if Unix is unavailable.
46+
// https://github.com/vectordotdev/vector/issues/23659
47+
#[allow(clippy::missing_errors_doc, reason = "Error documentation deferred")]
4448
pub fn on_unix<C, R>(
4549
self,
4650
context: C,

‎src/config/validation.rs‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![warn(clippy::pedantic)]
2+
13
use std::{collections::HashMap, path::PathBuf};
24

35
use futures_util::{FutureExt, StreamExt, TryFutureExt, TryStreamExt, stream};
@@ -88,6 +90,8 @@ pub fn check_names<'a, I: Iterator<Item = &'a ComponentKey>>(names: I) -> Result
8890
}
8991
}
9092

93+
// https://github.com/vectordotdev/vector/issues/23659
94+
#[allow(clippy::items_after_statements, reason = "Helper relocation deferred")]
9195
pub fn check_shape(config: &ConfigBuilder) -> Result<(), Vec<String>> {
9296
let mut errors = vec![];
9397

@@ -214,7 +218,7 @@ pub fn check_values(config: &ConfigBuilder) -> Result<(), Vec<String>> {
214218
/// does not have a named output with the name [`DEFAULT_OUTPUT`]
215219
pub fn check_outputs(config: &ConfigBuilder) -> Result<(), Vec<String>> {
216220
let mut errors = Vec::new();
217-
for (key, source) in config.sources.iter() {
221+
for (key, source) in &config.sources {
218222
let outputs = source.inner.outputs(config.schema.log_namespace());
219223
if outputs
220224
.iter()
@@ -227,7 +231,7 @@ pub fn check_outputs(config: &ConfigBuilder) -> Result<(), Vec<String>> {
227231
}
228232
}
229233

230-
for (key, transform) in config.transforms.iter() {
234+
for (key, transform) in &config.transforms {
231235
// Structural validation: reserved names, duplicate routes, invalid sample rates.
232236
// These checks run during config compilation. Transforms that need the schema/enrichment
233237
// context must implement validate_with_context(), called later in validate.rs.
@@ -345,7 +349,10 @@ pub async fn check_buffer_preconditions(config: &Config) -> Result<(), Vec<Strin
345349
let mut errors = Vec::new();
346350

347351
for (mountpoint, buffers) in mountpoint_buffer_mapping {
348-
let buffer_max_size_total: u64 = buffers.iter().map(|usage| usage.max_size()).sum();
352+
let buffer_max_size_total: u64 = buffers
353+
.iter()
354+
.map(vector_lib::buffers::config::DiskUsage::max_size)
355+
.sum();
349356
let mountpoint_total_capacity = mountpoints
350357
.get(&mountpoint)
351358
.copied()
@@ -383,6 +390,7 @@ async fn process_partitions(partitions: Vec<Partition>) -> heim::Result<IndexMap
383390
.await
384391
}
385392

393+
#[must_use]
386394
pub fn warnings(config: &Config) -> Vec<String> {
387395
let mut warnings = vec![];
388396

‎src/config/watcher.rs‎

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![warn(clippy::pedantic)]
2+
13
use notify::{EventKind, RecursiveMode, recommended_watcher};
24
use std::{
35
collections::{HashMap, HashSet},
@@ -64,10 +66,13 @@ impl Watcher {
6466
}
6567
}
6668

67-
/// Sends a ReloadFromDisk or ReloadEnrichmentTables on config_path changes.
69+
/// Sends a `ReloadFromDisk` or `ReloadEnrichmentTables` on `config_path` changes.
6870
/// Accumulates file changes until no change for given duration has occurred.
6971
/// Has best effort guarantee of detecting all file changes from the end of
7072
/// this function until the main thread stops.
73+
// https://github.com/vectordotdev/vector/issues/23659
74+
#[allow(clippy::missing_errors_doc, reason = "Error documentation deferred")]
75+
#[allow(clippy::too_many_lines, reason = "Preserve existing control flow")]
7176
pub fn spawn_thread<'a>(
7277
watcher_conf: WatcherConfig,
7378
signal_tx: crate::signal::SignalTx,
@@ -124,7 +129,7 @@ pub fn spawn_thread<'a>(
124129
let changed_components: HashMap<_, _> = component_configs
125130
.clone()
126131
.into_iter()
127-
.flat_map(|p| p.contains(&changed_paths))
132+
.filter_map(|p| p.contains(&changed_paths))
128133
.collect();
129134

130135
// We need to read paths to resolve any inode changes that may have happened.
@@ -137,7 +142,17 @@ pub fn spawn_thread<'a>(
137142
debug!(message = "Reloaded paths.");
138143

139144
info!("Configuration file changed.");
140-
if !changed_components.is_empty() {
145+
if changed_components.is_empty() {
146+
_ = signal_tx
147+
.send(crate::signal::SignalTo::ReloadFromDisk)
148+
.map_err(|error| {
149+
error!(
150+
message = "Unable to reload configuration file. Restart Vector to reload it.",
151+
cause = %error,
152+
internal_log_rate_limit = false,
153+
);
154+
});
155+
} else {
141156
info!(
142157
"Component {:?} configuration changed.",
143158
changed_components.keys()
@@ -154,7 +169,7 @@ pub fn spawn_thread<'a>(
154169
message = "Unable to reload enrichment tables.",
155170
cause = %error,
156171
internal_log_rate_limit = false,
157-
)
172+
);
158173
});
159174
} else {
160175
_ = signal_tx
@@ -166,22 +181,12 @@ pub fn spawn_thread<'a>(
166181
message = "Unable to reload component configuration. Restart Vector to reload it.",
167182
cause = %error,
168183
internal_log_rate_limit = false,
169-
)
184+
);
170185
});
171186
}
172-
} else {
173-
_ = signal_tx
174-
.send(crate::signal::SignalTo::ReloadFromDisk)
175-
.map_err(|error| {
176-
error!(
177-
message = "Unable to reload configuration file. Restart Vector to reload it.",
178-
cause = %error,
179-
internal_log_rate_limit = false,
180-
)
181-
});
182187
}
183188
} else {
184-
debug!(message = "Ignoring event.", event = ?event)
189+
debug!(message = "Ignoring event.", event = ?event);
185190
}
186191
}
187192
}
@@ -198,7 +203,7 @@ pub fn spawn_thread<'a>(
198203
// determine if anything changed.
199204
info!("Speculating that configuration files have changed.");
200205
_ = signal_tx.send(crate::signal::SignalTo::ReloadFromDisk).map_err(|error| {
201-
error!(message = "Unable to reload configuration file. Restart Vector to reload it.", cause = %error)
206+
error!(message = "Unable to reload configuration file. Restart Vector to reload it.", cause = %error);
202207
});
203208
}
204209
}
@@ -263,7 +268,7 @@ mod tests {
263268
trace_init();
264269

265270
let delay = Duration::from_secs(3);
266-
let dir = temp_dir().to_path_buf();
271+
let dir = temp_dir().clone();
267272
let watcher_conf = WatcherConfig::RecommendedWatcher;
268273
let component_file_path = vec![dir.join("tls.cert"), dir.join("tls.key")];
269274
let http_component = ComponentKey::from("http");
@@ -324,7 +329,7 @@ mod tests {
324329
trace_init();
325330

326331
let delay = Duration::from_secs(3);
327-
let dir = temp_dir().to_path_buf();
332+
let dir = temp_dir().clone();
328333
let file_path = dir.join("vector.toml");
329334
let watcher_conf = WatcherConfig::RecommendedWatcher;
330335

@@ -403,7 +408,7 @@ mod tests {
403408
trace_init();
404409

405410
let delay = Duration::from_secs(3);
406-
let dir = temp_dir().to_path_buf();
411+
let dir = temp_dir().clone();
407412
let sub_dir = dir.join("sources");
408413
let file_path = sub_dir.join("input.toml");
409414
let watcher_conf = WatcherConfig::RecommendedWatcher;

0 commit comments

Comments
 (0)