Skip to content

Commit

Permalink
Fixing some linter errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Luis Felipe Dominguez Vega committed Aug 6, 2020
1 parent e06928b commit 0bddb3b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 24 deletions.
9 changes: 2 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,9 @@ async fn main() {
let config_reader = global_config::SETTINGS.read().unwrap();

loop {
redis::get_redis_hosts(ping_thread_log.clone())
redis::get_redis_hosts(&ping_thread_log)
.map(|hosts| {
task::do_ping_task(
ping_thread_log.clone(),
&mut historical_hosts,
hosts,
hostname.clone(),
);
task::do_ping(&ping_thread_log, &mut historical_hosts, hosts, &hostname);
})
.unwrap_or_default();

Expand Down
2 changes: 1 addition & 1 deletion src/redis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ impl PartialEq for Host {
}
}

pub fn get_redis_hosts(ping_thread_log: Logger) -> Result<Vec<Host>, ()> {
pub fn get_redis_hosts(ping_thread_log: &Logger) -> Result<Vec<Host>, ()> {
let redis_host = crate::global_config::SETTINGS
.read()
.unwrap()
Expand Down
28 changes: 14 additions & 14 deletions src/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ use fastping_rs::Pinger;
use slog::Logger;
use std::collections::HashMap;

pub fn do_ping_task(
ping_thread_log: Logger,
pub fn do_ping(
ping_thread_log: &Logger,
historical_hosts: &mut HashMap<String, String>,
hosts: Vec<Host>,
hostname: String,
hostname: &str,
) {
let local_inet_address = crate::utils::ifaddrs(ping_thread_log.clone());
let local_inet_address = crate::utils::ifaddrs(ping_thread_log);

let config_reader = crate::global_config::SETTINGS.read().unwrap();

Expand Down Expand Up @@ -42,16 +42,16 @@ pub fn do_ping_task(

for deleted_host in deleted_hosts {
crate::prom::PING_LATENCY_HISTOGRAM
.remove_label_values(&[&deleted_host.0[..], &deleted_host.1[..], &hostname[..]])
.remove_label_values(&[&deleted_host.0[..], &deleted_host.1[..], hostname])
.unwrap_or_default();
crate::prom::PING_ERROR_COUNT
.remove_label_values(&[&deleted_host.0[..], &deleted_host.1[..], &hostname[..]])
.remove_label_values(&[&deleted_host.0[..], &deleted_host.1[..], hostname])
.unwrap_or_default();
crate::prom::PING_LAST
.remove_label_values(&[&deleted_host.0[..], &deleted_host.1[..], &hostname[..]])
.remove_label_values(&[&deleted_host.0[..], &deleted_host.1[..], hostname])
.unwrap_or_default();
crate::prom::HOST_UP
.remove_label_values(&[&deleted_host.0[..], &deleted_host.1[..], &hostname[..]])
.remove_label_values(&[&deleted_host.0[..], &deleted_host.1[..], hostname])
.unwrap_or_default();
}

Expand Down Expand Up @@ -99,21 +99,21 @@ pub fn do_ping_task(
.with_label_values(&[
&addr_str[..],
&historical_hosts[&addr_str][..],
&hostname[..],
hostname,
])
.inc();
crate::prom::PING_LAST
.remove_label_values(&[
&addr_str[..],
&historical_hosts[&addr_str][..],
&hostname[..],
hostname,
])
.unwrap_or_default();
crate::prom::HOST_UP
.with_label_values(&[
&addr_str[..],
&historical_hosts[&addr_str][..],
&hostname[..],
hostname,
])
.set(0.0);
warn!(ping_thread_log, "No response from host"; "host" => addr_str);
Expand All @@ -126,21 +126,21 @@ pub fn do_ping_task(
.with_label_values(&[
&addr_str[..],
&historical_hosts[&addr_str][..],
&hostname[..],
hostname,
])
.observe(millis as f64);
crate::prom::PING_LAST
.with_label_values(&[
&addr_str[..],
&historical_hosts[&addr_str][..],
&hostname[..],
hostname,
])
.set(millis as f64);
crate::prom::HOST_UP
.with_label_values(&[
&addr_str[..],
&historical_hosts[&addr_str][..],
&hostname[..],
hostname,
])
.set(1.0);

Expand Down
4 changes: 2 additions & 2 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use nix::sys::socket::SockAddr::Inet;
use nix::unistd::gethostname;
use slog::Logger;

pub fn ifaddrs(ping_thread_log: Logger) -> Vec<String> {
pub fn ifaddrs(ping_thread_log: &Logger) -> Vec<String> {
let mut local_inet_address = vec![];

for ifaddr in getifaddrs().unwrap() {
Expand All @@ -28,7 +28,7 @@ pub fn ifaddrs(ping_thread_log: Logger) -> Vec<String> {
}

pub fn host_name() -> String {
let mut buf = [0u8; 128];
let mut buf = [0_u8; 128];
let hostname_cstr = gethostname(&mut buf).expect("Failed getting hostname");
let hostname = hostname_cstr.to_str().expect("Hostname wasn't valid UTF-8");

Expand Down

0 comments on commit 0bddb3b

Please sign in to comment.