Skip to content

Commit

Permalink
style: clippy and fmt with new rules
Browse files Browse the repository at this point in the history
  • Loading branch information
bpetit committed Jan 30, 2023
1 parent 63e8a4b commit 7feb260
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 25 deletions.
12 changes: 6 additions & 6 deletions src/exporters/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ impl fmt::Display for MetricValueType {
match &self {
// MetricValueType::IntSigned(value) => write!(f, "{}", value),
// MetricValueType::Float(value) => write!(f, "{}", value),
MetricValueType::Text(text) => write!(f, "{}", text),
MetricValueType::FloatDouble(value) => write!(f, "{}", value),
MetricValueType::IntUnsigned(value) => write!(f, "{}", value),
MetricValueType::Text(text) => write!(f, "{text}"),
MetricValueType::FloatDouble(value) => write!(f, "{value}"),
MetricValueType::IntUnsigned(value) => write!(f, "{value}"),
}
}
}
Expand All @@ -85,9 +85,9 @@ impl fmt::Debug for MetricValueType {
match &self {
// MetricValueType::IntSigned(value) => write!(f, "{}", value),
// MetricValueType::Float(value) => write!(f, "{}", value),
MetricValueType::Text(text) => write!(f, "{}", text),
MetricValueType::FloatDouble(value) => write!(f, "{}", value),
MetricValueType::IntUnsigned(value) => write!(f, "{}", value),
MetricValueType::Text(text) => write!(f, "{text}"),
MetricValueType::FloatDouble(value) => write!(f, "{value}"),
MetricValueType::IntUnsigned(value) => write!(f, "{value}"),
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/exporters/prometheus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ fn format_metric(key: &str, value: &str, labels: Option<&HashMap<String, String>
result.remove(result.len() - 1);
result.push('}');
}
let _ = writeln!(result, " {}", value);
let _ = writeln!(result, " {value}");
result
}

Expand All @@ -214,8 +214,8 @@ fn push_metric(
add_help: bool,
) -> String {
if add_help {
let _ = write!(body, "# HELP {} {}", metric_name, help);
let _ = write!(body, "\n# TYPE {} {}\n", metric_name, metric_type);
let _ = write!(body, "# HELP {metric_name} {help}");
let _ = write!(body, "\n# TYPE {metric_name} {metric_type}\n");
}
body.push_str(&metric_line);
body
Expand Down Expand Up @@ -288,7 +288,7 @@ async fn show_metrics(
);
}
} else {
let _ = write!(body, "<a href=\"https://github.com/hubblo-org/scaphandre/\">Scaphandre's</a> prometheus exporter here. Metrics available on <a href=\"/{}\">/{}</a>", suffix, suffix);
let _ = write!(body, "<a href=\"https://github.com/hubblo-org/scaphandre/\">Scaphandre's</a> prometheus exporter here. Metrics available on <a href=\"/{suffix}\">/{suffix}</a>");
}
Ok(Response::new(body.into()))
}
Expand Down
4 changes: 2 additions & 2 deletions src/exporters/qemu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl QemuExporter {
);
let time_pdiff = last.total_time_jiffies() - previous.total_time_jiffies();
if let Some(time_tdiff) = &topo_stat_diff {
let first_domain_path = format!("{}/{}/intel-rapl:0:0", path, vm_name);
let first_domain_path = format!("{path}/{vm_name}/intel-rapl:0:0");
if fs::read_dir(&first_domain_path).is_err() {
match fs::create_dir_all(&first_domain_path) {
Ok(_) => info!("Created {} folder.", &path),
Expand All @@ -86,7 +86,7 @@ impl QemuExporter {
trace!("Ratio is {}", ratio.to_string());
let uj_to_add = ratio * topo_rec_uj.value.parse::<u64>().unwrap();
trace!("Adding {} uJ", uj_to_add);
let complete_path = format!("{}/{}/intel-rapl:0", path, vm_name);
let complete_path = format!("{path}/{vm_name}/intel-rapl:0");
if let Ok(result) = QemuExporter::add_or_create(&complete_path, uj_to_add) {
trace!("{:?}", result);
debug!("Updated {}", complete_path);
Expand Down
2 changes: 1 addition & 1 deletion src/exporters/riemann.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ impl Exporter for RiemannExporter {
Utc::now().format("%Y-%m-%dT%H:%M:%S")
);
println!("Press CTRL-C to stop scaphandre");
println!("Measurement step is: {}s", dispatch_duration);
println!("Measurement step is: {dispatch_duration}s");

let topology = self.sensor.get_topology().unwrap();
let mut metric_generator = MetricGenerator::new(
Expand Down
10 changes: 5 additions & 5 deletions src/exporters/stdout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ impl StdoutExporter {
parameters.is_present("containers"),
);

println!("Measurement step is: {}s", step_duration);
println!("Measurement step is: {step_duration}s");
if timeout_secs == 0 {
loop {
self.iterate(&regex_filter, process_number, &mut metric_generator);
Expand Down Expand Up @@ -179,7 +179,7 @@ impl StdoutExporter {

println!(
"Host:\t{} W",
(format!("{}", host_power).parse::<f64>().unwrap() / 1000000.0)
(format!("{host_power}").parse::<f64>().unwrap() / 1000000.0)
);

if domain_names.is_some() {
Expand All @@ -197,7 +197,7 @@ impl StdoutExporter {
}
let socket_id = s.attributes.get("socket_id").unwrap().clone();

let mut to_print = format!("Socket{}\t{} W |\t", socket_id, power_str);
let mut to_print = format!("Socket{socket_id}\t{power_str} W |\t");

let domains = metrics.iter().filter(|x| {
x.name == "scaph_domain_power_microwatts"
Expand Down Expand Up @@ -232,7 +232,7 @@ impl StdoutExporter {
to_print.push_str("---");
}
}
println!("{}\n", to_print);
println!("{to_print}\n");
}
}

Expand All @@ -244,7 +244,7 @@ impl StdoutExporter {
.proc_tracker
.get_filtered_processes(regex_filter);
} else {
println!("Top {} consumers:", process_number);
println!("Top {process_number} consumers:");
consumers = metric_generator
.topology
.proc_tracker
Expand Down
4 changes: 2 additions & 2 deletions src/exporters/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub fn get_scaphandre_version() -> String {
let major_version = version_parts.next().unwrap();
let patch_version = version_parts.next().unwrap();
let minor_version = version_parts.next().unwrap();
format!("{}.{}{}", major_version, patch_version, minor_version)
format!("{major_version}.{patch_version}{minor_version}")
}

/// Returns the hostname of the system running Scaphandre.
Expand Down Expand Up @@ -116,7 +116,7 @@ pub fn get_kubernetes_client() -> Result<Kubernetes, KubernetesError> {
) {
Ok(kubernetes) => Ok(kubernetes),
Err(err) => {
eprintln!("Got Kubernetes error: {} | {:?}", err, err);
eprintln!("Got Kubernetes error: {err} | {err:?}");
Err(err)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/exporters/warpten.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ impl Warp10Exporter {
//read_token: Option<&str>,
qemu: bool,
) -> Result<Vec<warp10::Warp10Response>, warp10::Error> {
let client = warp10::Client::new(&format!("{}://{}:{}", scheme, host, port))?;
let client = warp10::Client::new(&format!("{scheme}://{host}:{port}"))?;
let writer = client.get_writer(write_token.to_string());
self.topology
.proc_tracker
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ fn current_system_time_since_epoch() -> Duration {
}

pub fn scaphandre_header(exporter_name: &str) {
let title = format!("Scaphandre {} exporter", exporter_name);
let title = format!("Scaphandre {exporter_name} exporter");
println!("{}", title.red().bold());
println!("Sending ⚡ metrics");
}
Expand Down
2 changes: 1 addition & 1 deletion src/sensors/powercap_rapl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ impl Sensor for PowercapRAPLSensor {
self.base_path, socket_id, domain_id
),
);
if let Ok(domain_name) = &fs::read_to_string(format!("{}/name", folder_name)) {
if let Ok(domain_name) = &fs::read_to_string(format!("{folder_name}/name")) {
topo.safe_add_domain_to_socket(
socket_id,
domain_id,
Expand Down
2 changes: 1 addition & 1 deletion src/sensors/units.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl fmt::Display for Unit {
impl Eq for Unit {}
impl PartialEq for Unit {
fn eq(&self, other: &Self) -> bool {
format!("{:?}", self) == format!("{:?}", other)
format!("{self:?}") == format!("{other:?}")
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/sensors/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ impl ProcessTracker {
key = key.replace(e, "_");
}
description.insert(
format!("container_label_{}", key),
format!("container_label_{key}"),
v.to_string(),
);
}
Expand Down

0 comments on commit 7feb260

Please sign in to comment.