Skip to content

Commit

Permalink
Proceeded a rustfmt-nightly pass on code
Browse files Browse the repository at this point in the history
Signed-off-by: Valerian Saliou <valerian@valeriansaliou.name>
  • Loading branch information
valeriansaliou committed Feb 19, 2019
1 parent 07384c9 commit 16ff136
Show file tree
Hide file tree
Showing 21 changed files with 158 additions and 189 deletions.
45 changes: 17 additions & 28 deletions src/aggregator/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
// Copyright: 2018, Valerian Saliou <valerian@valeriansaliou.name>
// License: Mozilla Public License v2.0 (MPL v2.0)

use std::thread;
use std::time::{SystemTime, Duration};
use std::iter::FromIterator;
use std::thread;
use std::time::{Duration, SystemTime};
use time;

use crate::prober::status::Status;
use crate::prober::mode::Mode;
use crate::prober::manager::STORE as PROBER_STORE;
use crate::notifier::generic::Notification;
use crate::prober::manager::STORE as PROBER_STORE;
use crate::prober::mode::Mode;
use crate::prober::status::Status;
use crate::APP_CONF;

#[cfg(feature = "notifier-email")]
Expand Down Expand Up @@ -72,15 +72,13 @@ fn scan_and_bump_states() -> Option<BumpedStates> {
if let Ok(duration_since_report) =
SystemTime::now().duration_since(replica_report.time)
{
if duration_since_report >=
(replica_report.interval +
Duration::from_secs(APP_CONF.metrics.push_delay_dead))
if duration_since_report
>= (replica_report.interval
+ Duration::from_secs(APP_CONF.metrics.push_delay_dead))
{
debug!(
"replica: {}:{}:{} is dead because it didnt report in a while",
probe_id,
node_id,
replica_id
probe_id, node_id, replica_id
);

replica_status = Status::Dead;
Expand All @@ -91,14 +89,12 @@ fn scan_and_bump_states() -> Option<BumpedStates> {
// Compare system load indices and compute a new status?
if replica_status == Status::Healthy {
if let Some(ref replica_load) = replica.load {
if (replica_load.cpu > APP_CONF.metrics.push_system_cpu_sick_above) ||
(replica_load.ram > APP_CONF.metrics.push_system_ram_sick_above)
if (replica_load.cpu > APP_CONF.metrics.push_system_cpu_sick_above)
|| (replica_load.ram > APP_CONF.metrics.push_system_ram_sick_above)
{
debug!(
"replica: {}:{}:{} is sick because it is overloaded",
probe_id,
node_id,
replica_id
probe_id, node_id, replica_id
);

replica_status = Status::Sick;
Expand All @@ -125,10 +121,7 @@ fn scan_and_bump_states() -> Option<BumpedStates> {

debug!(
"aggregated status for replica: {}:{}:{} => {:?}",
probe_id,
node_id,
replica_id,
replica_status
probe_id, node_id, replica_id, replica_status
);

// Append bumped replica path?
Expand All @@ -146,9 +139,7 @@ fn scan_and_bump_states() -> Option<BumpedStates> {

debug!(
"aggregated status for node: {}:{} => {:?}",
probe_id,
node_id,
node_status
probe_id, node_id, node_status
);

node.status = node_status;
Expand All @@ -161,8 +152,7 @@ fn scan_and_bump_states() -> Option<BumpedStates> {

debug!(
"aggregated status for probe: {} => {:?}",
probe_id,
probe_status
probe_id, probe_status
);

probe.status = probe_status;
Expand All @@ -177,9 +167,8 @@ fn scan_and_bump_states() -> Option<BumpedStates> {
// - sick >> dead
// - dead >> sick
// - dead >> healthy
let mut should_notify = (store.states.status != Status::Dead &&
general_status == Status::Dead) ||
(store.states.status == Status::Dead && general_status != Status::Dead);
let mut should_notify = (store.states.status != Status::Dead && general_status == Status::Dead)
|| (store.states.status == Status::Dead && general_status != Status::Dead);

// Check if should re-notify? (in case status did not change; only if dead)
// Notice: this is used to send periodic reminders of downtime (ie. 'still down' messages)
Expand Down
2 changes: 1 addition & 1 deletion src/config/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// License: Mozilla Public License v2.0 (MPL v2.0)

use log;
use log::{Record, Level, Metadata, LevelFilter, SetLoggerError};
use log::{Level, LevelFilter, Metadata, Record, SetLoggerError};

pub struct ConfigLogger;

Expand Down
2 changes: 1 addition & 1 deletion src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

mod defaults;

pub mod logger;
pub mod config;
pub mod logger;
pub mod reader;
pub mod regex;
5 changes: 2 additions & 3 deletions src/config/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ impl ConfigReader {
let mut file = File::open(&APP_ARGS.config).expect("cannot find config file");
let mut conf = String::new();

file.read_to_string(&mut conf).expect(
"cannot read config file",
);
file.read_to_string(&mut conf)
.expect("cannot read config file");

debug!("read config file: {}", &APP_ARGS.config);

Expand Down
8 changes: 4 additions & 4 deletions src/config/regex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use std::fmt;
use std::ops::Deref;

use regex;
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use serde::de::{Error, Visitor};
use serde::{Deserialize, Deserializer, Serialize, Serializer};

#[derive(Clone, Debug)]
pub struct Regex(regex::Regex);
Expand Down Expand Up @@ -37,9 +37,9 @@ impl<'de> Deserialize<'de> for Regex {
}

fn visit_str<E: Error>(self, value: &str) -> Result<Regex, E> {
regex::Regex::new(value).map(Regex).map_err(|err| {
E::custom(err.to_string())
})
regex::Regex::new(value)
.map(Regex)
.map_err(|err| E::custom(err.to_string()))
}
}

Expand Down
38 changes: 20 additions & 18 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@ extern crate lazy_static;
extern crate serde_derive;
#[macro_use]
extern crate rocket;
extern crate time;
extern crate toml;
extern crate base64;
extern crate url;
extern crate serde;
extern crate url_serde;
extern crate indexmap;
extern crate rocket_contrib;
extern crate regex;
extern crate native_tls;
extern crate openssl_probe;
extern crate regex;
extern crate reqwest;
extern crate rocket_contrib;
extern crate serde;
extern crate time;
extern crate toml;
extern crate url;
extern crate url_serde;

#[cfg(feature = "notifier-email")]
extern crate lettre;
Expand All @@ -37,25 +37,25 @@ extern crate lettre_email;
#[cfg(feature = "notifier-xmpp")]
extern crate libstrophe;

mod config;
mod aggregator;
mod config;
mod notifier;
mod prober;
mod responder;
mod notifier;

use std::thread;
use std::ops::Deref;
use std::str::FromStr;
use std::thread;
use std::time::Duration;

use clap::{App, Arg};
use log::LevelFilter;

use crate::aggregator::manager::run as run_aggregator;
use crate::config::config::Config;
use crate::config::logger::ConfigLogger;
use crate::config::reader::ConfigReader;
use crate::prober::manager::{run as run_prober, initialize_store as initialize_store_prober};
use crate::aggregator::manager::run as run_aggregator;
use crate::prober::manager::{initialize_store as initialize_store_prober, run as run_prober};
use crate::responder::manager::run as run_responder;

struct AppArgs {
Expand All @@ -67,7 +67,7 @@ pub static THREAD_NAME_AGGREGATOR: &'static str = "vigil-aggregator";
pub static THREAD_NAME_RESPONDER: &'static str = "vigil-responder";

macro_rules! gen_spawn_managed {
($name:expr, $method:ident, $thread_name:ident, $managed_fn:ident) => (
($name:expr, $method:ident, $thread_name:ident, $managed_fn:ident) => {
fn $method() {
debug!("spawn managed thread: {}", $name);

Expand All @@ -92,7 +92,7 @@ macro_rules! gen_spawn_managed {
$method();
}
}
)
};
}

lazy_static! {
Expand Down Expand Up @@ -130,7 +130,9 @@ fn make_app_args() -> AppArgs {
.get_matches();

// Generate owned app arguments
AppArgs { config: String::from(matches.value_of("config").expect("invalid config value")) }
AppArgs {
config: String::from(matches.value_of("config").expect("invalid config value")),
}
}

fn ensure_states() {
Expand All @@ -151,9 +153,9 @@ fn main() {
openssl_probe::init_ssl_cert_env_vars();

// Initialize shared logger
let _logger = ConfigLogger::init(LevelFilter::from_str(&APP_CONF.server.log_level).expect(
"invalid log level",
));
let _logger = ConfigLogger::init(
LevelFilter::from_str(&APP_CONF.server.log_level).expect("invalid log level"),
);

info!("starting up");

Expand Down
25 changes: 12 additions & 13 deletions src/notifier/email.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@

use std::time::Duration;

use native_tls::TlsConnector;
use lettre::smtp::{ClientSecurity, SmtpTransportBuilder, SmtpTransport, ConnectionReuseParameters};
use lettre::smtp::authentication::Credentials;
use lettre::smtp::client::net::ClientTlsParameters;
use lettre::smtp::{
ClientSecurity, ConnectionReuseParameters, SmtpTransport, SmtpTransportBuilder,
};
use lettre::EmailTransport;
use lettre_email::EmailBuilder;
use native_tls::TlsConnector;

use super::generic::{DISPATCH_TIMEOUT_SECONDS, Notification, GenericNotifier};
use super::generic::{GenericNotifier, Notification, DISPATCH_TIMEOUT_SECONDS};
use crate::config::config::ConfigNotify;
use crate::APP_CONF;

Expand Down Expand Up @@ -47,9 +49,7 @@ impl GenericNotifier for EmailNotifier {

message.push_str("\n--\n");
message.push_str("\n");
message.push_str(
"To unsubscribe, please edit your status page configuration.",
);
message.push_str("To unsubscribe, please edit your status page configuration.");

debug!("will send email notification with message: {}", &message);

Expand All @@ -76,9 +76,10 @@ impl GenericNotifier for EmailNotifier {
email_config.smtp_username.to_owned(),
email_config.smtp_password.to_owned(),
email_config.smtp_encrypt,
).map(|mut transport| transport.send(&email_message))
.and(Ok(()))
.or(Err(true));
)
.map(|mut transport| transport.send(&email_message))
.and(Ok(()))
.or(Err(true));
}

Err(false)
Expand Down Expand Up @@ -129,10 +130,8 @@ fn acquire_transport(

match (smtp_username, smtp_password) {
(Some(smtp_username_value), Some(smtp_password_value)) => {
transport_builder = transport_builder.credentials(Credentials::new(
smtp_username_value,
smtp_password_value,
));
transport_builder = transport_builder
.credentials(Credentials::new(smtp_username_value, smtp_password_value));
}
_ => {}
}
Expand Down
2 changes: 1 addition & 1 deletion src/notifier/generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
use std::thread;
use std::time::Duration;

use crate::prober::status::Status;
use crate::config::config::ConfigNotify;
use crate::prober::status::Status;

const DISPATCH_TRY_WAIT_SECONDS: u64 = 2;
const DISPATCH_TRY_ATTEMPT_TIMES: u8 = 3;
Expand Down
4 changes: 2 additions & 2 deletions src/notifier/slack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ use std::time::Duration;

use reqwest::Client;

use super::generic::{DISPATCH_TIMEOUT_SECONDS, Notification, GenericNotifier};
use crate::prober::status::Status;
use super::generic::{GenericNotifier, Notification, DISPATCH_TIMEOUT_SECONDS};
use crate::config::config::ConfigNotify;
use crate::prober::status::Status;
use crate::APP_CONF;

lazy_static! {
Expand Down
4 changes: 2 additions & 2 deletions src/notifier/twilio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
// Copyright: 2018, Valerian Saliou <valerian@valeriansaliou.name>
// License: Mozilla Public License v2.0 (MPL v2.0)

use std::time::Duration;
use std::collections::HashMap;
use std::time::Duration;

use reqwest::Client;

use super::generic::{DISPATCH_TIMEOUT_SECONDS, Notification, GenericNotifier};
use super::generic::{GenericNotifier, Notification, DISPATCH_TIMEOUT_SECONDS};
use crate::config::config::ConfigNotify;
use crate::APP_CONF;

Expand Down
Loading

0 comments on commit 16ff136

Please sign in to comment.