From 3e0e33fb658b696fad1b2f80db448c24bf899a50 Mon Sep 17 00:00:00 2001 From: Emmanuel Bosquet Date: Mon, 5 Feb 2024 11:50:49 +0100 Subject: [PATCH] use binary SocketAddress in access logs use fixed32 for ipv4 addresses --- command/src/access_logs.rs | 8 ++++---- command/src/command.proto | 6 +++--- command/src/logging.rs | 8 +++++++- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/command/src/access_logs.rs b/command/src/access_logs.rs index 1c4b62326..6541b99db 100644 --- a/command/src/access_logs.rs +++ b/command/src/access_logs.rs @@ -4,7 +4,7 @@ use rusty_ulid::Ulid; use time::Duration; use crate::proto::command::{ - BinaryAccessLog, BinaryEndpoint, HttpMethod, RequestUlid, TcpEndpoint, Uint128 + BinaryAccessLog, BinaryEndpoint, HttpMethod, RequestUlid, TcpEndpoint, Uint128, }; /// This uses unsafe to creates a "fake" owner of the underlying data. @@ -147,7 +147,7 @@ impl RequestRecord<'_> { let (first, second) = self.context.request_id.into(); let request_id = RequestUlid { first, second }; let time: Uint128 = time.into(); - + let endpoint = match self.endpoint { EndpointRecord::Http { method, @@ -182,7 +182,7 @@ impl RequestRecord<'_> { }; ManuallyDrop::new(BinaryAccessLog { - backend_address: self.backend_address.map(|a| a.to_string()), + backend_address: self.backend_address.map(Into::into), backend_id: self.context.backend_id.duplicate(), bytes_in: *self.bytes_in as u64, bytes_out: *self.bytes_out as u64, @@ -197,7 +197,7 @@ impl RequestRecord<'_> { response_time: self.response_time.whole_microseconds() as u64, server_rtt: self.server_rtt.map(|t| t.whole_microseconds() as u64), service_time: self.service_time.whole_microseconds() as u64, - session_address: self.session_address.map(|a| a.to_string()), + session_address: self.session_address.map(Into::into), tags: self .tags .map(|tags| tags.tags.duplicate()) diff --git a/command/src/command.proto b/command/src/command.proto index 62f547e08..69ed35e59 100644 --- a/command/src/command.proto +++ b/command/src/command.proto @@ -619,7 +619,7 @@ message SocketAddress { message IpAddress { oneof inner { - uint32 v4 = 1; + fixed32 v4 = 1; Uint128 v6 = 2; } } @@ -639,9 +639,9 @@ message BinaryAccessLog { required RequestUlid request_id = 2; optional string cluster_id = 3; optional string backend_id = 4; - optional string session_address = 5; + optional SocketAddress session_address = 5; // socket address of the backend server - optional string backend_address = 6; + optional SocketAddress backend_address = 6; // the protocol, with SSL/TLS version, for instance "HTTPS-TLS1.1" required string protocol = 7; required BinaryEndpoint endpoint = 8; diff --git a/command/src/logging.rs b/command/src/logging.rs index deee0541e..1b6787e9b 100644 --- a/command/src/logging.rs +++ b/command/src/logging.rs @@ -184,7 +184,11 @@ impl InnerLogger { Err(IoError::new(IoErrorKind::InvalidData, e)) } else { // TODO: delete or make it trace - println!("binary log length: {}, {:02X?}", &self.buffer.len(), &self.buffer[..]); + println!( + "binary log length: {}, {:02X?}", + &self.buffer.len(), + &self.buffer[..] + ); let bytes = &self.buffer; match backend { LoggerBackend::Stdout(stdout) => { @@ -201,6 +205,8 @@ impl InnerLogger { } AccessLogFormat::Ascii => bind_format_args! { let args = ("{now} {precise_time} {pid} {tag} {level_tag} {log}"); + // TODO: delete or make it trace + println!("ascii access log length: {}", format!("{}", args).len()); match backend { LoggerBackend::Stdout(stdout) => { let _ = stdout.write_fmt(args);