Skip to content

Commit 9ea96a1

Browse files
authored
chore: Enable pedantic Clippy lints in remaining sources and helpers (#26705)
1 parent fe9626b commit 9ea96a1

91 files changed

Lines changed: 1762 additions & 1141 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎clippy.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ large-error-threshold = 256 # in bytes
22
allow-unwrap-in-tests = true
33

44
# Preserve product and component names in prose.
5-
doc-valid-idents = ["ClickHouse", "GreptimeCloud", "GreptimeDB", "InfluxDB", "JetStream", "NameNode", "OpenDAL", "OpenSearch", "PostgreSQL", "SQLx", "WebHDFS", ".."]
5+
doc-valid-idents = ["ClickHouse", "GreptimeCloud", "GreptimeDB", "InfluxDB", "JetStream", "MongoDB", "NameNode", "OpenDAL", "OpenSearch", "PostgreSQL", "SQLx", "StatsD", "WebHDFS", ".."]
66

77
# for `disallowed_method`:
88
# https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_method

‎src/sources/kubernetes_logs/k8s_paths_provider.rs‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ fn extract_excluded_containers_for_pod(pod: &Pod) -> impl Iterator<Item = &str>
128128
Some(value)
129129
})
130130
.flat_map(|containers| containers.split(','))
131-
.map(|container| container.trim())
131+
.map(str::trim)
132132
})
133133
}
134134

@@ -188,7 +188,7 @@ fn real_glob(pattern: &str) -> impl Iterator<Item = PathBuf> + use<> {
188188
},
189189
)
190190
.expect("the pattern is supposed to always be correct")
191-
.flat_map(|paths| paths.into_iter())
191+
.flat_map(IntoIterator::into_iter)
192192
}
193193

194194
fn filter_paths<'a>(
@@ -459,7 +459,7 @@ mod tests {
459459

460460
let actual_paths: Vec<_> = list_pod_log_paths(mock_glob, &pod).collect();
461461
let expected_paths: Vec<_> = expected_paths.into_iter().map(PathBuf::from).collect();
462-
assert_eq!(actual_paths, expected_paths)
462+
assert_eq!(actual_paths, expected_paths);
463463
}
464464
}
465465

@@ -532,7 +532,7 @@ mod tests {
532532
actual_paths, expected_paths,
533533
"failed for patterns {:?}",
534534
&str_patterns
535-
)
535+
);
536536
}
537537
}
538538

@@ -584,7 +584,7 @@ mod tests {
584584
actual_paths, expected_paths,
585585
"failed for patterns {:?}",
586586
&str_patterns
587-
)
587+
);
588588
}
589589
}
590590

@@ -626,7 +626,7 @@ mod tests {
626626
actual_patterns, expected_patterns,
627627
"failed for dir {:?} and containers {:?}",
628628
&pod_logs_dir, &containers,
629-
)
629+
);
630630
}
631631
}
632632
}

‎src/sources/kubernetes_logs/mod.rs‎

