From 0f5c411fd829790d003129c3dfce777ac3ff67cf Mon Sep 17 00:00:00 2001 From: Adam Cattermole Date: Fri, 8 Nov 2024 11:15:15 +0000 Subject: [PATCH] Put debug attributes function behind feature flag Signed-off-by: Adam Cattermole --- Cargo.toml | 1 + Makefile | 7 +++++-- README.md | 6 ++++++ src/data/cel.rs | 3 ++- src/data/mod.rs | 5 +++-- src/filter/http_context.rs | 7 ++++--- 6 files changed, 21 insertions(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index b8898595..c040fce3 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 e8c3fe88..4c4d8ef1 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 5068a974..57afe0db 100644 --- a/README.md +++ b/README.md @@ -80,6 +80,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 a4763d68..68fe2959 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; @@ -445,7 +446,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 3ad9633a..9b7dd28b 100644 --- a/src/data/mod.rs +++ b/src/data/mod.rs @@ -5,9 +5,10 @@ mod property; pub use attribute::get_attribute; pub use attribute::store_metadata; +#[cfg(feature = "debug-host-behaviour")] +pub use cel::debug_all_well_known_attributes; + pub use cel::Expression; pub use cel::Predicate; 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 e7e407f9..69a8c0c9 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