From 4ab7665c304deb721500c032991c1179ad9e372c Mon Sep 17 00:00:00 2001 From: Adil Hafeez Date: Thu, 23 Jan 2025 14:22:16 -0800 Subject: [PATCH] log improvements --- crates/common/src/routing.rs | 3 -- crates/llm_gateway/src/filter_context.rs | 5 ---- crates/llm_gateway/src/stream_context.rs | 31 +++++++-------------- crates/prompt_gateway/src/context.rs | 6 ++-- crates/prompt_gateway/src/filter_context.rs | 6 ---- crates/prompt_gateway/src/http_context.rs | 7 ----- 6 files changed, 12 insertions(+), 46 deletions(-) diff --git a/crates/common/src/routing.rs b/crates/common/src/routing.rs index 1a440ee9..f4baf896 100644 --- a/crates/common/src/routing.rs +++ b/crates/common/src/routing.rs @@ -2,7 +2,6 @@ use std::rc::Rc; use crate::{configuration, llm_providers::LlmProviders}; use configuration::LlmProvider; -use log::debug; use rand::{seq::IteratorRandom, thread_rng}; #[derive(Debug)] @@ -35,11 +34,9 @@ pub fn get_llm_provider( } if llm_providers.default().is_some() { - debug!("no llm provider found for hint, using default llm provider"); return llm_providers.default().unwrap(); } - debug!("no default llm found, using random llm provider"); let mut rng = thread_rng(); llm_providers .iter() diff --git a/crates/llm_gateway/src/filter_context.rs b/crates/llm_gateway/src/filter_context.rs index 16580063..4e44a9ff 100644 --- a/crates/llm_gateway/src/filter_context.rs +++ b/crates/llm_gateway/src/filter_context.rs @@ -79,11 +79,6 @@ impl RootContext for FilterContext { } fn create_http_context(&self, context_id: u32) -> Option> { - debug!( - "||| create_http_context called with context_id: {:?} |||", - context_id - ); - Some(Box::new(StreamContext::new( context_id, Rc::clone(&self.metrics), diff --git a/crates/llm_gateway/src/stream_context.rs b/crates/llm_gateway/src/stream_context.rs index 6939f1d8..b512147d 100644 --- a/crates/llm_gateway/src/stream_context.rs +++ b/crates/llm_gateway/src/stream_context.rs @@ -10,7 +10,6 @@ use common::consts::{ }; use common::errors::ServerError; use common::llm_providers::LlmProviders; -use common::pii::obfuscate_auth_header; use common::ratelimit::Header; use common::stats::{IncrementingMetric, RecordingMetric}; use common::tracing::{Event, Span, TraceData, Traceparent}; @@ -82,12 +81,16 @@ impl StreamContext { .get_http_request_header(ARCH_PROVIDER_HINT_HEADER) .map(|llm_name| llm_name.into()); - debug!("llm provider hint: {:?}", provider_hint); self.llm_provider = Some(routing::get_llm_provider( &self.llm_providers, provider_hint, )); - debug!("selected llm: {}", self.llm_provider.as_ref().unwrap().name); + + debug!( + "llm provider hint: {:?}, selected llm: {}", + self.get_http_request_header(ARCH_PROVIDER_HINT_HEADER), + self.llm_provider.as_ref().unwrap().name + ); } fn modify_auth_headers(&mut self) -> Result<(), ServerError> { @@ -173,6 +176,8 @@ impl HttpContext for StreamContext { // Envoy's HTTP model is event driven. The WASM ABI has given implementors events to hook onto // the lifecycle of the http request and response. fn on_http_request_headers(&mut self, _num_headers: usize, _end_of_stream: bool) -> Action { + let request_path = self.get_http_request_header(":path").unwrap_or_default(); + debug!("request_path: {}", request_path); self.select_llm_provider(); // if endpoint is not set then use provider name as routing header so envoy can resolve the cluster name @@ -197,12 +202,6 @@ impl HttpContext for StreamContext { self.is_chat_completions_request = self.get_http_request_header(":path").unwrap_or_default() == CHAT_COMPLETIONS_PATH; - debug!( - "on_http_request_headers S[{}] req_headers={:?}", - self.context_id, - obfuscate_auth_header(&mut self.get_http_request_headers()) - ); - self.request_id = self.get_http_request_header(REQUEST_ID_HEADER); self.traceparent = self.get_http_request_header(TRACE_PARENT_HEADER); @@ -310,11 +309,6 @@ impl HttpContext for StreamContext { } fn on_http_response_headers(&mut self, _num_headers: usize, _end_of_stream: bool) -> Action { - debug!( - "on_http_response_headers [S={}] end_stream={}", - self.context_id, _end_of_stream - ); - self.set_property( vec!["metadata", "filter_metadata", "llm_filter", "user_prompt"], Some("hello world from filter".as_bytes()), @@ -324,11 +318,6 @@ impl HttpContext for StreamContext { } fn on_http_response_body(&mut self, body_size: usize, end_of_stream: bool) -> Action { - debug!( - "on_http_response_body [S={}] bytes={} end_stream={}", - self.context_id, body_size, end_of_stream - ); - if !self.is_chat_completions_request { debug!("non-chatcompletion request"); return Action::Continue; @@ -438,7 +427,7 @@ impl HttpContext for StreamContext { } streaming_chunk } else { - debug!("non streaming response bytes read: 0:{}", body_size); + trace!("non streaming response bytes read: 0:{}", body_size); match self.get_http_response_body(0, body_size) { Some(body) => body, None => { @@ -520,7 +509,7 @@ impl HttpContext for StreamContext { } } } else { - debug!("non streaming response"); + trace!("non streaming response"); let chat_completions_response: ChatCompletionsResponse = match serde_json::from_str(body_utf8.as_str()) { Ok(de) => de, diff --git a/crates/prompt_gateway/src/context.rs b/crates/prompt_gateway/src/context.rs index 2b0f8d3f..c70937d7 100644 --- a/crates/prompt_gateway/src/context.rs +++ b/crates/prompt_gateway/src/context.rs @@ -3,7 +3,7 @@ use std::str::FromStr; use common::errors::ServerError; use common::stats::IncrementingMetric; use http::StatusCode; -use log::{debug, warn}; +use log::warn; use proxy_wasm::traits::Context; use crate::stream_context::{ResponseHandlerType, StreamContext}; @@ -25,12 +25,11 @@ impl Context for StreamContext { let body = self .get_http_call_response_body(0, body_size) - .unwrap_or(vec![]); + .unwrap_or_default(); let http_status = self .get_http_call_response_header(":status") .unwrap_or(StatusCode::OK.as_str().to_string()); - debug!("http call response code: {}", http_status); if http_status != StatusCode::OK.as_str() { let server_error = ServerError::Upstream { host: callout_context.upstream_cluster.unwrap(), @@ -45,7 +44,6 @@ impl Context for StreamContext { ); } - debug!("http call response handler type: {:?}", callout_context.response_handler_type); #[cfg_attr(any(), rustfmt::skip)] match callout_context.response_handler_type { ResponseHandlerType::ArchFC => self.arch_fc_response_handler(body, callout_context), diff --git a/crates/prompt_gateway/src/filter_context.rs b/crates/prompt_gateway/src/filter_context.rs index 9780ed7d..b323e675 100644 --- a/crates/prompt_gateway/src/filter_context.rs +++ b/crates/prompt_gateway/src/filter_context.rs @@ -3,7 +3,6 @@ use crate::stream_context::StreamContext; use common::configuration::{Configuration, Overrides, PromptGuards, PromptTarget, Tracing}; use common::http::Client; use common::stats::Gauge; -use log::debug; use proxy_wasm::traits::*; use proxy_wasm::types::*; use std::cell::RefCell; @@ -84,11 +83,6 @@ impl RootContext for FilterContext { } fn create_http_context(&self, context_id: u32) -> Option> { - debug!( - "||| create_http_context called with context_id: {:?} |||", - context_id - ); - Some(Box::new(StreamContext::new( context_id, Rc::clone(&self.metrics), diff --git a/crates/prompt_gateway/src/http_context.rs b/crates/prompt_gateway/src/http_context.rs index 76e137c1..f105fd7e 100644 --- a/crates/prompt_gateway/src/http_context.rs +++ b/crates/prompt_gateway/src/http_context.rs @@ -10,7 +10,6 @@ use common::{ }, errors::ServerError, http::{CallArgs, Client}, - pii::obfuscate_auth_header, }; use http::StatusCode; use log::{debug, trace, warn}; @@ -40,12 +39,6 @@ impl HttpContext for StreamContext { self.is_chat_completions_request = request_path == CHAT_COMPLETIONS_PATH; - trace!( - "on_http_request_headers S[{}] req_headers={:?}", - self.context_id, - obfuscate_auth_header(&mut self.get_http_request_headers()) - ); - self.request_id = self.get_http_request_header(REQUEST_ID_HEADER); self.traceparent = self.get_http_request_header(TRACE_PARENT_HEADER); Action::Continue