Skip to content

Commit

Permalink
chore: add health timeout for mmproxy
Browse files Browse the repository at this point in the history
  • Loading branch information
stringhandler committed Oct 18, 2024
1 parent 200b2c7 commit eb82ed3
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 35 deletions.
28 changes: 14 additions & 14 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ version = "0.5.37"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[build-dependencies]
tauri-build = {version = "1.5.5", features = ["isolation"]}
tauri-build = {version = "1.5.5", features = ["isolation"] }

[dependencies]
anyhow = "1"
async-trait = "0.1.81"
async_zip = {version = "0.0.17", features = ["full"]}
async_zip = {version = "0.0.17", features = ["full"] }
auto-launch = "0.5.0"
blake2 = "0.10"
chrono = "0.4.38"
Expand All @@ -29,26 +29,26 @@ keyring = {version = "3.0.5", features = [
"windows-native",
"apple-native",
"linux-native",
]}
] }
libsqlite3-sys = {version = "0.25.1", features = [
"bundled",
]}# Required for tari_wallet
] }# Required for tari_wallet
log = "0.4.22"
log4rs = "1.3.0"
minotari_node_grpc_client = {git = "https://github.com/tari-project/tari.git", branch = "development"}
minotari_wallet_grpc_client = {git = "https://github.com/tari-project/tari.git", branch = "development"}
nix = {version = "0.29.0", features = ["signal"]}
nix = {version = "0.29.0", features = ["signal"] }
nvml-wrapper = "0.10.0"
open = "5"
phraze = "0.3.15"
rand = "0.8.5"
regex = "1.10.5"
reqwest = {version = "0.12.5", features = ["stream", "json", "multipart"]}
reqwest = {version = "0.12.5", features = ["stream", "json", "multipart"] }
sanitize-filename = "0.5"
semver = "1.0.23"
sentry = {version = "0.34.0", features = ["anyhow"]}
sentry = {version = "0.34.0", features = ["anyhow"] }
sentry-tauri = "0.3.0"
serde = {version = "1", features = ["derive"]}
serde = {version = "1", features = ["derive"] }
serde_json = "1"
sha2 = "0.10.8"
sys-locale = "0.3.1"
Expand All @@ -58,7 +58,7 @@ tari_common = {git = "https://github.com/tari-project/tari.git", branch = "devel
tari_common_types = {git = "https://github.com/tari-project/tari.git", branch = "development"}
tari_core = {git = "https://github.com/tari-project/tari.git", branch = "development", features = [
"transactions",
]}
] }
tari_crypto = "0.20.3"
tari_key_manager = {git = "https://github.com/tari-project/tari.git", branch = "development"}
tari_shutdown = {git = "https://github.com/tari-project/tari.git", branch = "development"}
Expand All @@ -78,12 +78,12 @@ tauri = {version = "1.8.0", features = [
"isolation",
"shell-open",
"process-command-api",
]}
] }
tauri-plugin-single-instance = {git = "https://github.com/tauri-apps/plugins-workspace", branch = "v1"}
thiserror = "1.0.26"
tokio = {version = "1", features = ["full"]}
tokio-util = {version = "0.7.11", features = ["compat"]}
xz2 = {version = "0.1.7", features = ["static"]}# static bind lzma
tokio = {version = "1", features = ["full"] }
tokio-util = {version = "0.7.11", features = ["compat"] }
xz2 = {version = "0.1.7", features = ["static"] }# static bind lzma
zip = "2.2.0"

[target.'cfg(windows)'.dependencies]
Expand All @@ -92,7 +92,7 @@ winreg = "0.52.0"
# needed for keymanager. TODO: Find a way of creating a keymanager without bundling sqlite
chrono = "0.4.38"
device_query = "2.1.0"
libsqlite3-sys = {version = "0.25.1", features = ["bundled"]}
libsqlite3-sys = {version = "0.25.1", features = ["bundled"] }
log = "0.4.22"
nvml-wrapper = "0.10.0"
rand = "0.8.5"
Expand Down
38 changes: 20 additions & 18 deletions src-tauri/src/mm_proxy_adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ use crate::process_adapter::{
use crate::utils::file_utils::convert_to_string;
use anyhow::{anyhow, Error};
use async_trait::async_trait;
use log::warn;
// use log::warn;
use reqwest::Client;
use serde_json::json;
use tari_common_types::tari_address::TariAddress;
use tari_shutdown::Shutdown;

// const LOG_TARGET: &str = "tari::universe::mm_proxy_adapter";
const LOG_TARGET: &str = "tari::universe::mm_proxy_adapter";

#[derive(Clone, PartialEq, Default)]
pub(crate) struct MergeMiningProxyConfig {
Expand Down Expand Up @@ -142,6 +143,7 @@ impl ProcessAdapter for MergeMiningProxyAdapter {
},
MergeMiningProxyStatusMonitor {
json_rpc_port: config.port,
start_time: std::time::Instant::now(),
},
))
}
Expand All @@ -158,29 +160,29 @@ impl ProcessAdapter for MergeMiningProxyAdapter {
#[derive(Clone)]
pub struct MergeMiningProxyStatusMonitor {
json_rpc_port: u16,
// start_time: std::time::Instant,
start_time: std::time::Instant,
}

#[async_trait]
impl StatusMonitor for MergeMiningProxyStatusMonitor {
async fn check_health(&self) -> HealthStatus {
// TODO: Monero calls are really slow, so temporarily changing to Healthy
HealthStatus::Healthy
// if self
// .get_version()
// .await
// .inspect_err(|e| warn!(target: LOG_TARGET, "Failed to get block template during health check: {:?}", e))
// .is_ok()
// {
// HealthStatus::Healthy
// } else {
// if self.start_time.elapsed().as_secs() < 10 {
// return HealthStatus::Healthy;
// }
// // HealthStatus::Unhealthy
// // This can return a bad error from time to time, especially on startup
// HealthStatus::Warning
// }
// HealthStatus::Healthy
if self
.get_version()
.await
.inspect_err(|e| warn!(target: LOG_TARGET, "Failed to get block template during health check: {:?}", e))
.is_ok()
{
HealthStatus::Healthy
} else {
if self.start_time.elapsed().as_secs() <30 {
return HealthStatus::Healthy;
}
// HealthStatus::Unhealthy
// This can return a bad error from time to time, especially on startup
HealthStatus::Warning
}
}
}

Expand Down
4 changes: 3 additions & 1 deletion src-tauri/src/mm_proxy_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ impl Clone for MmProxyManager {
impl MmProxyManager {
pub fn new() -> Self {
let sidecar_adapter = MergeMiningProxyAdapter::new();
let process_watcher = ProcessWatcher::new(sidecar_adapter);
let mut process_watcher = ProcessWatcher::new(sidecar_adapter);
process_watcher.health_timeout = std::time::Duration::from_secs(28);
process_watcher.poll_time = std::time::Duration::from_secs(30);

Self {
watcher: Arc::new(RwLock::new(process_watcher)),
Expand Down
4 changes: 2 additions & 2 deletions src-tauri/src/process_watcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ pub struct ProcessWatcher<TAdapter: ProcessAdapter> {
pub(crate) adapter: TAdapter,
watcher_task: Option<JoinHandle<Result<i32, anyhow::Error>>>,
internal_shutdown: Shutdown,
poll_time: tokio::time::Duration,
health_timeout: tokio::time::Duration,
pub poll_time: tokio::time::Duration,
pub health_timeout: tokio::time::Duration,
pub(crate) status_monitor: Option<TAdapter::StatusMonitor>,
}

Expand Down

0 comments on commit eb82ed3

Please sign in to comment.