From c0afc295ca62dd1b908bd618654c3acd49d92f66 Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Wed, 22 Mar 2023 15:18:54 -0700 Subject: [PATCH] add hostname to status --- Cargo.lock | 1 + web3_proxy/Cargo.toml | 1 + web3_proxy/src/app/mod.rs | 5 +++++ web3_proxy/src/frontend/status.rs | 2 ++ 4 files changed, 9 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 47350e46..8bd8065e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5814,6 +5814,7 @@ dependencies = [ "handlebars", "hashbrown 0.13.2", "hdrhistogram", + "hostname", "http", "ipnet", "itertools", diff --git a/web3_proxy/Cargo.toml b/web3_proxy/Cargo.toml index 5e0d54bc..a3135764 100644 --- a/web3_proxy/Cargo.toml +++ b/web3_proxy/Cargo.toml @@ -45,6 +45,7 @@ handlebars = "4.3.6" hashbrown = { version = "0.13.2", features = ["serde"] } hdrhistogram = "7.5.2" http = "0.2.9" +hostname = "0.3.1" ipnet = "2.7.1" itertools = "0.10.5" log = "0.4.17" diff --git a/web3_proxy/src/app/mod.rs b/web3_proxy/src/app/mod.rs index aa4677e7..d945fa2c 100644 --- a/web3_proxy/src/app/mod.rs +++ b/web3_proxy/src/app/mod.rs @@ -44,6 +44,7 @@ use redis_rate_limiter::{redis, DeadpoolRuntime, RedisConfig, RedisPool, RedisRa use serde::Serialize; use serde_json::json; use serde_json::value::to_raw_value; +use std::ffi::OsString; use std::fmt; use std::hash::{Hash, Hasher}; use std::net::IpAddr; @@ -213,6 +214,7 @@ pub struct Web3ProxyApp { pub config: AppConfig, pub db_conn: Option, pub db_replica: Option, + pub hostname: Option, /// store pending transactions that we've seen so that we don't send duplicates to subscribers pub pending_transactions: Cache, pub frontend_ip_rate_limiter: Option>, @@ -694,6 +696,8 @@ impl Web3ProxyApp { Some(private_rpcs) }; + let hostname = hostname::get().ok(); + let app = Self { config: top_config.app.clone(), balanced_rpcs, @@ -709,6 +713,7 @@ impl Web3ProxyApp { login_rate_limiter, db_conn, db_replica, + hostname, vredis_pool, rpc_secret_key_cache, bearer_token_semaphores, diff --git a/web3_proxy/src/frontend/status.rs b/web3_proxy/src/frontend/status.rs index 53cf5824..f678e34f 100644 --- a/web3_proxy/src/frontend/status.rs +++ b/web3_proxy/src/frontend/status.rs @@ -40,11 +40,13 @@ pub async fn status( let body = response_cache .get_with(FrontendResponseCaches::Status, async { // TODO: what else should we include? uptime, cache hit rates, cpu load, memory used + // TODO: the hostname is probably not going to change. only get once at the start? let body = json!({ "version": APP_USER_AGENT, "chain_id": app.config.chain_id, "balanced_rpcs": app.balanced_rpcs, "private_rpcs": app.private_rpcs, + "hostname": app.hostname, }); Arc::new(body)