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
|
|
@ -44,6 +44,19 @@ impl From<rusqlite::Error> for HandlerError {
|
|||
|
||||
type OpResult = Result<(u8, Vec<u8>), HandlerError>;
|
||||
|
||||
/// Wire op byte to log name; unknown bytes are logged as dispatched too.
|
||||
fn op_name(op: u8) -> &'static str {
|
||||
match op {
|
||||
OP_AUTH => "AUTH",
|
||||
OP_RESOLVE => "RESOLVE",
|
||||
OP_SEND => "SEND",
|
||||
OP_FETCH => "FETCH",
|
||||
OP_DELETE => "DELETE",
|
||||
OP_REGISTER => "REGISTER",
|
||||
_ => "UNKNOWN",
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Session<'a> {
|
||||
config: &'a ServerConfig,
|
||||
store: Store,
|
||||
|
|
@ -72,7 +85,25 @@ impl<'a> Session<'a> {
|
|||
/// panicking or propagating errors to the caller: a bad frame or a
|
||||
/// storage error both become a response, and the caller decides
|
||||
/// separately whether to keep the connection open.
|
||||
///
|
||||
/// Timing lives in this wrapper because both carriers dispatch through
|
||||
/// it, so the metrics flag covers TCP and RNS from one place.
|
||||
pub fn dispatch(&mut self, op: u8, body: &[u8]) -> (u8, Vec<u8>) {
|
||||
let started = std::time::Instant::now();
|
||||
let (status, payload) = self.dispatch_op(op, body);
|
||||
log::debug!(
|
||||
"op {} from {} in {:?}: status {}, {}B request, {}B response",
|
||||
op_name(op),
|
||||
self.peer_ip,
|
||||
started.elapsed(),
|
||||
status,
|
||||
body.len(),
|
||||
payload.len()
|
||||
);
|
||||
(status, payload)
|
||||
}
|
||||
|
||||
fn dispatch_op(&mut self, op: u8, body: &[u8]) -> (u8, Vec<u8>) {
|
||||
if matches!(op, OP_FETCH | OP_DELETE) && self.username.is_none() {
|
||||
return (AUTH_REQUIRED, Vec::new());
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue