From dafdc25afcf801f35b854ce18f37d8345876855e Mon Sep 17 00:00:00 2001 From: Sacha Morard <2254275+SachaMorard@users.noreply.github.com> Date: Wed, 9 Oct 2024 18:45:59 +0200 Subject: [PATCH] feat: destinations node interpretation for wasm components --- .../compute/data_collection/components.rs | 5 +++- src/proxy/compute/data_collection/payload.rs | 23 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/proxy/compute/data_collection/components.rs b/src/proxy/compute/data_collection/components.rs index e632b1c..64a6348 100644 --- a/src/proxy/compute/data_collection/components.rs +++ b/src/proxy/compute/data_collection/components.rs @@ -50,7 +50,7 @@ pub async fn send_data_collection(p: &Payload) -> anyhow::Result<()> { // clone the payload to be able to move it to the async thread let p = p.clone(); let payload = provider::Payload { - uuid: p.uuid, + uuid: p.uuid.clone(), timestamp: p.timestamp.timestamp(), timestamp_millis: p.timestamp.timestamp_millis(), timestamp_micros: p.timestamp.timestamp_micros(), @@ -281,6 +281,9 @@ pub async fn send_data_collection(p: &Payload) -> anyhow::Result<()> { }; for cfg in &config::get().components.data_collection { + if !p.is_destination_enabled(cfg.name.as_str()) { + continue; + } let component = WASM_COMPONENTS .get() .unwrap() diff --git a/src/proxy/compute/data_collection/payload.rs b/src/proxy/compute/data_collection/payload.rs index 13e5380..03ec39e 100644 --- a/src/proxy/compute/data_collection/payload.rs +++ b/src/proxy/compute/data_collection/payload.rs @@ -227,3 +227,26 @@ pub struct Session { pub first_seen: DateTime, pub last_seen: DateTime, } + +impl Payload { + pub fn is_destination_enabled(&self, name: &str) -> &bool { + // if destinations is not set, return true + if self.destinations.is_none() { + return &true; + } + + // get destinations.get("all") + let all = self + .destinations + .as_ref() + .unwrap() + .get("all") + .unwrap_or(&true); + + // check if the destination is enabled + if self.destinations.as_ref().unwrap().contains_key(name) { + return self.destinations.as_ref().unwrap().get(name).unwrap(); + } + all + } +}