Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions crates/pbs/src/mev_boost/get_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ async fn send_one_get_header(
RELAY_STATUS_CODE.with_label_values(&[code.as_str(), GET_HEADER_ENDPOINT_TAG, &relay.id]).inc();

let response_bytes = read_chunked_body_with_max(res, MAX_SIZE_GET_HEADER_RESPONSE).await?;
let header_size_bytes = response_bytes.len();
if !code.is_success() {
return Err(PbsError::RelayResponse {
error_msg: String::from_utf8_lossy(&response_bytes).into_owned(),
Expand Down Expand Up @@ -357,6 +358,7 @@ async fn send_one_get_header(

debug!(
relay_id = relay.id.as_ref(),
header_size_bytes,
latency = ?request_latency,
version = get_header_response.version(),
value_eth = format_ether(get_header_response.value()),
Expand Down
31 changes: 29 additions & 2 deletions crates/pbs/src/routes/router.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use axum::{
body::HttpBody,
extract::{DefaultBodyLimit, MatchedPath, Request},
middleware::{self, Next},
response::Response,
Expand All @@ -10,7 +11,7 @@ use cb_common::pbs::{
BUILDER_V1_API_PATH, BUILDER_V2_API_PATH, GET_HEADER_PATH, GET_STATUS_PATH,
REGISTER_VALIDATOR_PATH, RELOAD_PATH, SUBMIT_BLOCK_PATH,
};
use tracing::trace;
use tracing::{trace, warn};
use uuid::Uuid;

use super::{
Expand Down Expand Up @@ -75,6 +76,8 @@ pub fn create_app_router<S: BuilderApiState, A: BuilderApi<S>>(state: PbsStateGu
),
)]
pub async fn tracing_middleware(req: Request, next: Next) -> Response {
let mut watcher = RequestWatcher::new();

trace!(
http.method = %req.method(),
http.user_agent = req.headers().typed_get::<UserAgent>().map(|ua| ua.to_string()).unwrap_or_default(),
Expand All @@ -84,8 +87,32 @@ pub async fn tracing_middleware(req: Request, next: Next) -> Response {
let response = next.run(req).await;

let status = response.status();
let response_size = response.body().size_hint().upper().unwrap_or(0);

trace!(http.response.status_code = ?status, "end request");
trace!(http.response.status_code = ?status, response_size, "end request");

watcher.observe();
response
}

struct RequestWatcher {
observed: bool,
}

impl RequestWatcher {
fn new() -> Self {
Self { observed: false }
}

fn observe(&mut self) {
self.observed = true;
}
}

impl Drop for RequestWatcher {
fn drop(&mut self) {
if !self.observed {
warn!("client timed out")
}
}
}
4 changes: 2 additions & 2 deletions crates/pbs/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ pub type PbsStateGuard<S> = Arc<RwLock<PbsState<S>>>;
#[derive(Clone)]
pub struct PbsState<S: BuilderApiState = ()> {
/// Config data for the Pbs service
pub config: PbsModuleConfig,
pub config: Arc<PbsModuleConfig>,
/// Opaque extra data for library use
pub data: S,
}

impl PbsState<()> {
pub fn new(config: PbsModuleConfig) -> Self {
Self { config, data: () }
Self { config: Arc::new(config), data: () }
}

pub fn with_data<S: BuilderApiState>(self, data: S) -> PbsState<S> {
Expand Down
Loading