diff --git a/Cargo.toml b/Cargo.toml index b889859..c040fce 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/Makefile b/Makefile index e8c3fe8..4c4d8ef 100644 --- a/Makefile +++ b/Makefile @@ -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)) @@ -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 diff --git a/README.md b/README.md index a638a36..640f3f8 100644 --- a/README.md +++ b/README.md @@ -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 ``` diff --git a/src/data/cel.rs b/src/data/cel.rs index 83f8167..9858640 100644 --- a/src/data/cel.rs +++ b/src/data/cel.rs @@ -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; @@ -442,7 +443,7 @@ fn properties<'e>(exp: &'e CelExpression, all: &mut Vec>, 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)| { diff --git a/src/data/mod.rs b/src/data/mod.rs index 004ece6..fc479ae 100644 --- a/src/data/mod.rs +++ b/src/data/mod.rs @@ -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; diff --git a/src/filter/http_context.rs b/src/filter/http_context.rs index e7e407f..69a8c0c 100644 --- a/src/filter/http_context.rs +++ b/src/filter/http_context.rs @@ -1,5 +1,7 @@ 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}; @@ -7,7 +9,6 @@ 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, @@ -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