Lines changed: 59 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
#![warn(clippy::pedantic)]
12
//! This mod implements `kubernetes_logs` source.
23
//! The scope of this source is to consume the log files that a kubelet keeps
34
//! at "/var/log/pods" on the host of the Kubernetes Node when Vector itself is
4-
//! running inside the cluster as a DaemonSet.
5+
//! running inside the cluster as a `DaemonSet`.
56
67
#![deny(missing_docs)]
78
use std::{
@@ -83,6 +84,10 @@ use self::{
8384
/// The `self_node_name` value env var key.
8485
const SELF_NODE_NAME_ENV_KEY: &str = "VECTOR_SELF_NODE_NAME";
8586

87+
#[allow(
88+
clippy::struct_excessive_bools,
89+
reason = "Restructuring these source configuration fields is deferred to preserve the existing API. https://github.com/vectordotdev/vector/issues/23659"
90+
)]
8691
/// Configuration for the `kubernetes_logs` source.
8792
#[serde_as]
8893
#[configurable_component(source("kubernetes_logs", "Collect Pod logs from Kubernetes Nodes."))]
@@ -318,11 +323,11 @@ impl GenerateConfig for Config {
318323
impl Default for Config {
319324
fn default() -> Self {
320325
Self {
321-
extra_label_selector: "".to_string(),
322-
extra_namespace_label_selector: "".to_string(),
326+
extra_label_selector: String::new(),
327+
extra_namespace_label_selector: String::new(),
323328
insert_namespace_fields: true,
324329
self_node_name: default_self_node_name_env_template(),
325-
extra_field_selector: "".to_string(),
330+
extra_field_selector: String::new(),
326331
auto_partial_merge: true,
327332
data_dir: None,
328333
pod_annotation_fields: pod_metadata_annotator::FieldsSpec::default(),
@@ -345,7 +350,7 @@ impl Default for Config {
345350
use_apiserver_cache: false,
346351
delay_deletion_ms: default_delay_deletion_ms(),
347352
log_namespace: None,
348-
internal_metrics: Default::default(),
353+
internal_metrics: FileInternalMetricsConfig::default(),
349354
rotate_wait: default_rotate_wait(),
350355
}
351356
}
@@ -370,6 +375,10 @@ impl SourceConfig for Config {
370375
))
371376
}
372377

378+
#[allow(
379+
clippy::too_many_lines,
380+
reason = "Splitting this source routine is deferred to keep the lint cleanup mechanical. https://github.com/vectordotdev/vector/issues/23659"
381+
)]
373382
fn outputs(&self, global_log_namespace: LogNamespace) -> Vec<SourceOutput> {
374383
let log_namespace = global_log_namespace.merge(self.log_namespace);
375384
let schema_definition = BytesDeserializerConfig
@@ -598,6 +607,10 @@ impl SourceConfig for Config {
598607
}
599608
}
600609

610+
#[allow(
611+
clippy::struct_excessive_bools,
612+
reason = "Restructuring these source configuration fields is deferred to preserve the existing API. https://github.com/vectordotdev/vector/issues/23659"
613+
)]
601614
#[derive(Clone)]
602615
struct Source {
603616
client: Client,
@@ -723,6 +736,10 @@ impl Source {
723736
})
724737
}
725738

739+
#[allow(
740+
clippy::too_many_lines,
741+
reason = "Splitting this source routine is deferred to keep the lint cleanup mechanical. https://github.com/vectordotdev/vector/issues/23659"
742+
)]
726743
async fn run(
727744
self,
728745
mut out: SourceSender,
@@ -1020,18 +1037,16 @@ impl Source {
10201037
shutdown,
10211038
Duration::from_secs(30), // more than enough time to propagate
10221039
)
1023-
.map(|result| {
1024-
match result {
1025-
Ok(Ok(())) => info!(message = "Event processing loop completed gracefully."),
1026-
Ok(Err(_)) => emit!(StreamClosedError {
1027-
count: events_count
1028-
}),
1029-
Err(error) => emit!(KubernetesLifecycleError {
1030-
error,
1031-
message: "Event processing loop timed out during the shutdown.",
1032-
count: events_count,
1033-
}),
1034-
};
1040+
.map(|result| match result {
1041+
Ok(Ok(())) => info!(message = "Event processing loop completed gracefully."),
1042+
Ok(Err(_)) => emit!(StreamClosedError {
1043+
count: events_count
1044+
}),
1045+
Err(error) => emit!(KubernetesLifecycleError {
1046+
error,
1047+
message: "Event processing loop timed out during the shutdown.",
1048+
count: events_count,
1049+
}),
10351050
});
10361051
slot.bind(Box::pin(fut));
10371052
}
@@ -1131,11 +1146,11 @@ fn create_event(
11311146
}
11321147
// When LogNamespace::Legacy, only set when the `ingestion_timestamp_field` is configured.
11331148
(LogNamespace::Legacy, Some(ingestion_timestamp_field)) => {
1134-
log.try_insert(ingestion_timestamp_field, Utc::now())
1149+
log.try_insert(ingestion_timestamp_field, Utc::now());
11351150
}
11361151
// The CRI/Docker parsers handle inserting the `log_schema().timestamp_key()` value.
11371152
(LogNamespace::Legacy, None) => (),
1138-
};
1153+
}
11391154

11401155
log.into()
11411156
}
@@ -1183,15 +1198,15 @@ const fn default_max_line_bytes() -> usize {
11831198
}
11841199

