diff --git a/Cargo.lock b/Cargo.lock index ccad487..917ec91 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -538,9 +538,7 @@ dependencies = [ "clap", "dashmap", "env_logger", - "futures", "hex", - "log", "primitive-types", "r2d2", "redis", @@ -548,6 +546,7 @@ dependencies = [ "serde", "serde_json", "sha1", + "tracing", ] [[package]] @@ -867,21 +866,6 @@ version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" -[[package]] -name = "futures" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23342abe12aba583913b2e62f22225ff9c950774065e4bfb61a19cd9770fec40" -dependencies = [ - "futures-channel", - "futures-core", - "futures-executor", - "futures-io", - "futures-sink", - "futures-task", - "futures-util", -] - [[package]] name = "futures-channel" version = "0.3.28" @@ -889,7 +873,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "955518d47e09b25bbebc7a18df10b81f0c766eaf4c4f1cccef2fca5f2a4fb5f2" dependencies = [ "futures-core", - "futures-sink", ] [[package]] @@ -898,17 +881,6 @@ version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4bca583b7e26f571124fe5b7561d49cb2868d79116cfa0eefce955557c6fee8c" -[[package]] -name = "futures-executor" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ccecee823288125bd88b4d7f565c9e58e41858e47ab72e8ea2d64e93624386e0" -dependencies = [ - "futures-core", - "futures-task", - "futures-util", -] - [[package]] name = "futures-io" version = "0.3.28" @@ -930,17 +902,6 @@ dependencies = [ "waker-fn", ] -[[package]] -name = "futures-macro" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.38", -] - [[package]] name = "futures-sink" version = "0.3.28" @@ -959,16 +920,10 @@ version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "26b01e40b772d54cf6c6d721c1d1abd0647a0106a12ecaa1c186273392a69533" dependencies = [ - "futures-channel", "futures-core", - "futures-io", - "futures-macro", - "futures-sink", "futures-task", - "memchr", "pin-project-lite", "pin-utils", - "slab", ] [[package]] @@ -1638,9 +1593,9 @@ dependencies = [ [[package]] name = "redis" -version = "0.23.3" +version = "0.24.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f49cdc0bb3f412bf8e7d1bd90fe1d9eb10bc5c399ba90973c14662a27b3f8ba" +checksum = "c580d9cbbe1d1b479e8d67cf9daf6a62c957e6846048408b80b43ac3f6af84cd" dependencies = [ "async-std", "combine", @@ -2186,21 +2141,32 @@ checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" [[package]] name = "tracing" -version = "0.1.37" +version = "0.1.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" dependencies = [ - "cfg-if", "log", "pin-project-lite", + "tracing-attributes", "tracing-core", ] +[[package]] +name = "tracing-attributes" +version = "0.1.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.38", +] + [[package]] name = "tracing-core" -version = "0.1.31" +version = "0.1.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0955b8137a1df6f1a2e9a37d8a6656291ff0297c1a97c24e0d8425fe2312f79a" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" dependencies = [ "once_cell", ] diff --git a/Cargo.toml b/Cargo.toml index 4c3e840..ee9646d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,12 +11,11 @@ anyhow = "1.0.71" clap = { version = "4.3.4", features = ["derive"] } dashmap = { version = "5.5.3", features = ["serde"] } env_logger = "0.10.0" -futures = "0.3.28" hex = "0.4.3" -log = "0.4.19" +tracing = "0.1.40" primitive-types = "0.12.1" r2d2 = "0.8.10" -redis = { version = "0.23.3", features = ["r2d2", "async-std"] } +redis = { version = "0.24.0", features = ["r2d2", "async-std"] } reqwest = { version = "0.11.18", features = ["rustls", "json", "serde_json"] } serde = { version = "1.0.164", features = ["derive"] } serde_json = { version = "1.0.97", features = ["std"] } diff --git a/src/main.rs b/src/main.rs index c84217f..49fee04 100644 --- a/src/main.rs +++ b/src/main.rs @@ -100,14 +100,13 @@ fn read_cache( }) } - #[actix_web::post("/{chain}")] async fn rpc_call( - path: web::Path<(String, )>, + path: web::Path<(String,)>, data: web::Data, body: web::Json, ) -> Result { - let (chain, ) = path.into_inner(); + let (chain,) = path.into_inner(); let chain_state = data .chains .get(&chain.to_uppercase()) @@ -124,7 +123,7 @@ async fn rpc_call( let mut ids_in_original_order = vec![]; let mut redis_con = data.redis.get().map_err(|err| { - log::error!("fail to get redis connection because: {}", err); + tracing::error!("fail to get redis connection because: {}", err); error::ErrorInternalServerError("fail to get redis connection") })?; @@ -151,23 +150,28 @@ async fn rpc_call( } }; - let result = read_cache(&mut redis_con, cache_entry.handler.as_ref(), &method, ¶ms); + let result = read_cache( + &mut redis_con, + cache_entry.handler.as_ref(), + &method, + ¶ms, + ); match result { Err(err) => { - log::error!("fail to read cache because: {}", err); + tracing::error!("fail to read cache because: {}", err); uncached_requests.insert(id, (method, params, None)); } Ok(CacheStatus::NotAvailable) => { - log::info!("cache not available for method {}", method); + tracing::info!("cache not available for method {}", method); uncached_requests.insert(id, (method, params, None)); } Ok(CacheStatus::Cached(cache_key, value)) => { - log::info!("cache hit for method {} with key {}", method, cache_key); + tracing::info!("cache hit for method {} with key {}", method, cache_key); request_result.insert(id, ResultOrError::Result(value)); } Ok(CacheStatus::Missed(cache_key)) => { - log::info!("cache missed for method {} with key {}", method, cache_key); + tracing::info!("cache missed for method {} with key {}", method, cache_key); uncached_requests.insert(id, (method, params, Some(cache_key))); } } @@ -193,16 +197,19 @@ async fn rpc_call( chain_state.rpc_url.clone(), &request_body, ) - .await - .map_err(|err| { - log::error!("fail to make rpc request because: {}", err); - error::ErrorInternalServerError(format!("fail to make rpc request because: {}", err)) - })?; + .await + .map_err(|err| { + tracing::error!("fail to make rpc request because: {}", err); + error::ErrorInternalServerError(format!("fail to make rpc request because: {}", err)) + })?; let result_values = match rpc_result { Value::Array(v) => v, _ => { - log::error!("array is expected but we got invalid rpc response: {},", rpc_result.to_string()); + tracing::error!( + "array is expected but we got invalid rpc response: {},", + rpc_result.to_string() + ); return Err(error::ErrorInternalServerError("invalid rpc response")); } }; @@ -284,10 +291,10 @@ async fn main() -> std::io::Result<()> { let handler_factories = rpc_cache_handler::all_factories(); - log::info!("Provisioning cache tables"); + tracing::info!("Provisioning cache tables"); for (name, rpc_url) in arg.endpoints.iter() { - log::info!("Adding endpoint {} linked to {}", name, rpc_url); + tracing::info!("Adding endpoint {} linked to {}", name, rpc_url); let mut chain_state = ChainState::new(rpc_url.clone()); @@ -303,7 +310,7 @@ async fn main() -> std::io::Result<()> { let app_state = web::Data::new(app_state); - log::info!("Server listening on {}:{}", arg.bind, arg.port); + tracing::info!("Server listening on {}:{}", arg.bind, arg.port); { let app_state = app_state.clone(); @@ -314,7 +321,7 @@ async fn main() -> std::io::Result<()> { .await?; } - log::info!("Server stopped"); + tracing::info!("Server stopped"); Ok(()) }