feat: add debug-level per-op, session and link metrics
This commit is contained in:
parent
0ba9f32837
commit
07f064460f
5 changed files with 76 additions and 0 deletions
|
|
@ -103,6 +103,7 @@ fn handle_connection(
|
|||
) -> anyhow::Result<()> {
|
||||
stream.set_read_timeout(Some(Duration::from_secs(IDLE_TIMEOUT_SECS)))?;
|
||||
|
||||
let handshake_started = std::time::Instant::now();
|
||||
let (transport, handshake_hash) = match handshake(&mut stream, static_key) {
|
||||
Ok(v) => v,
|
||||
Err(e) => {
|
||||
|
|
@ -110,6 +111,17 @@ fn handle_connection(
|
|||
return Ok(());
|
||||
}
|
||||
};
|
||||
log::debug!(
|
||||
"handshake from {peer_ip} in {:?}",
|
||||
handshake_started.elapsed()
|
||||
);
|
||||
|
||||
// Drop logs the summary once, whatever return path closes the session.
|
||||
let summary = SessionSummary {
|
||||
peer_ip,
|
||||
started: std::time::Instant::now(),
|
||||
ops: std::cell::Cell::new(0),
|
||||
};
|
||||
|
||||
let store = Store::open(db_path)?;
|
||||
let server_static = derive_public(static_key);
|
||||
|
|
@ -129,6 +141,7 @@ fn handle_connection(
|
|||
return Ok(());
|
||||
}
|
||||
};
|
||||
summary.ops.set(summary.ops.get() + 1);
|
||||
|
||||
let (status, payload) = session.dispatch(op, &body);
|
||||
let mut response = Vec::with_capacity(1 + payload.len());
|
||||
|
|
@ -140,6 +153,23 @@ fn handle_connection(
|
|||
}
|
||||
}
|
||||
|
||||
struct SessionSummary<'a> {
|
||||
peer_ip: &'a str,
|
||||
started: std::time::Instant,
|
||||
ops: std::cell::Cell<u64>,
|
||||
}
|
||||
|
||||
impl Drop for SessionSummary<'_> {
|
||||
fn drop(&mut self) {
|
||||
log::debug!(
|
||||
"session {} closed: {} op(s) in {:?}",
|
||||
self.peer_ip,
|
||||
self.ops.get(),
|
||||
self.started.elapsed()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
fn is_eof_like(e: &anyhow::Error) -> bool {
|
||||
if let Some(io_err) = e.downcast_ref::<std::io::Error>() {
|
||||
return matches!(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue