Skip to content

Commit

Permalink
fix: Fix clippy warnings
Browse files Browse the repository at this point in the history
- Remove all clippy warnings using Rust release 1.61.
  • Loading branch information
uggla committed Jun 9, 2022
1 parent 8273ced commit 2daaa30
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 45 deletions.
2 changes: 1 addition & 1 deletion src/exporters/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ impl MetricGenerator {
attributes.insert("exe".to_string(), exe.clone());

if let Some(cmdline_str) = cmdline {
attributes.insert("cmdline".to_string(), cmdline_str.replace("\"", "\\\""));
attributes.insert("cmdline".to_string(), cmdline_str.replace('"', "\\\""));

if self.qemu {
if let Some(vmname) = utils::filter_qemu_cmdline(&cmdline_str) {
Expand Down
2 changes: 1 addition & 1 deletion src/exporters/prometheus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ fn format_metric(key: &str, value: &str, labels: Option<&HashMap<String, String>
if let Some(labels) = labels {
result.push('{');
for (k, v) in labels.iter() {
result.push_str(&format!("{}=\"{}\",", k, v.replace("\"", "_")));
result.push_str(&format!("{}=\"{}\",", k, v.replace('"', "_")));
}
result.remove(result.len() - 1);
result.push('}');
Expand Down
21 changes: 9 additions & 12 deletions src/exporters/riemann.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,16 @@ impl RiemannClient {
.unwrap()
.parse::<u16>()
.expect("Fail parsing port number");
let client: Client;
if parameters.is_present("mtls") {
let client: Client = if parameters.is_present("mtls") {
let cafile = parameters.value_of("cafile").unwrap();
let certfile = parameters.value_of("certfile").unwrap();
let keyfile = parameters.value_of("keyfile").unwrap();
client = Client::connect_tls(&address, port, cafile, certfile, keyfile)
.expect("Fail to connect to Riemann server using mTLS");
Client::connect_tls(&address, port, cafile, certfile, keyfile)
.expect("Fail to connect to Riemann server using mTLS")
} else {
client = Client::connect(&(address, port))
.expect("Fail to connect to Riemann server using raw TCP");
}
Client::connect(&(address, port))
.expect("Fail to connect to Riemann server using raw TCP")
};
RiemannClient { client }
}

Expand Down Expand Up @@ -88,7 +87,7 @@ impl RiemannClient {
i64::try_from(value).expect("Metric cannot be converted to signed integer."),
),
MetricValueType::Text(ref value) => {
let value = value.replace(",", ".").replace("\n", "");
let value = value.replace(',', ".").replace('\n', "");
if value.contains('.') {
event.set_metric_d(value.parse::<f64>().expect("Cannot parse metric value."));
} else {
Expand Down Expand Up @@ -184,7 +183,7 @@ impl Exporter for RiemannExporter {
attributes.insert("exe".to_string(), exe.clone());

if let Some(cmdline_str) = cmdline {
attributes.insert("cmdline".to_string(), cmdline_str.replace("\"", "\\\""));
attributes.insert("cmdline".to_string(), cmdline_str.replace('"', "\\\""));

if parameters.is_present("qemu") {
if let Some(vmname) = utils::filter_qemu_cmdline(&cmdline_str) {
Expand All @@ -197,9 +196,7 @@ impl Exporter for RiemannExporter {
// to differentiate services/metrics
let metric_name = format!(
"{}_{}_{}",
"scaph_process_power_consumption_microwatts",
pid.to_string(),
exe
"scaph_process_power_consumption_microwatts", pid, exe
);
if let Some(power) = metric_generator
.topology
Expand Down
39 changes: 19 additions & 20 deletions src/exporters/stdout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,16 @@ impl StdoutExporter {
.parse()
.expect("Wrong process_number value, should be a number");

let regex_filter: Option<Regex>;
if !parameters.is_present("regex_filter")
let regex_filter: Option<Regex> = if !parameters.is_present("regex_filter")
|| parameters.value_of("regex_filter").unwrap().is_empty()
{
regex_filter = None;
None
} else {
regex_filter = Some(
Some(
Regex::new(parameters.value_of("regex_filter").unwrap())
.expect("Wrong regex_filter, regexp is invalid"),
);
}
)
};

if parameters.occurrences_of("regex_filter") == 1
&& parameters.occurrences_of("process_number") == 1
Expand Down Expand Up @@ -229,20 +228,20 @@ impl StdoutExporter {
println!("{}\n", to_print);
}

let consumers: Vec<(procfs::process::Process, u64)>;
if let Some(regex_filter) = regex_filter {
println!("Processes filtered by '{}':", regex_filter.as_str());
consumers = metric_generator
.topology
.proc_tracker
.get_filtered_processes(regex_filter);
} else {
println!("Top {} consumers:", process_number);
consumers = metric_generator
.topology
.proc_tracker
.get_top_consumers(process_number);
}
let consumers: Vec<(procfs::process::Process, u64)> =
if let Some(regex_filter) = regex_filter {
println!("Processes filtered by '{}':", regex_filter.as_str());
metric_generator
.topology
.proc_tracker
.get_filtered_processes(regex_filter)
} else {
println!("Top {} consumers:", process_number);
metric_generator
.topology
.proc_tracker
.get_top_consumers(process_number)
};

info!("consumers : {:?}", consumers);
println!("Power\t\tPID\tExe");
Expand Down
17 changes: 7 additions & 10 deletions src/exporters/warpten.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,16 @@ impl Exporter for Warp10Exporter {
let host = parameters.value_of("host").unwrap();
let scheme = parameters.value_of("scheme").unwrap();
let port = parameters.value_of("port").unwrap();
let write_token;
if let Some(token) = parameters.value_of("write-token") {
write_token = token.to_owned();
let write_token = if let Some(token) = parameters.value_of("write-token") {
token.to_owned()
} else {
write_token = match env::var("SCAPH_WARP10_WRITE_TOKEN") {
match env::var("SCAPH_WARP10_WRITE_TOKEN") {
Ok(val) => val,
Err(_e) => panic!(
"SCAPH_WARP10_WRITE_TOKEN not found in env, nor write-token flag was used."
),
};
}
}
};
//let read_token = parameters.value_of("read-token");
let step = parameters.value_of("step").unwrap();
let qemu = parameters.is_present("qemu");
Expand Down Expand Up @@ -343,14 +342,12 @@ impl Warp10Exporter {
}
plabels.push(warp10::Label::new(
"cmdline",
&cmdline_str.replace("\"", "\\\""),
&cmdline_str.replace('"', "\\\""),
));
}
let metric_name = format!(
"{}_{}_{}",
"scaph_process_power_consumption_microwats",
pid.to_string(),
exe
"scaph_process_power_consumption_microwats", pid, exe
);
if let Some(power) = self.topology.get_process_power_consumption_microwatts(pid) {
process_data.push(warp10::Data::new(
Expand Down
2 changes: 1 addition & 1 deletion src/sensors/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ impl ProcessTracker {
if let Some(container) = containers.iter().find(|x| x.Id == container_id) {
let mut names = String::from("");
for n in &container.Names {
names.push_str(&n.trim().replace("/", ""));
names.push_str(&n.trim().replace('/', ""));
}
description.insert(String::from("container_names"), names);
description.insert(
Expand Down

0 comments on commit 2daaa30

Please sign in to comment.