Healthcheck getting new topology every run

This commit is contained in:
Jedrzej Stuczynski
2020-01-09 15:07:23 +00:00
parent ca2faf0095
commit 1e0d84fb8b
4 changed files with 42 additions and 9 deletions
Generated
+11
View File
@@ -882,6 +882,14 @@ dependencies = [
"libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "itertools"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"either 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "itoa"
version = "0.4.4"
@@ -1222,6 +1230,7 @@ version = "0.1.0"
dependencies = [
"built 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
"clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)",
"directory-client 0.1.0",
"dotenv 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)",
"futures 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -2119,6 +2128,7 @@ dependencies = [
"addressing 0.1.0",
"base64 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
"curve25519-dalek 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
"itertools 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -2432,6 +2442,7 @@ dependencies = [
"checksum indexmap 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712d7b3ea5827fcb9d4fda14bf4da5f136f0db2ae9c8f4bd4e2d1c6fde4e6db2"
"checksum input_buffer 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8e1b822cc844905551931d6f81608ed5f50a79c1078a4e2b4d42dbc7c1eedfbf"
"checksum iovec 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "b2b3ea6ff95e175473f8ffe6a7eb7c00d054240321b84c57051175fe3c1e075e"
"checksum itertools 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f56a2d0bc861f9165be4eb3442afd3c236d8a98afd426f65d92324ae1091a484"
"checksum itoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "501266b7edd0174f8530248f87f99c88fbe60ca4ef3dd486835b8d8d53136f7f"
"checksum jobserver 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)" = "230ae9adf468173aecd4176c7233bddc84a15871a586c5971ace9a55f881c075"
"checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d"
+4
View File
@@ -19,6 +19,10 @@ serde_derive = "1.0.104"
tokio = { version = "0.2", features = ["full"] }
toml = "0.5.5"
## internal
directory-client = { path = "../clients/directory-client" }
[build-dependencies]
built = "0.3.2"
+25 -8
View File
@@ -1,28 +1,45 @@
use crate::validator::config;
use directory_client::requests::presence_topology_get::PresenceTopologyGetRequester;
use directory_client::DirectoryClient;
use log::{debug, trace};
use std::time::Duration;
#[derive(Debug)]
pub enum HealthCheckerError {
FailedToObtainTopologyError,
}
pub(crate) struct HealthChecker {
directory_server: String,
directory_client: directory_client::Client,
interval: Duration,
}
impl HealthChecker {
pub fn new(config: config::HealthCheck) -> Self {
debug!(
"healthcheck will be using the following directory server: {:?}",
config.directory_server
);
let directory_client_config = directory_client::Config::new(config.directory_server);
HealthChecker {
directory_server: config.directory_server,
directory_client: directory_client::Client::new(directory_client_config),
interval: Duration::from_secs_f64(config.interval),
}
}
pub async fn run(self) {
debug!(
"healthcheck run. will use directory at: {:?} and run every {:?}",
self.directory_server, self.interval,
);
pub async fn run(self) -> Result<(), HealthCheckerError> {
debug!("healthcheck will run every {:?}", self.interval,);
loop {
tokio::time::delay_for(self.interval).await;
trace!("going to perform a healthcheck!");
let current_topology = match self.directory_client.presence_topology.get() {
Ok(topology) => topology,
Err(_) => return Err(HealthCheckerError::FailedToObtainTopologyError),
};
trace!("current topology: {:?}", current_topology);
tokio::time::delay_for(self.interval).await;
}
}
}
+2 -1
View File
@@ -26,6 +26,7 @@ impl Validator {
let health_check_future = self.heath_check.run();
rt.block_on(health_check_future);
let health_check_res = rt.block_on(health_check_future);
assert!(health_check_res.is_ok()); // if it got here it means healthchecker failed anyway
}
}