From 1f6a7c174a15df2a7f51baae690df758a6d222a5 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Tue, 28 Apr 2020 12:30:54 -0700 Subject: [PATCH] Report duration of last alarm in the All Clear message (#9766) (#9771) automerge (cherry picked from commit 6e42989309a8f1cfcc68b4dedb2b8b795ca4dca7) Co-authored-by: Michael Vines --- Cargo.lock | 1 + watchtower/Cargo.toml | 1 + watchtower/src/main.rs | 20 +++++++++++++++++--- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8618b1e127..3df5e01780 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4786,6 +4786,7 @@ name = "solana-watchtower" version = "1.1.8" dependencies = [ "clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)", + "humantime 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "reqwest 0.10.4 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.48 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/watchtower/Cargo.toml b/watchtower/Cargo.toml index 2c1b9c617e..1120fccfa4 100644 --- a/watchtower/Cargo.toml +++ b/watchtower/Cargo.toml @@ -11,6 +11,7 @@ homepage = "https://solana.com/" [dependencies] clap = "2.33.0" log = "0.4.8" +humantime = "2.0.0" reqwest = { version = "0.10.4", default-features = false, features = ["blocking", "rustls-tls", "json"] } serde_json = "1.0" solana-clap-utils = { path = "../clap-utils", version = "1.1.8" } diff --git a/watchtower/src/main.rs b/watchtower/src/main.rs index bc96edfbf2..ef7be6c1b8 100644 --- a/watchtower/src/main.rs +++ b/watchtower/src/main.rs @@ -14,7 +14,12 @@ use solana_client::{ }; use solana_metrics::{datapoint_error, datapoint_info}; use solana_sdk::{hash::Hash, native_token::lamports_to_sol, pubkey::Pubkey}; -use std::{error, str::FromStr, thread::sleep, time::Duration}; +use std::{ + error, + str::FromStr, + thread::sleep, + time::{Duration, Instant}, +}; struct Config { interval: Duration, @@ -136,6 +141,7 @@ fn main() -> Result<(), Box> { let mut last_transaction_count = 0; let mut last_recent_blockhash = Hash::default(); let mut last_notification_msg = "".into(); + let mut last_success = Instant::now(); loop { let failure = match get_cluster_info(&rpc_client) { @@ -269,10 +275,18 @@ fn main() -> Result<(), Box> { last_notification_msg = notification_msg; } else { if !last_notification_msg.is_empty() { - info!("All clear"); - notifier.send("solana-watchtower: All clear"); + let alarm_duration = Instant::now().duration_since(last_success); + let alarm_duration = Duration::from_secs(alarm_duration.as_secs()); // Drop milliseconds in message + + let all_clear_msg = format!( + "All clear after {}", + humantime::format_duration(alarm_duration) + ); + info!("{}", all_clear_msg); + notifier.send(&format!("solana-watchtower: {}", all_clear_msg)); } last_notification_msg = "".into(); + last_success = Instant::now(); } sleep(config.interval); }