From 315ece38aedc804a68622cf97e248a60f0cd4983 Mon Sep 17 00:00:00 2001 From: Jedrzej Stuczynski Date: Tue, 14 Jan 2020 10:44:05 +0000 Subject: [PATCH] Temporarily moved healthcheck from validator to separate common crate --- Cargo.lock | 30 +++++++++++++------ Cargo.toml | 1 + common/healthcheck/Cargo.toml | 29 ++++++++++++++++++ common/healthcheck/src/config.rs | 15 ++++++++++ .../mod.rs => common/healthcheck/src/lib.rs | 8 ++--- .../healthcheck/src}/path_check.rs | 0 .../healthcheck/src}/result.rs | 4 +-- .../healthcheck/src}/score.rs | 0 validator/Cargo.toml | 12 +------- validator/src/validator/config/mod.rs | 16 +--------- validator/src/validator/mod.rs | 3 +- 11 files changed, 75 insertions(+), 43 deletions(-) create mode 100644 common/healthcheck/Cargo.toml create mode 100644 common/healthcheck/src/config.rs rename validator/src/validator/health_check/mod.rs => common/healthcheck/src/lib.rs (94%) rename {validator/src/validator/health_check => common/healthcheck/src}/path_check.rs (100%) rename {validator/src/validator/health_check => common/healthcheck/src}/result.rs (96%) rename {validator/src/validator/health_check => common/healthcheck/src}/score.rs (100%) diff --git a/Cargo.lock b/Cargo.lock index 69d63816a2..69893a1555 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -845,6 +845,26 @@ dependencies = [ "tokio-io", ] +[[package]] +name = "healthcheck" +version = "0.1.0" +dependencies = [ + "addressing", + "crypto", + "directory-client", + "futures 0.3.1", + "itertools", + "log", + "mix-client", + "provider-client", + "serde", + "serde_derive", + "sfw-provider-requests", + "sphinx", + "tokio 0.2.9", + "topology", +] + [[package]] name = "hermit-abi" version = "0.1.6" @@ -1390,25 +1410,17 @@ dependencies = [ name = "nym-validator" version = "0.1.0" dependencies = [ - "addressing", "built", "clap", - "crypto", - "directory-client", "dotenv", "futures 0.3.1", - "itertools", + "healthcheck", "log", - "mix-client", "pretty_env_logger", - "provider-client", "serde", "serde_derive", - "sfw-provider-requests", - "sphinx", "tokio 0.2.9", "toml", - "topology", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 8e1687fdc5..d03d085fa8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,6 +7,7 @@ members = [ "common/clients/validator-client", "common/addressing", "common/crypto", + "common/healthcheck", "common/topology", "mixnode", "nym-client", diff --git a/common/healthcheck/Cargo.toml b/common/healthcheck/Cargo.toml new file mode 100644 index 0000000000..eb82f95fd5 --- /dev/null +++ b/common/healthcheck/Cargo.toml @@ -0,0 +1,29 @@ +[package] +name = "healthcheck" +version = "0.1.0" +authors = ["Jedrzej Stuczynski "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +futures = "0.3.1" +itertools = "0.8.2" +log = "0.4.8" +serde = "1.0.104" +serde_derive = "1.0.104" +tokio = { version = "0.2", features = ["full"] } + +## internal +addressing = {path = "../addressing" } +crypto = { path = "../crypto" } +directory-client = { path = "../clients/directory-client" } +mix-client = { path = "../clients/mix-client" } +provider-client = { path = "../clients/provider-client" } +sfw-provider-requests = { path = "../../sfw-provider/sfw-provider-requests" } +topology = {path = "../topology" } + +## will be moved to proper dependencies once released +sphinx = { git = "https://github.com/nymtech/sphinx", rev="1d8cefcb6a0cb8e87d00d89eb1ccf2839e92aa1f" } + +[dev-dependencies] diff --git a/common/healthcheck/src/config.rs b/common/healthcheck/src/config.rs new file mode 100644 index 0000000000..a33fe18ab2 --- /dev/null +++ b/common/healthcheck/src/config.rs @@ -0,0 +1,15 @@ +use serde_derive::Deserialize; + +#[derive(Deserialize, Debug)] +pub struct HealthCheck { + #[serde(rename(deserialize = "directory-server"))] + pub directory_server: String, + + pub interval: f64, // in seconds + + #[serde(rename(deserialize = "resolution-timeout"))] + pub resolution_timeout: f64, // in seconds + + #[serde(rename(deserialize = "test-packets-per-node"))] + pub num_test_packets: usize, +} diff --git a/validator/src/validator/health_check/mod.rs b/common/healthcheck/src/lib.rs similarity index 94% rename from validator/src/validator/health_check/mod.rs rename to common/healthcheck/src/lib.rs index 1fe0eded43..15efcba3b5 100644 --- a/validator/src/validator/health_check/mod.rs +++ b/common/healthcheck/src/lib.rs @@ -1,11 +1,11 @@ -use crate::validator::config; -use crate::validator::health_check::result::HealthCheckResult; +use crate::result::HealthCheckResult; use directory_client::requests::presence_topology_get::PresenceTopologyGetRequester; use directory_client::DirectoryClient; use log::{debug, error, info, trace}; use std::time::Duration; use topology::NymTopologyError; +pub mod config; mod path_check; mod result; mod score; @@ -23,7 +23,7 @@ impl From for HealthCheckerError { } } -pub(crate) struct HealthChecker { +pub struct HealthChecker { directory_client: directory_client::Client, interval: Duration, num_test_packets: usize, @@ -61,7 +61,7 @@ impl HealthChecker { self.num_test_packets, self.resolution_timeout, ) - .await; + .await; healthcheck_result.sort_scores(); Ok(healthcheck_result) } diff --git a/validator/src/validator/health_check/path_check.rs b/common/healthcheck/src/path_check.rs similarity index 100% rename from validator/src/validator/health_check/path_check.rs rename to common/healthcheck/src/path_check.rs diff --git a/validator/src/validator/health_check/result.rs b/common/healthcheck/src/result.rs similarity index 96% rename from validator/src/validator/health_check/result.rs rename to common/healthcheck/src/result.rs index 95ff1e83cb..b38f291b5e 100644 --- a/validator/src/validator/health_check/result.rs +++ b/common/healthcheck/src/result.rs @@ -1,5 +1,5 @@ -use crate::validator::health_check::path_check::{PathChecker, PathStatus}; -use crate::validator::health_check::score::NodeScore; +use crate::path_check::{PathChecker, PathStatus}; +use crate::score::NodeScore; use crypto::identity::{DummyMixIdentityKeyPair, MixnetIdentityKeyPair}; use log::{debug, info, warn}; use std::collections::HashMap; diff --git a/validator/src/validator/health_check/score.rs b/common/healthcheck/src/score.rs similarity index 100% rename from validator/src/validator/health_check/score.rs rename to common/healthcheck/src/score.rs diff --git a/validator/Cargo.toml b/validator/Cargo.toml index d0f9cdb325..2b97dcb8f5 100644 --- a/validator/Cargo.toml +++ b/validator/Cargo.toml @@ -12,7 +12,6 @@ clap = "2.33.0" # Read notes https://crates.io/crates/dotenv - tl;dr: don't use in production, set environmental variables properly. dotenv = "0.15.0" futures = "0.3.1" -itertools = "0.8.2" log = "0.4.8" pretty_env_logger = "0.3.1" serde = "1.0.104" @@ -21,16 +20,7 @@ tokio = { version = "0.2", features = ["full"] } toml = "0.5.5" ## internal -addressing = {path = "../common/addressing" } -crypto = { path = "../common/crypto" } -directory-client = { path = "../common/clients/directory-client" } -mix-client = { path = "../common/clients/mix-client" } -provider-client = { path = "../common/clients/provider-client" } -sfw-provider-requests = { path = "../sfw-provider/sfw-provider-requests" } -topology = {path = "../common/topology" } - -## will be moved to proper dependencies once released -sphinx = { git = "https://github.com/nymtech/sphinx", rev="1d8cefcb6a0cb8e87d00d89eb1ccf2839e92aa1f" } +healthcheck = {path = "../common/healthcheck" } [build-dependencies] built = "0.3.2" diff --git a/validator/src/validator/config/mod.rs b/validator/src/validator/config/mod.rs index 420bc90692..4ef70b9c7e 100644 --- a/validator/src/validator/config/mod.rs +++ b/validator/src/validator/config/mod.rs @@ -3,19 +3,5 @@ use serde_derive::Deserialize; #[derive(Deserialize, Debug)] pub struct Config { #[serde(rename(deserialize = "healthcheck"))] - pub health_check: HealthCheck, -} - -#[derive(Deserialize, Debug)] -pub struct HealthCheck { - #[serde(rename(deserialize = "directory-server"))] - pub directory_server: String, - - pub interval: f64, // in seconds - - #[serde(rename(deserialize = "resolution-timeout"))] - pub resolution_timeout: f64, // in seconds - - #[serde(rename(deserialize = "test-packets-per-node"))] - pub num_test_packets: usize, + pub health_check: healthcheck::config::HealthCheck, } diff --git a/validator/src/validator/mod.rs b/validator/src/validator/mod.rs index 1521cf2290..608b7dd852 100644 --- a/validator/src/validator/mod.rs +++ b/validator/src/validator/mod.rs @@ -1,10 +1,9 @@ use crate::validator::config::Config; -use crate::validator::health_check::HealthChecker; +use healthcheck::HealthChecker; use log::debug; use tokio::runtime::Runtime; pub mod config; -mod health_check; pub struct Validator { heath_check: HealthChecker,