Skip to content

Commit

Permalink
Put debug attributes function behind feature flag
Browse files Browse the repository at this point in the history
Signed-off-by: Adam Cattermole <[email protected]>
  • Loading branch information
adam-cattermole committed Nov 8, 2024
1 parent 9103d31 commit c58d7ed
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 8 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ crate-type = ["cdylib"]
[features]
default = ["with-serde"]
with-serde = ["protobuf/with-serde"]
debug-host-behaviour = []

[dependencies]
proxy-wasm = "0.2.1"
Expand Down
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ MKFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST)))
PROJECT_PATH := $(patsubst %/,%,$(dir $(MKFILE_PATH)))

BUILD ?= debug
ifneq ($(FEATURES),)
FEATURE_CMD=--features $(FEATURES)
endif

WASM_RELEASE_BIN = $(PROJECT_PATH)/target/wasm32-unknown-unknown/$(BUILD)/wasm_shim.wasm
WASM_RELEASE_PATH = $(dir $(WASM_RELEASE_BIN))
Expand All @@ -24,9 +27,9 @@ $(PROTOC_BIN):
build: $(PROTOC_BIN)
@echo "Building the wasm filter"
ifeq ($(BUILD), release)
export PATH=$(PROJECT_PATH)/bin:$$PATH; cargo build --target=wasm32-unknown-unknown --release
export PATH=$(PROJECT_PATH)/bin:$$PATH; cargo build --target=wasm32-unknown-unknown --release $(FEATURE_CMD)
else
export PATH=$(PROJECT_PATH)/bin:$$PATH; cargo build --target=wasm32-unknown-unknown
export PATH=$(PROJECT_PATH)/bin:$$PATH; cargo build --target=wasm32-unknown-unknown $(FEATURE_CMD)
endif

# Remove old ones and fetch the latest third-party protobufs
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,12 @@ Build the WASM module in release mode
make build BUILD=release
```

Build the WASM module with features

```
make build FEATURES=debug-host-behaviour
```

## Testing

```
Expand Down
3 changes: 2 additions & 1 deletion src/data/cel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use cel_interpreter::objects::{Key, Map, ValueType};
use cel_interpreter::{Context, ExecutionError, ResolveResult, Value};
use cel_parser::{parse, Expression as CelExpression, Member, ParseError};
use chrono::{DateTime, FixedOffset};
#[cfg(feature = "debug-host-behaviour")]
use log::debug;
use proxy_wasm::types::{Bytes, Status};
use serde_json::Value as JsonValue;
Expand Down Expand Up @@ -442,7 +443,7 @@ fn properties<'e>(exp: &'e CelExpression, all: &mut Vec<Vec<&'e str>>, path: &mu
}
}

#[allow(dead_code)]
#[cfg(feature = "debug-host-behaviour")]
pub fn debug_all_well_known_attributes() {
let attributes = new_well_known_attribute_map();
attributes.iter().for_each(|(key, value_type)| {
Expand Down
5 changes: 3 additions & 2 deletions src/data/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ pub use attribute::get_attribute;
pub use attribute::store_metadata;
pub use attribute::AttributeValue;

#[cfg(feature = "debug-host-behaviour")]
pub use cel::debug_all_well_known_attributes;

pub use cel::Expression;
pub use cel::Predicate;

pub use property::get_property;
pub use property::Path as PropertyPath;

// pub use cel::debug_all_well_known_attributes;
7 changes: 4 additions & 3 deletions src/filter/http_context.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
use crate::configuration::action_set::ActionSet;
use crate::configuration::{FailureMode, FilterConfig};
#[cfg(feature = "debug-host-behaviour")]
use crate::data;
use crate::operation_dispatcher::{OperationDispatcher, OperationError};
use crate::service::GrpcService;
use log::{debug, warn};
use proxy_wasm::traits::{Context, HttpContext};
use proxy_wasm::types::Action;
use std::cell::RefCell;
use std::rc::Rc;
// use crate::data;

pub struct Filter {
pub context_id: u32,
Expand Down Expand Up @@ -95,8 +96,8 @@ impl HttpContext for Filter {
fn on_http_request_headers(&mut self, _: usize, _: bool) -> Action {
debug!("#{} on_http_request_headers", self.context_id);

// uncomment to debug log all well known attributes
// data::debug_all_well_known_attributes();
#[cfg(feature = "debug-host-behaviour")]
data::debug_all_well_known_attributes();

match self
.config
Expand Down

0 comments on commit c58d7ed

Please sign in to comment.