11851200
const fn default_glob_minimum_cooldown_ms() -> Duration {
1186-
Duration::from_millis(60_000)
1201+
Duration::from_mins(1)
11871202
}
11881203

11891204
const fn default_fingerprint_lines() -> usize {
11901205
1
11911206
}
11921207

11931208
const fn default_delay_deletion_ms() -> Duration {
1194-
Duration::from_millis(60_000)
1209+
Duration::from_mins(1)
11951210
}
11961211

11971212
const fn default_rotate_wait() -> Duration {
@@ -1236,6 +1251,10 @@ fn prepare_glob_patterns(paths: &[PathBuf], op: &str) -> crate::Result<Vec<glob:
12361251

12371252
// This function constructs the effective field selector to use, based on
12381253
// the specified configuration.
1254+
#[allow(
1255+
clippy::unnecessary_wraps,
1256+
reason = "Removing this fallible API is deferred to keep source construction and error handling unchanged. https://github.com/vectordotdev/vector/issues/23659"
1257+
)]
12391258
fn prepare_field_selector(config: &Config, self_node_name: &str) -> crate::Result<String> {
12401259
info!(
12411260
message = "Obtained Kubernetes Node name to collect logs for (self).",
@@ -1252,6 +1271,10 @@ fn prepare_field_selector(config: &Config, self_node_name: &str) -> crate::Resul
12521271
}
12531272

12541273
// This function constructs the selector for a node to annotate entries with a node metadata.
1274+
#[allow(
1275+
clippy::unnecessary_wraps,
1276+
reason = "Removing this fallible API is deferred to keep source construction and error handling unchanged. https://github.com/vectordotdev/vector/issues/23659"
1277+
)]
12551278
fn prepare_node_selector(self_node_name: &str) -> crate::Result<String> {
12561279
Ok(format!("metadata.name={self_node_name}"))
12571280
}
@@ -1372,9 +1395,9 @@ mod tests {
13721395
#[test]
13731396
fn test_config_serialization_insert_namespace_fields() {
13741397
// Test that the flag serializes/deserializes correctly from YAML
1375-
let yaml_config = indoc! {r#"
1398+
let yaml_config = indoc! {r"
13761399
insert_namespace_fields: false
1377-
"#};
1400+
"};
13781401
let config: Config = serde_yaml::from_str(yaml_config).unwrap();
13791402
assert_eq!(config.insert_namespace_fields, false);
13801403

@@ -1464,7 +1487,7 @@ mod tests {
14641487
(
14651488
Config {
14661489
self_node_name: "qwe".to_owned(),
1467-
extra_field_selector: "".to_owned(),
1490+
extra_field_selector: String::new(),
14681491
..Default::default()
14691492
},
14701493
"spec.nodeName=qwe",
@@ -1498,15 +1521,15 @@ mod tests {
14981521
),
14991522
(
15001523
Config {
1501-
extra_label_selector: "".to_owned(),
1524+
extra_label_selector: String::new(),
15021525
..Default::default()
15031526
}
15041527
.extra_label_selector,
15051528
"vector.dev/exclude!=true",
15061529
),
15071530
(
15081531
Config {
1509-
extra_namespace_label_selector: "".to_owned(),
1532+
extra_namespace_label_selector: String::new(),
15101533
..Default::default()
15111534
}
15121535
.extra_namespace_label_selector,
@@ -1536,6 +1559,10 @@ mod tests {
15361559
}
15371560
}
15381561

1562+
#[allow(
1563+
clippy::too_many_lines,
1564+
reason = "Splitting this fixture is deferred to keep the lint cleanup mechanical. https://github.com/vectordotdev/vector/issues/23659"
1565+
)]
15391566
#[test]
15401567
fn test_output_schema_definition_vector_namespace() {
15411568
let definitions = serde_yaml::from_str::<Config>("")
@@ -1660,9 +1687,13 @@ mod tests {
16601687
)
16611688
.with_meaning(OwnedTargetPath::event_root(), "message")
16621689
)
1663-
)
1690+
);
16641691
}
16651692

1693+
#[allow(
1694+
clippy::too_many_lines,
1695+
reason = "Splitting this fixture is deferred to keep the lint cleanup mechanical. https://github.com/vectordotdev/vector/issues/23659"
1696+
)]
16661697
#[test]
16671698
fn test_output_schema_definition_legacy_namespace() {
16681699
let definitions = serde_yaml::from_str::<Config>("")
@@ -1776,7 +1807,7 @@ mod tests {
17761807
None
17771808
)
17781809
)
1779-
)
1810+
);
17801811
}
17811812

