Skip to content

Commit

Permalink
Merge pull request #82 from Kuadrant/debug-log-on-get-property
Browse files Browse the repository at this point in the history
add debug log for get_property call
  • Loading branch information
eguzki authored Sep 12, 2024
2 parents ff7e501 + cb43003 commit 7c7fa22
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/policy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ impl Policy {

fn pattern_expression_applies(&self, filter: &Filter, p_e: &PatternExpression) -> bool {
let attribute_path = p_e.path();
debug!(
"#{} get_property: selector: {} path: {:?}",
filter.context_id, p_e.selector, attribute_path
);
let attribute_value = match filter.get_property(attribute_path) {
None => {
debug!(
Expand Down Expand Up @@ -127,6 +131,10 @@ impl Policy {
};

let attribute_path = selector_item.path();
debug!(
"#{} get_property: selector: {} path: {:?}",
filter.context_id, selector_item.selector, attribute_path
);
let value = match filter.get_property(attribute_path.tokens()) {
None => {
debug!(
Expand Down
28 changes: 28 additions & 0 deletions tests/rate_limited.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,18 @@ fn it_limits() {
Some(LogLevel::Debug),
Some("#2 ratelimitpolicy selected some-name"),
)
.expect_log(
Some(LogLevel::Debug),
Some("#2 get_property: selector: request.url_path path: [\"request\", \"url_path\"]"),
)
.expect_log(
Some(LogLevel::Debug),
Some("#2 get_property: selector: request.host path: [\"request\", \"host\"]"),
)
.expect_log(
Some(LogLevel::Debug),
Some("#2 get_property: selector: request.method path: [\"request\", \"method\"]"),
)
.expect_grpc_call(
Some("limitador-cluster"),
Some("envoy.service.ratelimit.v3.RateLimitService"),
Expand Down Expand Up @@ -317,6 +329,18 @@ fn it_passes_additional_headers() {
Some(LogLevel::Debug),
Some("#2 ratelimitpolicy selected some-name"),
)
.expect_log(
Some(LogLevel::Debug),
Some("#2 get_property: selector: request.url_path path: [\"request\", \"url_path\"]"),
)
.expect_log(
Some(LogLevel::Debug),
Some("#2 get_property: selector: request.host path: [\"request\", \"host\"]"),
)
.expect_log(
Some(LogLevel::Debug),
Some("#2 get_property: selector: request.method path: [\"request\", \"method\"]"),
)
.expect_grpc_call(
Some("limitador-cluster"),
Some("envoy.service.ratelimit.v3.RateLimitService"),
Expand Down Expand Up @@ -556,6 +580,10 @@ fn it_does_not_rate_limits_when_selector_does_not_exist_and_misses_default_value
Some(LogLevel::Debug),
Some("#2 ratelimitpolicy selected some-name"),
)
.expect_log(
Some(LogLevel::Debug),
Some("#2 get_property: selector: unknown.path path: Path { tokens: [\"unknown\", \"path\"] }"),
)
.expect_log(
Some(LogLevel::Debug),
Some("#2 build_single_descriptor: selector not found: unknown.path"),
Expand Down

0 comments on commit 7c7fa22

Please sign in to comment.