Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
refactor(euclid): log refactors for dynamic routing (#6052)
Prajjwal Kumar7e03da75781b
diff --git a/crates/router/src/core/payments/operations/payment_response.rs b/crates/router/src/core/payments/operations/payment_response.rsindex b163947ae0..deaa20e3f3 100644--- a/crates/router/src/core/payments/operations/payment_response.rs+++ b/crates/router/src/core/payments/operations/payment_response.rs@@ -1716,23 +1716,27 @@ async fn payment_response_update_tracker<F: Clone, T: types::Capturable>(#[cfg(all(feature = "v1", feature = "dynamic_routing"))]{- let state = state.clone();- let business_profile = business_profile.clone();- let payment_attempt = payment_attempt.clone();- tokio::spawn(- async move {- push_metrics_for_success_based_routing(- &state,- &payment_attempt,- routable_connectors,- &business_profile,- )- .await- .map_err(|e| logger::error!(dynamic_routing_metrics_error=?e))- .ok();- }- .in_current_span(),- );+ if let Some(dynamic_routing_algorithm) = business_profile.dynamic_routing_algorithm.clone()+ {+ let state = state.clone();+ let business_profile = business_profile.clone();+ let payment_attempt = payment_attempt.clone();+ tokio::spawn(+ async move {+ push_metrics_for_success_based_routing(+ &state,+ &payment_attempt,+ routable_connectors,+ &business_profile,+ dynamic_routing_algorithm,+ )+ .await+ .map_err(|e| logger::error!(dynamic_routing_metrics_error=?e))+ .ok();+ }+ .in_current_span(),+ );+ }}payment_data.payment_intent = payment_intent;payment_data.payment_attempt = payment_attempt;diff --git a/crates/router/src/core/routing.rs b/crates/router/src/core/routing.rsindex 4347b1418e..b7b1c13ea8 100644--- a/crates/router/src/core/routing.rs+++ b/crates/router/src/core/routing.rs@@ -1253,6 +1253,27 @@ pub async fn toggle_success_based_routing(),};+ // redact cache for success based routing configs+ let cache_key = format!(+ "{}_{}",+ business_profile.get_id().get_string_repr(),+ algorithm_id.get_string_repr()+ );+ let cache_entries_to_redact =+ vec![cache::CacheKind::SuccessBasedDynamicRoutingCache(+ cache_key.into(),+ )];+ let _ = cache::publish_into_redact_channel(+ state.store.get_cache_store().as_ref(),+ cache_entries_to_redact,+ )+ .await+ .map_err(|e| {+ logger::error!(+ "unable to publish into the redact channel for evicting the success based routing config cache {e:?}"+ )+ });+let record = db.find_routing_algorithm_by_profile_id_algorithm_id(business_profile.get_id(),@@ -1351,7 +1372,7 @@ pub async fn success_based_routing_update_configs(cache_entries_to_redact,).await- .map_err(|e| logger::error!("unable to redact the success based routing config cache {e:?}"));+ .map_err(|e| logger::error!("unable to publish into the redact channel for evicting the success based routing config cache {e:?}"));let new_record = record.foreign_into();diff --git a/crates/router/src/core/routing/helpers.rs b/crates/router/src/core/routing/helpers.rsindex ef62119786..22966208dd 100644--- a/crates/router/src/core/routing/helpers.rs+++ b/crates/router/src/core/routing/helpers.rs@@ -594,13 +594,8 @@ pub async fn refresh_success_based_routing_cache(pub async fn fetch_success_based_routing_configs(state: &SessionState,business_profile: &domain::Profile,+ dynamic_routing_algorithm: serde_json::Value,) -> RouterResult<routing_types::SuccessBasedRoutingConfig> {- let dynamic_routing_algorithm = business_profile.dynamic_routing_algorithm.clone().ok_or(- errors::ApiErrorResponse::GenericNotFoundError {- message: "unable to find dynamic_routing_algorithm in business profile".to_string(),- },- )?;-let dynamic_routing_algorithm_ref = dynamic_routing_algorithm.parse_value::<routing_types::DynamicRoutingAlgorithmRef>("DynamicRoutingAlgorithmRef").change_context(errors::ApiErrorResponse::InternalServerError)@@ -613,8 +608,12 @@ pub async fn fetch_success_based_routing_configs(.to_string(),})?.algorithm_id+ // error can be possible when the feature is toggled off..ok_or(errors::ApiErrorResponse::GenericNotFoundError {- message: "unable to find algorithm id in success based algorithm config".to_string(),+ message: format!(+ "unable to find algorithm_id in success based algorithm config as the feature is disabled for profile_id: {}",+ business_profile.get_id().get_string_repr()+ ),})?;let key = format!(@@ -658,6 +657,7 @@ pub async fn push_metrics_for_success_based_routing(payment_attempt: &storage::PaymentAttempt,routable_connectors: Vec<routing_types::RoutableConnectorChoice>,business_profile: &domain::Profile,+ dynamic_routing_algorithm: serde_json::Value,) -> RouterResult<()> {let client = state.grpc_client@@ -675,10 +675,10 @@ pub async fn push_metrics_for_success_based_routing()?;let success_based_routing_configs =- fetch_success_based_routing_configs(state, business_profile)+ fetch_success_based_routing_configs(state, business_profile, dynamic_routing_algorithm).await.change_context(errors::ApiErrorResponse::InternalServerError)- .attach_printable("unable to retrieve success_rate configs")?;+ .attach_printable("unable to retrieve success_rate based dynamic routing configs")?;let tenant_business_profile_id = format!("{}:{}",@@ -749,41 +749,35 @@ pub async fn push_metrics_for_success_based_routing("currency",payment_attempt.currency- .ok_or(errors::ApiErrorResponse::InternalServerError)- .attach_printable("payment currency not found in payment_attempt")?- .to_string(),+ .map_or_else(|| "None".to_string(), |currency| currency.to_string()),),("payment_method",- payment_attempt- .payment_method- .ok_or(errors::ApiErrorResponse::InternalServerError)- .attach_printable("payment method not found in payment_attempt")?- .to_string(),+ payment_attempt.payment_method.map_or_else(+ || "None".to_string(),+ |payment_method| payment_method.to_string(),+ ),),("payment_method_type",- payment_attempt- .payment_method_type- .ok_or(errors::ApiErrorResponse::InternalServerError)- .attach_printable("payment method type not found in payment_attempt")?- .to_string(),+ payment_attempt.payment_method_type.map_or_else(+ || "None".to_string(),+ |payment_method_type| payment_method_type.to_string(),+ ),),("capture_method",- payment_attempt- .capture_method- .ok_or(errors::ApiErrorResponse::InternalServerError)- .attach_printable("capture method not found in payment_attempt")?- .to_string(),+ payment_attempt.capture_method.map_or_else(+ || "None".to_string(),+ |capture_method| capture_method.to_string(),+ ),),("authentication_type",- payment_attempt- .authentication_type- .ok_or(errors::ApiErrorResponse::InternalServerError)- .attach_printable("authentication type not found in payment_attempt")?- .to_string(),+ payment_attempt.authentication_type.map_or_else(+ || "None".to_string(),+ |authentication_type| authentication_type.to_string(),+ ),),("payment_status", payment_attempt.status.to_string()),("conclusive_classification", outcome.to_string()),diff --git a/crates/router/src/routes/routing.rs b/crates/router/src/routes/routing.rsindex 8fe543f851..4c8d89fa87 100644--- a/crates/router/src/routes/routing.rs+++ b/crates/router/src/routes/routing.rs@@ -1014,7 +1014,7 @@ pub async fn toggle_success_based_routing(&auth::JWTAuthProfileFromRoute {profile_id: wrapper.profile_id,required_permission: Permission::RoutingWrite,- minimum_entity_level: EntityType::Merchant,+ minimum_entity_level: EntityType::Profile,},req.headers(),),