From 73c1c9ea5be21d8028c7fd92117c13035c90b870 Mon Sep 17 00:00:00 2001 From: Christian Theilemann Date: Sun, 25 Sep 2022 18:20:13 +0200 Subject: [PATCH] observability: structured logging for faucet requests (#4529) --- crates/aptos-faucet/src/lib.rs | 42 ++++++++++++---------------------- 1 file changed, 14 insertions(+), 28 deletions(-) diff --git a/crates/aptos-faucet/src/lib.rs b/crates/aptos-faucet/src/lib.rs index 6142282a371c8..a5cae7f2354ba 100644 --- a/crates/aptos-faucet/src/lib.rs +++ b/crates/aptos-faucet/src/lib.rs @@ -34,7 +34,7 @@ use aptos_sdk::{ use clap::Parser; use futures::lock::Mutex; use reqwest::StatusCode; -use std::{convert::Infallible, fmt, path::PathBuf, sync::Arc}; +use std::{convert::Infallible, path::PathBuf, sync::Arc}; use url::Url; use warp::{http, Filter, Rejection, Reply}; @@ -195,21 +195,23 @@ pub fn routes( health .or(mint) .with(warp::log::custom(|info| { - let actual_ip = info + let forwarded_for = info .request_headers() .get("x-forwarded-for") .map(|inner| inner.to_str().unwrap_or("-")); + info!( - "{} \"{} {} {:?}\" {} \"{}\" \"{}\" \"{}\" {:?}", - OptFmt(info.remote_addr()), - info.method(), - info.path(), - info.version(), - info.status().as_u16(), - OptFmt(info.referer()), - OptFmt(info.user_agent()), - OptFmt(actual_ip), - info.elapsed(), + remote_addr = info.remote_addr(), + forwarded_for = forwarded_for, + host = info.host(), + method = format!("{}", info.method()), + path = info.path(), + version = format!("{:?}", info.version()), + status = format!("{}", info.status()), + referer = info.referer(), + user_agent = info.user_agent(), + elapsed = info.elapsed(), + "mint request" ) })) .with( @@ -242,22 +244,6 @@ async fn handle_health(service: Arc) -> Result, In } } -// -// Common Types -// - -struct OptFmt(Option); - -impl fmt::Display for OptFmt { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - if let Some(t) = &self.0 { - fmt::Display::fmt(t, f) - } else { - f.write_str("-") - } - } -} - /// The idea is that this may be happening concurrently. If we end up in such a race, the faucets /// might attempt to send transactions with the same sequence number, in such an event, one will /// succeed and the other will hit an unwrap. Eventually all faucets should get online.