Skip to content

Commit

Permalink
logging enhancements
Browse files Browse the repository at this point in the history
  • Loading branch information
eguzki committed Jun 14, 2024
1 parent 984d7fe commit 7c051c0
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 33 deletions.
69 changes: 38 additions & 31 deletions src/filter/http_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::envoy::{
};
use crate::filter::http_context::TracingHeader::{Baggage, Traceparent, Tracestate};
use crate::utils::tokenize_with_escaping;
use log::{debug, info, warn};
use log::{debug, warn};
use protobuf::Message;
use proxy_wasm::traits::{Context, HttpContext};
use proxy_wasm::types::{Action, Bytes};
Expand Down Expand Up @@ -63,7 +63,7 @@ impl Filter {
fn process_rate_limit_policy(&self, rlp: &RateLimitPolicy) -> Action {
let descriptors = self.build_descriptors(rlp);
if descriptors.is_empty() {
debug!("[context_id: {}] empty descriptors", self.context_id);
debug!("empty descriptors #{}", self.context_id);
return Action::Continue;
}

Expand All @@ -89,7 +89,10 @@ impl Filter {
Duration::from_secs(5),
) {
Ok(call_id) => {
info!("Initiated gRPC call (id# {}) to Limitador", call_id);
debug!(
"Initiated gRPC call (id# {}) to Limitador #{}",
call_id, self.context_id
);
Action::Pause
}
Err(e) => {
Expand Down Expand Up @@ -137,28 +140,29 @@ impl Filter {
let attribute_path = tokenize_with_escaping(&p_e.selector, '.', '\\');
// convert a Vec<String> to Vec<&str>
// attribute_path.iter().map(AsRef::as_ref).collect()
let attribute_value =
match self.get_property(attribute_path.iter().map(AsRef::as_ref).collect()) {
None => {
let attribute_value = match self
.get_property(attribute_path.iter().map(AsRef::as_ref).collect())
{
None => {
debug!(
"pattern_expression_applies: selector not found: {}, defaulting to `` #{}",
p_e.selector, self.context_id
);
"".to_string()
}
// TODO(eastizle): not all fields are strings
// https://www.envoyproxy.io/docs/envoy/latest/intro/arch_overview/advanced/attributes
Some(attribute_bytes) => match String::from_utf8(attribute_bytes) {
Err(e) => {
debug!(
"[context_id: {}]: selector not found: {}, defaulting to ``",
self.context_id, p_e.selector
);
"".to_string()
}
// TODO(eastizle): not all fields are strings
// https://www.envoyproxy.io/docs/envoy/latest/intro/arch_overview/advanced/attributes
Some(attribute_bytes) => match String::from_utf8(attribute_bytes) {
Err(e) => {
debug!(
"[context_id: {}]: failed to parse selector value: {}, error: {}",
self.context_id, p_e.selector, e
"pattern_expression_applies: failed to parse selector value: {}, error: {} #{}",
p_e.selector, e, self.context_id,
);
return false;
}
Ok(attribute_value) => attribute_value,
},
};
return false;
}
Ok(attribute_value) => attribute_value,
},
};
p_e.operator
.eval(p_e.value.as_str(), attribute_value.as_str())
}
Expand Down Expand Up @@ -189,8 +193,8 @@ impl Filter {
{
None => {
debug!(
"[context_id: {}]: selector not found: {}",
self.context_id, selector_item.selector
"selector not found: {} #{}",
selector_item.selector, self.context_id,
);
match &selector_item.default {
None => return None, // skipping the entire descriptor
Expand Down Expand Up @@ -234,7 +238,7 @@ impl Filter {

impl HttpContext for Filter {
fn on_http_request_headers(&mut self, _: usize, _: bool) -> Action {
info!("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 @@ -248,13 +252,16 @@ impl HttpContext for Filter {
.get_longest_match_policy(self.request_authority().as_str())
{
None => {
info!(
"context #{}: Allowing request to pass because zero descriptors generated",
debug!(
"Allowing request to pass because zero descriptors generated #{}",
self.context_id
);
Action::Continue
}
Some(rlp) => self.process_rate_limit_policy(rlp),
Some(rlp) => {
debug!("ratelimitpolicy selected {} #{}", rlp.name, self.context_id);
self.process_rate_limit_policy(rlp)
}
}
}

Expand All @@ -269,8 +276,8 @@ impl HttpContext for Filter {

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

Expand Down
4 changes: 2 additions & 2 deletions src/filter/root_context.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::configuration::{FilterConfig, PluginConfiguration};
use crate::filter::http_context::Filter;
use const_format::formatcp;
use log::{info, warn};
use log::{debug, info, warn};
use proxy_wasm::traits::{Context, HttpContext, RootContext};
use proxy_wasm::types::ContextType;
use std::rc::Rc;
Expand Down Expand Up @@ -35,7 +35,7 @@ impl RootContext for FilterRoot {
}

fn create_http_context(&self, context_id: u32) -> Option<Box<dyn HttpContext>> {
info!("create_http_context #{}", context_id);
debug!("create_http_context #{}", context_id);
Some(Box::new(Filter {
context_id,
config: Rc::clone(&self.config),
Expand Down

0 comments on commit 7c051c0

Please sign in to comment.