Skip to content

Commit

Permalink
use binary SocketAddress in access logs
Browse files Browse the repository at this point in the history
use fixed32 for ipv4 addresses
  • Loading branch information
Keksoj committed Feb 5, 2024
1 parent 4d4a0fa commit 3e0e33f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
8 changes: 4 additions & 4 deletions command/src/access_logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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())
Expand Down
6 changes: 3 additions & 3 deletions command/src/command.proto
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ message SocketAddress {

message IpAddress {
oneof inner {
uint32 v4 = 1;
fixed32 v4 = 1;
Uint128 v6 = 2;
}
}
Expand All @@ -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;
Expand Down
8 changes: 7 additions & 1 deletion command/src/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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);
Expand Down

0 comments on commit 3e0e33f

Please sign in to comment.