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
feat(routing): add a metrics label for the Decision Engine batch evaluate endpoint (#13909)
Ankit Kumar Guptab44f560b12a2
diff --git a/crates/router/src/core/payments/routing.rs b/crates/router/src/core/payments/routing.rsindex 9c38668b57..206a380fcc 100644--- a/crates/router/src/core/payments/routing.rs+++ b/crates/router/src/core/payments/routing.rs@@ -1011,7 +1011,8 @@ impl RoutingStage for SessionRoutingStage {let de_routing_effective =utils::is_decision_engine_routing_effective(input.state, input.dimensions).await;let shadow_evaluation_enabled = input.state.conf.open_router.static_routing_enabled- && input.state.conf.open_router.shadow_routing_enabled;+ && input.state.conf.open_router.shadow_routing_enabled+ && profile_has_active_routing_algorithm(input.business_profile);// Built up front so the Decision Engine calls can be issued together rather// than one wallet type at a time. A rule may branch on payment method type, so@@ -1725,6 +1726,20 @@ impl RoutingStage for HybridRoutingStage {}}+/// Whether the profile has an active routing algorithm for the Decision Engine to evaluate.+#[cfg(feature = "v1")]+fn profile_has_active_routing_algorithm(business_profile: &domain::Profile) -> bool {+ business_profile+ .routing_algorithm+ .clone()+ .and_then(|ra| {+ ra.parse_value::<api::routing::RoutingAlgorithmRef>("RoutingAlgorithmRef")+ .ok()+ })+ .and_then(|algorithm_ref| algorithm_ref.algorithm_id)+ .is_some()+}+#[allow(clippy::too_many_arguments)]#[cfg(feature = "v1")]pub async fn perform_hybrid_routing_if_enabled(@@ -1758,15 +1773,7 @@ pub async fn perform_hybrid_routing_if_enabled(// skipped on the premise that it only ever runs for cut-over profiles).let is_decision_engine_cutover_enabled =utils::is_decision_engine_routing_effective(state, dimensions).await;- let has_active_routing_algorithm = business_profile- .routing_algorithm- .clone()- .and_then(|ra| {- ra.parse_value::<api::routing::RoutingAlgorithmRef>("RoutingAlgorithmRef")- .ok()- })- .and_then(|algorithm_ref| algorithm_ref.algorithm_id)- .is_some();+ let has_active_routing_algorithm = profile_has_active_routing_algorithm(business_profile);// A cut-over profile's rules live on the Decision Engine, so a missing Hyperswitch// algorithm is the normal state and must not skip evaluation; for every other profile@@ -3132,7 +3139,8 @@ pub async fn perform_session_flow_routing(// Not cut over, the evaluation is shadow-only and off the request path.let collect_shadow_entries = !de_routing_effective&& session_input.state.conf.open_router.static_routing_enabled- && session_input.state.conf.open_router.shadow_routing_enabled;+ && session_input.state.conf.open_router.shadow_routing_enabled+ && profile_has_active_routing_algorithm(business_profile);// Same list for every wallet type, so it is fetched once rather than per iteration.let de_fallback_config = if de_routing_effective || collect_shadow_entries {diff --git a/crates/router/src/core/payments/routing/utils.rs b/crates/router/src/core/payments/routing/utils.rsindex 44fa1744e9..4a2d0fc7d7 100644--- a/crates/router/src/core/payments/routing/utils.rs+++ b/crates/router/src/core/payments/routing/utils.rs@@ -106,6 +106,7 @@ enum DecisionEngineEndpoint {DecideGateway,UpdateGatewayScore,RoutingEvaluate,+ RoutingEvaluateBatch,RoutingHybrid,RoutingCreate,RoutingActivate,@@ -119,6 +120,7 @@ impl DecisionEngineEndpoint {const DECIDE_GATEWAY_PATH: &'static str = "decide-gateway";const UPDATE_GATEWAY_SCORE_PATH: &'static str = "update-gateway-score";const ROUTING_EVALUATE_PATH: &'static str = "routing/evaluate";+ const ROUTING_EVALUATE_BATCH_PATH: &'static str = "routing/evaluate/batch";const ROUTING_HYBRID_PATH: &'static str = "routing/hybrid";const ROUTING_CREATE_PATH: &'static str = "routing/create";const ROUTING_ACTIVATE_PATH: &'static str = "routing/activate";@@ -129,6 +131,7 @@ impl DecisionEngineEndpoint {const DECIDE_GATEWAY_LABEL: &'static str = "decide_gateway";const UPDATE_GATEWAY_SCORE_LABEL: &'static str = "update_gateway_score";const ROUTING_EVALUATE_LABEL: &'static str = "routing_evaluate";+ const ROUTING_EVALUATE_BATCH_LABEL: &'static str = "routing_evaluate_batch";const ROUTING_HYBRID_LABEL: &'static str = "routing_hybrid";const ROUTING_CREATE_LABEL: &'static str = "routing_create";const ROUTING_ACTIVATE_LABEL: &'static str = "routing_activate";@@ -142,6 +145,7 @@ impl DecisionEngineEndpoint {match path {Self::DECIDE_GATEWAY_PATH => Self::DecideGateway,Self::UPDATE_GATEWAY_SCORE_PATH => Self::UpdateGatewayScore,+ Self::ROUTING_EVALUATE_BATCH_PATH => Self::RoutingEvaluateBatch,Self::ROUTING_EVALUATE_PATH => Self::RoutingEvaluate,Self::ROUTING_HYBRID_PATH => Self::RoutingHybrid,Self::ROUTING_CREATE_PATH => Self::RoutingCreate,@@ -158,6 +162,7 @@ impl DecisionEngineEndpoint {Self::DecideGateway => Self::DECIDE_GATEWAY_LABEL,Self::UpdateGatewayScore => Self::UPDATE_GATEWAY_SCORE_LABEL,Self::RoutingEvaluate => Self::ROUTING_EVALUATE_LABEL,+ Self::RoutingEvaluateBatch => Self::ROUTING_EVALUATE_BATCH_LABEL,Self::RoutingHybrid => Self::ROUTING_HYBRID_LABEL,Self::RoutingCreate => Self::ROUTING_CREATE_LABEL,Self::RoutingActivate => Self::ROUTING_ACTIVATE_LABEL,@@ -1421,6 +1426,11 @@ pub async fn decision_engine_routing_batch(algorithm_for: TransactionType,routing_flow: RoutingFlow,) -> RoutingResult<Vec<Vec<RoutableConnectorChoice>>> {+ // Callers build one entry per payment method type, so a card-only profile has none.+ if backend_inputs.is_empty() {+ return Ok(Vec::new());+ }+let expected_len = backend_inputs.len();let created_by = business_profile.get_id().get_string_repr().to_string();let fallback_output = convert_fallback_to_de_choices(merchant_fallback_config);