Skip to content

Commit

Permalink
observability: structured logging for faucet requests (#4529)
Browse files Browse the repository at this point in the history
  • Loading branch information
geekflyer authored Sep 25, 2022
1 parent 5314b72 commit 73c1c9e
Showing 1 changed file with 14 additions and 28 deletions.
42 changes: 14 additions & 28 deletions crates/aptos-faucet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -242,22 +244,6 @@ async fn handle_health(service: Arc<Service>) -> Result<Box<dyn warp::Reply>, In
}
}

//
// Common Types
//

struct OptFmt<T>(Option<T>);

impl<T: fmt::Display> fmt::Display for OptFmt<T> {
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.
Expand Down

0 comments on commit 73c1c9e

Please sign in to comment.