17821813
#[test]

‎src/sources/kubernetes_logs/namespace_metadata_annotator.rs‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ fn annotate_from_metadata(
105105
if let Some(labels) = &metadata.labels {
106106
let legacy_key_prefix = fields_spec.namespace_labels.path.as_ref().map(|k| &k.path);
107107

108-
for (key, value) in labels.iter() {
108+
for (key, value) in labels {
109109
let key_path = path!(key);
110110
let legacy_key = legacy_key_prefix
111111
.map(|k| k.concat(key_path))
@@ -117,7 +117,7 @@ fn annotate_from_metadata(
117117
legacy_key,
118118
path!("namespace_labels", key),
119119
value.to_owned(),
120-
)
120+
);
121121
}
122122
}
123123

@@ -128,7 +128,7 @@ fn annotate_from_metadata(
128128
.as_ref()
129129
.map(|k| &k.path);
130130

131-
for (key, value) in annotations.iter() {
131+
for (key, value) in annotations {
132132
let key_path = path!(key);
133133
let legacy_key = legacy_key_prefix
134134
.map(|k| k.concat(key_path))
@@ -140,7 +140,7 @@ fn annotate_from_metadata(
140140
legacy_key,
141141
path!("namespace_annotations", key),
142142
value.to_owned(),
143-
)
143+
);
144144
}
145145
}
146146
}
@@ -152,6 +152,10 @@ mod tests {
152152

153153
use super::*;
154154

155+
#[allow(
156+
clippy::too_many_lines,
157+
reason = "Splitting this fixture is deferred to keep the lint cleanup mechanical. https://github.com/vectordotdev/vector/issues/23659"
158+
)]
155159
#[test]
156160
fn test_annotate_from_metadata() {
157161
let cases = vec![
@@ -541,7 +545,7 @@ mod tests {
541545
),
542546
];
543547

544-
for (fields_spec, metadata, expected, log_namespace) in cases.into_iter() {
548+
for (fields_spec, metadata, expected, log_namespace) in cases {
545549
let mut log = LogEvent::default();
546550
annotate_from_metadata(&mut log, &fields_spec, &metadata, log_namespace);
547551
assert_eq!(log, expected);

‎src/sources/kubernetes_logs/node_metadata_annotator.rs‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ fn annotate_from_metadata(
8484
if let Some(labels) = &metadata.labels {
8585
let legacy_key_prefix = fields_spec.node_labels.path.as_ref().map(|k| &k.path);
8686

87-
for (key, value) in labels.iter() {
87+
for (key, value) in labels {
8888
let key_path = path!(key);
8989
let legacy_key = legacy_key_prefix
9090
.map(|k| k.concat(key_path))
@@ -96,7 +96,7 @@ fn annotate_from_metadata(
9696
legacy_key,
9797
path!("node_labels", key),
9898
value.to_owned(),
99-
)
99+
);
100100
}
101101
}
102102
}
@@ -108,6 +108,10 @@ mod tests {
108108

109109
use super::*;
110110

111+
#[allow(
112+
clippy::too_many_lines,
113+
reason = "Splitting this fixture is deferred to keep the lint cleanup mechanical. https://github.com/vectordotdev/vector/issues/23659"
114+
)]
111115
#[test]
112116
fn test_annotate_from_metadata() {
113117
let cases = vec![
@@ -246,7 +250,7 @@ mod tests {
246250
),
247251
];
248252

249-
for (fields_spec, metadata, expected, log_namespace) in cases.into_iter() {
253+
for (fields_spec, metadata, expected, log_namespace) in cases {
250254
let mut log = LogEvent::default();
251255
annotate_from_metadata(&mut log, &fields_spec, &metadata, log_namespace);
252256
assert_eq!(log, expected);

0 commit comments

Comments
 (0)