diff options
author | rtkay123 <dev@kanjala.com> | 2025-08-12 21:05:07 +0200 |
---|---|---|
committer | rtkay123 <dev@kanjala.com> | 2025-08-12 21:05:07 +0200 |
commit | b6924a50c9ec49e1b2b0d286abbbe608410af87d (patch) | |
tree | 9c5cf583fedfbb585985ac829bbdfdadce1571fe /crates/router/src/processor/load.rs | |
parent | d75b5fc9c0497f56e6b8602d8ff8991bfaeff18c (diff) | |
download | warden-b6924a50c9ec49e1b2b0d286abbbe608410af87d.tar.bz2 warden-b6924a50c9ec49e1b2b0d286abbbe608410af87d.zip |
feat(router): get config
Diffstat (limited to 'crates/router/src/processor/load.rs')
-rw-r--r-- | crates/router/src/processor/load.rs | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/crates/router/src/processor/load.rs b/crates/router/src/processor/load.rs new file mode 100644 index 0000000..9d3fd0d --- /dev/null +++ b/crates/router/src/processor/load.rs @@ -0,0 +1,51 @@ +use opentelemetry_semantic_conventions::attribute; +use tracing_opentelemetry::OpenTelemetrySpanExt; +use tracing::{Instrument, debug, info, info_span, instrument, warn}; +use warden_core::{configuration::routing::RoutingConfiguration, google }; + +use crate::{cnfg::CACHE_KEY, state::AppHandle}; + +#[instrument(skip(state))] +pub async fn get_routing_config(state: AppHandle) -> Option<RoutingConfiguration> { + debug!("getting routing config"); + { + let span = info_span!("local_cache.get"); + span.set_attribute(attribute::DB_SYSTEM_NAME, "moka"); + let local_cache = state.local_cache.read().await; + if let Some(value) = local_cache.get(&CACHE_KEY).await { + return Some(value); + } + } + + let mut client = state.query_routing_client.clone(); + + let span = info_span!("get.routing.config"); + span.set_attribute(attribute::RPC_SERVICE, env!("CARGO_PKG_NAME")); + span.set_attribute("otel.kind", "client"); + + if let Ok(config) = client + .get_active_routing_configuration(google::protobuf::Empty::default()) + .instrument(span) + .await + { + debug!("fetched routing config"); + let span = info_span!("local_cache.insert"); + span.set_attribute(attribute::DB_SYSTEM_NAME, "moka"); + if let Some(config) = config.into_inner().configuration { + debug!("updating cache"); + let local_cache = state.local_cache.write().await; + local_cache + .insert(CACHE_KEY, config.clone()) + .instrument(span) + .await; + info!("cache refreshed"); + return Some(config); + } else { + warn!("no routing config is active"); + return None; + } + } else { + warn!("no routing config is active"); + return None; + } +} |