Skip to content

Commit

Permalink
logging: context in the beginning of the log line
Browse files Browse the repository at this point in the history
  • Loading branch information
eguzki committed Jun 20, 2024
1 parent f2138c8 commit f0bd703
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ extern "C" fn start() {
proxy_wasm::hostcalls::log(LogLevel::Critical, &panic_info.to_string()).unwrap();
}));
proxy_wasm::set_root_context(|context_id| -> Box<dyn RootContext> {
info!("set_root_context #{}", context_id);
info!("#{} set_root_context", context_id);
Box::new(FilterRoot {
context_id,
config: Rc::new(FilterConfig::new()),
Expand Down
36 changes: 20 additions & 16 deletions src/filter/http_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl Filter {
let descriptors = self.build_descriptors(rlp);
if descriptors.is_empty() {
debug!(
"process_rate_limit_policy: empty descriptors #{}",
"#{} process_rate_limit_policy: empty descriptors",
self.context_id
);
return Action::Continue;
Expand Down Expand Up @@ -93,8 +93,8 @@ impl Filter {
) {
Ok(call_id) => {
debug!(
"Initiated gRPC call (id# {}) to Limitador #{}",
call_id, self.context_id
"#{} initiated gRPC call (id# {}) to Limitador",
self.context_id, call_id
);
Action::Pause
}
Expand Down Expand Up @@ -148,8 +148,8 @@ impl Filter {
{
None => {
debug!(
"pattern_expression_applies: selector not found: {}, defaulting to `` #{}",
p_e.selector, self.context_id
"#{} pattern_expression_applies: selector not found: {}, defaulting to ``",
self.context_id, p_e.selector
);
"".to_string()
}
Expand All @@ -158,8 +158,8 @@ impl Filter {
Some(attribute_bytes) => match String::from_utf8(attribute_bytes) {
Err(e) => {
debug!(
"pattern_expression_applies: failed to parse selector value: {}, error: {} #{}",
p_e.selector, e, self.context_id,
"#{} pattern_expression_applies: failed to parse selector value: {}, error: {}",
self.context_id, p_e.selector, e
);
return false;
}
Expand Down Expand Up @@ -196,8 +196,8 @@ impl Filter {
{
None => {
debug!(
"build_single_descriptor: selector not found: {} #{}",
selector_item.selector, self.context_id,
"#{} build_single_descriptor: selector not found: {}",
self.context_id, selector_item.selector
);
match &selector_item.default {
None => return None, // skipping the entire descriptor
Expand All @@ -209,8 +209,8 @@ impl Filter {
Some(attribute_bytes) => match String::from_utf8(attribute_bytes) {
Err(e) => {
debug!(
"build_single_descriptor: failed to parse selector value: {}, error: {} #{}",
selector_item.selector, e, self.context_id
"#{} build_single_descriptor: failed to parse selector value: {}, error: {}",
self.context_id, selector_item.selector, e
);
return None;
}
Expand Down Expand Up @@ -242,7 +242,7 @@ impl Filter {

impl HttpContext for Filter {
fn on_http_request_headers(&mut self, _: usize, _: bool) -> Action {
debug!("on_http_request_headers #{}", self.context_id);
debug!("#{} on_http_request_headers", self.context_id);

for header in TracingHeader::all() {
if let Some(value) = self.get_http_request_header_bytes(header.as_str()) {
Expand All @@ -257,31 +257,35 @@ impl HttpContext for Filter {
{
None => {
debug!(
"Allowing request to pass because zero descriptors generated #{}",
"#{} allowing request to pass because zero descriptors generated",
self.context_id
);
Action::Continue
}
Some(rlp) => {
debug!("ratelimitpolicy selected {} #{}", rlp.name, self.context_id);
debug!("#{} ratelimitpolicy selected {}", self.context_id, rlp.name);
self.process_rate_limit_policy(rlp)
}
}
}

fn on_http_response_headers(&mut self, _num_headers: usize, _end_of_stream: bool) -> Action {
debug!("on_http_response_headers #{}", self.context_id);
debug!("#{} on_http_response_headers", self.context_id);
for (name, value) in &self.response_headers_to_add {
self.add_http_response_header(name, value);
}
Action::Continue
}

fn on_log(&mut self) {
debug!("#{} completed.", self.context_id);
}
}

impl Context for Filter {
fn on_grpc_call_response(&mut self, token_id: u32, status_code: u32, resp_size: usize) {
debug!(
"on_grpc_call_response: received gRPC call response: token: {token_id}, status: {status_code} #{}",
"#{} on_grpc_call_response: received gRPC call response: token: {token_id}, status: {status_code}",
self.context_id
);

Expand Down
8 changes: 4 additions & 4 deletions src/filter/root_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ impl RootContext for FilterRoot {
);

info!(
"{} {} root-context #{}: VM started",
WASM_SHIM_HEADER, full_version, self.context_id
"#{} {} {}: VM started",
self.context_id, WASM_SHIM_HEADER, full_version
);
true
}

fn create_http_context(&self, context_id: u32) -> Option<Box<dyn HttpContext>> {
debug!("create_http_context #{}", context_id);
debug!("#{} create_http_context", context_id);
Some(Box::new(Filter {
context_id,
config: Rc::clone(&self.config),
Expand All @@ -45,7 +45,7 @@ impl RootContext for FilterRoot {
}

fn on_configure(&mut self, _config_size: usize) -> bool {
info!("on_configure #{}", self.context_id);
info!("#{} on_configure", self.context_id);
let configuration: Vec<u8> = match self.get_plugin_configuration() {
Some(c) => c,
None => return false,
Expand Down

0 comments on commit f0bd703

Please sign in to comment.