diff --git a/Cargo.lock b/Cargo.lock index 166104c..124bce8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -393,6 +393,41 @@ dependencies = [ "typenum", ] +[[package]] +name = "darling" +version = "0.20.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f63b86c8a8826a49b8c21f08a2d07338eec8d900540f8630dc76284be802989" +dependencies = [ + "darling_core", + "darling_macro", +] + +[[package]] +name = "darling_core" +version = "0.20.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95133861a8032aaea082871032f5815eb9e98cef03fa916ab4500513994df9e5" +dependencies = [ + "fnv", + "ident_case", + "proc-macro2", + "quote", + "strsim", + "syn", +] + +[[package]] +name = "darling_macro" +version = "0.20.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d336a2a514f6ccccaa3e09b02d41d35330c07ddf03a62165fcec10bb561c7806" +dependencies = [ + "darling_core", + "quote", + "syn", +] + [[package]] name = "der" version = "0.7.9" @@ -741,13 +776,19 @@ dependencies = [ "futures-sink", "futures-util", "http", - "indexmap", + "indexmap 2.3.0", "slab", "tokio", "tokio-util", "tracing", ] +[[package]] +name = "hashbrown" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" + [[package]] name = "hashbrown" version = "0.14.5" @@ -764,7 +805,7 @@ version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6ba4ff7128dee98c7dc9794b6a411377e1404dba1c97deb8d1a55297bd25d8af" dependencies = [ - "hashbrown", + "hashbrown 0.14.5", ] [[package]] @@ -928,6 +969,12 @@ dependencies = [ "cc", ] +[[package]] +name = "ident_case" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" + [[package]] name = "idna" version = "0.5.0" @@ -938,6 +985,17 @@ dependencies = [ "unicode-normalization", ] +[[package]] +name = "indexmap" +version = "1.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" +dependencies = [ + "autocfg", + "hashbrown 0.12.3", + "serde", +] + [[package]] name = "indexmap" version = "2.3.0" @@ -945,7 +1003,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "de3fc2e30ba82dd1b3911c8de1ffc143c74a914a14e99514d7637e3099df5ea0" dependencies = [ "equivalent", - "hashbrown", + "hashbrown 0.14.5", + "serde", ] [[package]] @@ -1561,6 +1620,7 @@ dependencies = [ "reqwest", "serde", "serde_json", + "serde_with", "sqlx", "tokio", "tokio-stream", @@ -1865,6 +1925,36 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_with" +version = "3.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69cecfa94848272156ea67b2b1a53f20fc7bc638c4a46d2f8abde08f05f4b857" +dependencies = [ + "base64 0.22.1", + "chrono", + "hex", + "indexmap 1.9.3", + "indexmap 2.3.0", + "serde", + "serde_derive", + "serde_json", + "serde_with_macros", + "time", +] + +[[package]] +name = "serde_with_macros" +version = "3.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8fee4991ef4f274617a51ad4af30519438dacb2f56ac773b08a1922ff743350" +dependencies = [ + "darling", + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "sha1" version = "0.10.6" @@ -2011,10 +2101,10 @@ dependencies = [ "futures-intrusive", "futures-io", "futures-util", - "hashbrown", + "hashbrown 0.14.5", "hashlink", "hex", - "indexmap", + "indexmap 2.3.0", "log", "memchr", "native-tls", @@ -2192,6 +2282,12 @@ dependencies = [ "unicode-properties", ] +[[package]] +name = "strsim" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" + [[package]] name = "subtle" version = "2.6.1" diff --git a/Cargo.toml b/Cargo.toml index c5bd3b4..e28039c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,6 +22,7 @@ redis = { version = "0.22.1", features = ["aio", "tokio-comp"] } reqwest = { version = "0.11", features = ["json", "gzip"] } serde = { version = "1", features = ["derive"] } serde_json = "1" +serde_with = "3.5.1" sqlx = { version = "0.8.0", features = [ "chrono", "postgres", diff --git a/src/phoenix/env.rs b/src/phoenix/env.rs index 67afa7c..4880e0b 100644 --- a/src/phoenix/env.rs +++ b/src/phoenix/env.rs @@ -1,9 +1,13 @@ +use std::{fmt, str}; + use lazy_static::lazy_static; use reqwest::Url; use serde::Deserialize; +use serde_with::{serde_as, DisplayFromStr}; use crate::env::{deserialize_network, deserialize_urls, get_app_config, Env, Network}; +#[serde_as] #[derive(Deserialize)] pub struct AppConfig { #[serde(default = "default_wait")] @@ -15,6 +19,8 @@ pub struct AppConfig { /// Skip global checks in `run_ops_monitors` and only check for beacon/sim node status. #[serde(default)] pub ff_node_check_only: bool, + #[serde_as(as = "DisplayFromStr")] + pub geo: Geo, pub loki_url: String, /// Minimum number of missed slots per check interval to trigger an alert #[serde(default = "default_missed_slots_alert_threshold")] @@ -79,6 +85,34 @@ fn default_missed_slots_alert_threshold() -> i64 { 3 } +/// Auction geography +#[allow(clippy::upper_case_acronyms)] +pub enum Geo { + RBX, + VIN, +} + +impl fmt::Display for Geo { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + let str = match &self { + Geo::RBX => "rbx", + Geo::VIN => "vin", + }; + write!(f, "{}", str) + } +} + +impl str::FromStr for Geo { + type Err = String; + fn from_str(s: &str) -> Result { + match s { + "rbx" => Ok(Geo::RBX), + "vin" => Ok(Geo::VIN), + _ => Err(format!("invalid auction geo: {}", s)), + } + } +} + lazy_static! { pub static ref APP_CONFIG: AppConfig = get_app_config(); } diff --git a/src/phoenix/mod.rs b/src/phoenix/mod.rs index 8beefd5..ebd410d 100644 --- a/src/phoenix/mod.rs +++ b/src/phoenix/mod.rs @@ -120,15 +120,19 @@ impl NodeAlarm { async fn fire_age_over_limit(&mut self, name: &str) { let message = format!( - "{} hasn't updated for more than {} seconds", + "{} hasn't updated for more than {} seconds on {}", name, PHOENIX_MAX_LIFESPAN.num_seconds(), + APP_CONFIG.geo ); self.alarm.fire(&message, &AlarmType::Opsgenie).await; } async fn fire_num_unsynced_nodes(&mut self, name: &str, num_unsynced_nodes: usize) { - let message = format!("{} has {} unsynced instances", name, num_unsynced_nodes); + let message = format!( + "{} has {} unsynced instances on {}", + name, num_unsynced_nodes, APP_CONFIG.geo + ); if num_unsynced_nodes >= APP_CONFIG.unsynced_nodes_threshold_og_alert { self.alarm.fire(&message, &AlarmType::Opsgenie).await;