Skip to content

Commit dcd3dae

Browse files
authored
chore: more logs in pbs module (#359)
1 parent 150f692 commit dcd3dae

File tree

3 files changed

+33
-4
lines changed

3 files changed

+33
-4
lines changed

crates/pbs/src/mev_boost/get_header.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ async fn send_one_get_header(
328328
RELAY_STATUS_CODE.with_label_values(&[code.as_str(), GET_HEADER_ENDPOINT_TAG, &relay.id]).inc();
329329

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

358359
debug!(
359360
relay_id = relay.id.as_ref(),
361+
header_size_bytes,
360362
latency = ?request_latency,
361363
version = get_header_response.version(),
362364
value_eth = format_ether(get_header_response.value()),

crates/pbs/src/routes/router.rs

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use axum::{
2+
body::HttpBody,
23
extract::{DefaultBodyLimit, MatchedPath, Request},
34
middleware::{self, Next},
45
response::Response,
@@ -10,7 +11,7 @@ use cb_common::pbs::{
1011
BUILDER_V1_API_PATH, BUILDER_V2_API_PATH, GET_HEADER_PATH, GET_STATUS_PATH,
1112
REGISTER_VALIDATOR_PATH, RELOAD_PATH, SUBMIT_BLOCK_PATH,
1213
};
13-
use tracing::trace;
14+
use tracing::{trace, warn};
1415
use uuid::Uuid;
1516

1617
use super::{
@@ -75,6 +76,8 @@ pub fn create_app_router<S: BuilderApiState, A: BuilderApi<S>>(state: PbsStateGu
7576
),
7677
)]
7778
pub async fn tracing_middleware(req: Request, next: Next) -> Response {
79+
let mut watcher = RequestWatcher::new();
80+
7881
trace!(
7982
http.method = %req.method(),
8083
http.user_agent = req.headers().typed_get::<UserAgent>().map(|ua| ua.to_string()).unwrap_or_default(),
@@ -84,8 +87,32 @@ pub async fn tracing_middleware(req: Request, next: Next) -> Response {
8487
let response = next.run(req).await;
8588

8689
let status = response.status();
90+
let response_size = response.body().size_hint().upper().unwrap_or(0);
8791

88-
trace!(http.response.status_code = ?status, "end request");
92+
trace!(http.response.status_code = ?status, response_size, "end request");
8993

94+
watcher.observe();
9095
response
9196
}
97+
98+
struct RequestWatcher {
99+
observed: bool,
100+
}
101+
102+
impl RequestWatcher {
103+
fn new() -> Self {
104+
Self { observed: false }
105+
}
106+
107+
fn observe(&mut self) {
108+
self.observed = true;
109+
}
110+
}
111+
112+
impl Drop for RequestWatcher {
113+
fn drop(&mut self) {
114+
if !self.observed {
115+
warn!("client timed out")
116+
}
117+
}
118+
}

crates/pbs/src/state.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ pub type PbsStateGuard<S> = Arc<RwLock<PbsState<S>>>;
1818
#[derive(Clone)]
1919
pub struct PbsState<S: BuilderApiState = ()> {
2020
/// Config data for the Pbs service
21-
pub config: PbsModuleConfig,
21+
pub config: Arc<PbsModuleConfig>,
2222
/// Opaque extra data for library use
2323
pub data: S,
2424
}
2525

2626
impl PbsState<()> {
2727
pub fn new(config: PbsModuleConfig) -> Self {
28-
Self { config, data: () }
28+
Self { config: Arc::new(config), data: () }
2929
}
3030

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

0 commit comments

Comments
 (0)