From 2fc4e3df84cd06e90547b1f0339940937e502eeb Mon Sep 17 00:00:00 2001 From: Conrad Ludgate Date: Fri, 8 Mar 2024 19:47:46 +0000 Subject: [PATCH] update logging --- Cargo.lock | 1 - proxy/src/bin/pg_sni_router.rs | 2 +- proxy/src/context.rs | 13 +++++++++---- proxy/src/proxy.rs | 4 ++-- proxy/src/serverless.rs | 7 ++++--- workspace_hack/Cargo.toml | 3 +-- 6 files changed, 17 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bf75e71113..da87d78e71 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7155,7 +7155,6 @@ dependencies = [ "tower", "tracing", "tracing-core", - "tungstenite 0.20.1", "url", "uuid", "zeroize", diff --git a/proxy/src/bin/pg_sni_router.rs b/proxy/src/bin/pg_sni_router.rs index 385f7820cb..03a7503686 100644 --- a/proxy/src/bin/pg_sni_router.rs +++ b/proxy/src/bin/pg_sni_router.rs @@ -175,7 +175,7 @@ async fn task_main( .context("failed to set socket option")?; info!(%peer_addr, "serving"); - let ctx = RequestMonitoring::new(session_id, peer_addr.ip(), "sni_router", "sni"); + let ctx = RequestMonitoring::new(session_id, peer_addr, "sni_router", "sni"); handle_client(ctx, dest_suffix, tls_config, tls_server_end_point, socket).await } .unwrap_or_else(|e| { diff --git a/proxy/src/context.rs b/proxy/src/context.rs index 1b48e01358..8f126e2278 100644 --- a/proxy/src/context.rs +++ b/proxy/src/context.rs @@ -3,7 +3,7 @@ use chrono::Utc; use once_cell::sync::OnceCell; use smol_str::SmolStr; -use std::net::IpAddr; +use std::net::{IpAddr, SocketAddr}; use tokio::sync::mpsc; use tracing::{field::display, info_span, Span}; use uuid::Uuid; @@ -62,7 +62,7 @@ pub enum AuthMethod { impl RequestMonitoring { pub fn new( session_id: Uuid, - peer_addr: IpAddr, + peer_addr: SocketAddr, protocol: &'static str, region: &'static str, ) -> Self { @@ -75,7 +75,7 @@ impl RequestMonitoring { ); Self { - peer_addr, + peer_addr: peer_addr.ip(), session_id, protocol, first_packet: Utc::now(), @@ -100,7 +100,12 @@ impl RequestMonitoring { #[cfg(test)] pub fn test() -> Self { - RequestMonitoring::new(Uuid::now_v7(), [127, 0, 0, 1].into(), "test", "test") + RequestMonitoring::new( + Uuid::now_v7(), + ([127, 0, 0, 1], 5432).into(), + "test", + "test", + ) } pub fn console_application_name(&self) -> String { diff --git a/proxy/src/proxy.rs b/proxy/src/proxy.rs index 5b8d654149..abf73c5a1c 100644 --- a/proxy/src/proxy.rs +++ b/proxy/src/proxy.rs @@ -92,7 +92,7 @@ pub async fn task_main( connections.spawn(async move { let mut socket = WithClientIp::new(socket); let peer_addr = match socket.wait_for_addr().await { - Ok(Some(addr)) => addr.ip(), + Ok(Some(addr)) => addr, Err(e) => { error!("per-client task finished with an error: {e:#}"); return; @@ -101,7 +101,7 @@ pub async fn task_main( error!("missing required client IP"); return; } - Ok(None) => peer_addr.ip() + Ok(None) => peer_addr }; match socket.inner.set_nodelay(true) { diff --git a/proxy/src/serverless.rs b/proxy/src/serverless.rs index fada8c0701..4dbfc4b6a9 100644 --- a/proxy/src/serverless.rs +++ b/proxy/src/serverless.rs @@ -33,7 +33,7 @@ use crate::serverless::backend::PoolingBackend; use crate::{cancellation::CancellationHandler, config::ProxyConfig}; use std::convert::Infallible; -use std::net::IpAddr; +use std::net::SocketAddr; use std::pin::pin; use std::sync::Arc; use std::time::Duration; @@ -140,6 +140,7 @@ pub async fn task_main( if let Some(peer) = peer { peer_addr = peer; } + info!(%peer_addr, protocol = "http", "accepted new TCP connection"); let accept = tls.accept(conn); let conn = match timeout(Duration::from_secs(10), accept).await { @@ -177,7 +178,7 @@ pub async fn task_main( backend, ws_connections, cancellation_handler, - peer_addr.ip(), + peer_addr, endpoint_rate_limiter, ) .await @@ -281,7 +282,7 @@ async fn request_handler( backend: Arc, ws_connections: TaskTracker, cancellation_handler: Arc, - peer_addr: IpAddr, + peer_addr: SocketAddr, endpoint_rate_limiter: Arc, ) -> Result>, ApiError> { let session_id = uuid::Uuid::new_v4(); diff --git a/workspace_hack/Cargo.toml b/workspace_hack/Cargo.toml index 8593b752c2..aa7268e12c 100644 --- a/workspace_hack/Cargo.toml +++ b/workspace_hack/Cargo.toml @@ -64,7 +64,7 @@ rustls = { version = "0.21", features = ["dangerous_configuration"] } scopeguard = { version = "1" } serde = { version = "1", features = ["alloc", "derive"] } serde_json = { version = "1", features = ["raw_value"] } -smallvec = { version = "1", default-features = false, features = ["write"] } +smallvec = { version = "1", default-features = false, features = ["const_new", "write"] } subtle = { version = "2" } time = { version = "0.3", features = ["local-offset", "macros", "serde-well-known"] } tokio = { version = "1", features = ["fs", "io-std", "io-util", "macros", "net", "process", "rt-multi-thread", "signal", "test-util"] } @@ -76,7 +76,6 @@ tonic = { version = "0.9", features = ["tls-roots"] } tower = { version = "0.4", default-features = false, features = ["balance", "buffer", "limit", "log", "timeout", "util"] } tracing = { version = "0.1", features = ["log"] } tracing-core = { version = "0.1" } -tungstenite = { version = "0.20" } url = { version = "2", features = ["serde"] } uuid = { version = "1", features = ["serde", "v4", "v7"] } zeroize = { version = "1", features = ["derive"] }