aboutsummaryrefslogtreecommitdiffstats
path: root/crates/configuration/src/state/routing
diff options
context:
space:
mode:
authorrtkay123 <dev@kanjala.com>2025-08-14 18:05:07 +0200
committerrtkay123 <dev@kanjala.com>2025-08-14 18:05:07 +0200
commit1b8c6886f6d22f9c61e978b42d066dce91e334dc (patch)
tree468fae725d2464baac9b27d6a02f67f24e3eeb9f /crates/configuration/src/state/routing
parent600c7a1942c06c0f7a0ae87448595057206bf324 (diff)
downloadwarden-1b8c6886f6d22f9c61e978b42d066dce91e334dc.tar.bz2
warden-1b8c6886f6d22f9c61e978b42d066dce91e334dc.zip
feat(config): rule grpc
Diffstat (limited to 'crates/configuration/src/state/routing')
-rw-r--r--crates/configuration/src/state/routing/mutate_routing.rs23
-rw-r--r--crates/configuration/src/state/routing/query_routing.rs16
2 files changed, 27 insertions, 12 deletions
diff --git a/crates/configuration/src/state/routing/mutate_routing.rs b/crates/configuration/src/state/routing/mutate_routing.rs
index 0c0637a..105cf18 100644
--- a/crates/configuration/src/state/routing/mutate_routing.rs
+++ b/crates/configuration/src/state/routing/mutate_routing.rs
@@ -1,6 +1,6 @@
use opentelemetry_semantic_conventions::attribute;
use tonic::{Request, Response, Status, async_trait};
-use tracing::{Instrument, error, info_span, instrument};
+use tracing::{Instrument, error, info_span, instrument, trace};
use tracing_opentelemetry::OpenTelemetrySpanExt;
use uuid::Uuid;
use warden_core::configuration::{
@@ -26,11 +26,14 @@ impl MutateRouting for AppHandle {
&self,
request: Request<RoutingConfiguration>,
) -> Result<Response<RoutingConfiguration>, Status> {
+ trace!("creating routing configuration");
+
let request = request.into_inner();
let span = info_span!("create.configuration.routing");
span.set_attribute(attribute::DB_SYSTEM_NAME, "postgres");
span.set_attribute(attribute::DB_OPERATION_NAME, "insert");
span.set_attribute(attribute::DB_COLLECTION_NAME, "routing");
+ span.set_attribute("otel.kind", "client");
sqlx::query!(
"insert into routing (id, configuration) values ($1, $2)",
@@ -42,8 +45,9 @@ impl MutateRouting for AppHandle {
.await
.map_err(|e| {
error!("{e}");
- tonic::Status::internal(e.to_string())
+ tonic::Status::internal("database error")
})?;
+ trace!("configuration created");
Ok(tonic::Response::new(request))
}
@@ -58,7 +62,7 @@ impl MutateRouting for AppHandle {
.subject
.split(".")
.next()
- .expect("bad config");
+ .expect("checked on startup");
let request = request.into_inner();
let id = Uuid::parse_str(&request.id)
@@ -70,6 +74,9 @@ impl MutateRouting for AppHandle {
span.set_attribute(attribute::DB_SYSTEM_NAME, "postgres");
span.set_attribute(attribute::DB_OPERATION_NAME, "update");
span.set_attribute(attribute::DB_COLLECTION_NAME, "routing");
+ span.set_attribute("otel.kind", "client");
+
+ trace!("updating configuration");
let updated = sqlx::query_as!(
RoutingRow,
@@ -87,8 +94,9 @@ impl MutateRouting for AppHandle {
.await
.map_err(|e| {
error!("{e}");
- tonic::Status::internal(e.to_string())
+ tonic::Status::internal("database is not ready")
})?;
+ trace!("configuration updated");
let (_del_result, _publish_result) = tokio::try_join!(
invalidate_cache(self, CacheKey::Routing(&id)),
@@ -110,7 +118,7 @@ impl MutateRouting for AppHandle {
.subject
.split(".")
.next()
- .expect("bad config");
+ .expect("checked on startup");
let request = request.into_inner();
let id = Uuid::parse_str(&request.id)
@@ -120,6 +128,8 @@ impl MutateRouting for AppHandle {
span.set_attribute(attribute::DB_SYSTEM_NAME, "postgres");
span.set_attribute(attribute::DB_OPERATION_NAME, "delete");
span.set_attribute(attribute::DB_COLLECTION_NAME, "routing");
+ span.set_attribute("otel.kind", "client");
+ trace!("deleting configuration");
let updated = sqlx::query_as!(
RoutingRow,
@@ -135,8 +145,9 @@ impl MutateRouting for AppHandle {
.await
.map_err(|e| {
error!("{e}");
- tonic::Status::internal(e.to_string())
+ tonic::Status::internal("database is not ready")
})?;
+ trace!("configuration deleted");
let (_del_result, _publish_result) = tokio::try_join!(
invalidate_cache(self, CacheKey::Routing(&id)),
diff --git a/crates/configuration/src/state/routing/query_routing.rs b/crates/configuration/src/state/routing/query_routing.rs
index 3c6814d..82c8d1c 100644
--- a/crates/configuration/src/state/routing/query_routing.rs
+++ b/crates/configuration/src/state/routing/query_routing.rs
@@ -38,6 +38,8 @@ impl QueryRouting for AppHandle {
span.set_attribute(attribute::DB_SYSTEM_NAME, "valkey");
span.set_attribute(attribute::DB_OPERATION_NAME, "get");
span.set_attribute(attribute::DB_OPERATION_PARAMETER, "active");
+ span.set_attribute("otel.kind", "client");
+
let routing_config = cache
.get::<_, Vec<u8>>(CacheKey::ActiveRouting)
.instrument(span)
@@ -50,12 +52,12 @@ impl QueryRouting for AppHandle {
}
});
- if let Ok(Some(routing_config)) = routing_config {
- if routing_config.active {
- return Ok(tonic::Response::new(GetActiveRoutingResponse {
- configuration: Some(routing_config),
- }));
- }
+ if let Ok(Some(routing_config)) = routing_config
+ && routing_config.active
+ {
+ return Ok(tonic::Response::new(GetActiveRoutingResponse {
+ configuration: Some(routing_config),
+ }));
}
let span = info_span!("db.get.routing.active");
@@ -63,6 +65,7 @@ impl QueryRouting for AppHandle {
span.set_attribute(attribute::DB_OPERATION_NAME, "select");
span.set_attribute(attribute::DB_COLLECTION_NAME, "routing");
span.set_attribute(attribute::DB_OPERATION_PARAMETER, "active");
+ span.set_attribute("otel.kind", "client");
let config = sqlx::query_as!(
RoutingRow,
@@ -85,6 +88,7 @@ impl QueryRouting for AppHandle {
span.set_attribute(attribute::DB_SYSTEM_NAME, "valkey");
span.set_attribute(attribute::DB_OPERATION_NAME, "set");
span.set_attribute(attribute::DB_OPERATION_PARAMETER, "routing.active");
+ span.set_attribute("otel.kind", "client");
if let Err(e) = cache
.set::<_, _, ()>(CacheKey::ActiveRouting, bytes)