From 552300d437ed3a3c3ecf20049b0f96eb2a9a13c1 Mon Sep 17 00:00:00 2001 From: rtkay123 Date: Fri, 15 Aug 2025 21:05:36 +0200 Subject: feat(exec): get config --- .../src/processor/rule/configuration.rs | 42 ++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 crates/rule-executor/src/processor/rule/configuration.rs (limited to 'crates/rule-executor/src/processor/rule') diff --git a/crates/rule-executor/src/processor/rule/configuration.rs b/crates/rule-executor/src/processor/rule/configuration.rs new file mode 100644 index 0000000..6e11248 --- /dev/null +++ b/crates/rule-executor/src/processor/rule/configuration.rs @@ -0,0 +1,42 @@ +use anyhow::{Result, anyhow}; +use tracing::{Instrument, instrument, trace, trace_span}; +use warden_core::configuration::rule::{RuleConfiguration, RuleConfigurationRequest}; + +use crate::state::AppHandle; + +#[instrument(skip(state))] +pub(super) async fn get_configuration( + request: RuleConfigurationRequest, + state: AppHandle, +) -> Result { + trace!("checking cache for rule configuration"); + let cache = state.local_cache.read().await; + let config = cache.get(&request).await; + if let Some(config) = config { + trace!("cache hit"); + return Ok(config); + } + trace!("cache miss, asking config service"); + + let mut client = state.query_rule_client.clone(); + + let span = trace_span!( + "get.rule.config", + "otel.kind" = "client", + "rpc.service" = "configuration" + ); + let resp = client + .get_rule_configuration(request.clone()) + .instrument(span) + .await? + .into_inner(); + + let config = resp + .configuration + .ok_or_else(|| anyhow!("missing configuration"))?; + + let mut cache = state.local_cache.write().await; + cache.insert(request, config.clone()).await; + + Ok(config) +} -- cgit v1.2.3