Skip to content

Commit bab64ee

Browse files
authored
refactor(open_router): call elimination routing of open router if enabled instead of dynamo (#7961)
1 parent 2cefac5 commit bab64ee

File tree

6 files changed

+213
-171
lines changed

6 files changed

+213
-171
lines changed

crates/api_models/src/routing.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,17 @@ impl DynamicRoutingAlgorithmRef {
643643
self.dynamic_routing_volume_split = volume
644644
}
645645

646+
pub fn is_success_rate_routing_enabled(&self) -> bool {
647+
self.success_based_algorithm
648+
.as_ref()
649+
.map(|success_based_routing| {
650+
success_based_routing.enabled_feature
651+
== DynamicRoutingFeatures::DynamicConnectorSelection
652+
|| success_based_routing.enabled_feature == DynamicRoutingFeatures::Metrics
653+
})
654+
.unwrap_or_default()
655+
}
656+
646657
pub fn is_elimination_enabled(&self) -> bool {
647658
self.elimination_routing_algorithm
648659
.as_ref()

crates/router/src/core/errors.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -419,8 +419,8 @@ pub enum RoutingError {
419419
ContractRoutingClientInitializationError,
420420
#[error("Invalid contract based connector label received from dynamic routing service: '{0}'")]
421421
InvalidContractBasedConnectorLabel(String),
422-
#[error("Failed to perform {algo} in open_router")]
423-
OpenRouterCallFailed { algo: String },
422+
#[error("Failed to perform routing in open_router")]
423+
OpenRouterCallFailed,
424424
#[error("Error from open_router: {0}")]
425425
OpenRouterError(String),
426426
}

crates/router/src/core/payments.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7243,7 +7243,7 @@ where
72437243

72447244
if routing_choice.routing_type.is_dynamic_routing() {
72457245
if state.conf.open_router.enabled {
7246-
routing::perform_open_routing(
7246+
routing::perform_dynamic_routing_with_open_router(
72477247
state,
72487248
connectors.clone(),
72497249
business_profile,
@@ -7285,7 +7285,7 @@ where
72857285
.map(|card_isin| card_isin.to_string()),
72867286
);
72877287

7288-
routing::perform_dynamic_routing(
7288+
routing::perform_dynamic_routing_with_intelligent_router(
72897289
state,
72907290
connectors.clone(),
72917291
business_profile,

crates/router/src/core/payments/operations/payment_response.rs

Lines changed: 42 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2148,36 +2148,49 @@ async fn payment_response_update_tracker<F: Clone, T: types::Capturable>(
21482148
);
21492149
tokio::spawn(
21502150
async move {
2151-
routing_helpers::push_metrics_with_update_window_for_success_based_routing(
2152-
&state,
2153-
&payment_attempt,
2154-
routable_connectors.clone(),
2155-
&profile_id,
2156-
dynamic_routing_algo_ref.clone(),
2157-
dynamic_routing_config_params_interpolator.clone(),
2158-
)
2159-
.await
2160-
.map_err(|e| logger::error!(success_based_routing_metrics_error=?e))
2161-
.ok();
2162-
2163-
if let Some(gsm_error_category) = gsm_error_category {
2164-
if gsm_error_category.should_perform_elimination_routing() {
2165-
logger::info!("Performing update window for elimination routing");
2166-
routing_helpers::update_window_for_elimination_routing(
2167-
&state,
2168-
&payment_attempt,
2169-
&profile_id,
2170-
dynamic_routing_algo_ref.clone(),
2171-
dynamic_routing_config_params_interpolator.clone(),
2172-
gsm_error_category,
2173-
)
2174-
.await
2175-
.map_err(|e| logger::error!(dynamic_routing_metrics_error=?e))
2176-
.ok();
2151+
let should_route_to_open_router = state.conf.open_router.enabled;
2152+
2153+
if should_route_to_open_router {
2154+
routing_helpers::update_gateway_score_helper_with_open_router(
2155+
&state,
2156+
&payment_attempt,
2157+
&profile_id,
2158+
dynamic_routing_algo_ref.clone(),
2159+
)
2160+
.await
2161+
.map_err(|e| logger::error!(open_router_update_gateway_score_err=?e))
2162+
.ok();
2163+
} else {
2164+
routing_helpers::push_metrics_with_update_window_for_success_based_routing(
2165+
&state,
2166+
&payment_attempt,
2167+
routable_connectors.clone(),
2168+
&profile_id,
2169+
dynamic_routing_algo_ref.clone(),
2170+
dynamic_routing_config_params_interpolator.clone(),
2171+
)
2172+
.await
2173+
.map_err(|e| logger::error!(success_based_routing_metrics_error=?e))
2174+
.ok();
2175+
2176+
if let Some(gsm_error_category) = gsm_error_category {
2177+
if gsm_error_category.should_perform_elimination_routing() {
2178+
logger::info!("Performing update window for elimination routing");
2179+
routing_helpers::update_window_for_elimination_routing(
2180+
&state,
2181+
&payment_attempt,
2182+
&profile_id,
2183+
dynamic_routing_algo_ref.clone(),
2184+
dynamic_routing_config_params_interpolator.clone(),
2185+
gsm_error_category,
2186+
)
2187+
.await
2188+
.map_err(|e| logger::error!(dynamic_routing_metrics_error=?e))
2189+
.ok();
2190+
};
21772191
};
2178-
};
21792192

2180-
routing_helpers::push_metrics_with_update_window_for_contract_based_routing(
2193+
routing_helpers::push_metrics_with_update_window_for_contract_based_routing(
21812194
&state,
21822195
&payment_attempt,
21832196
routable_connectors,
@@ -2188,6 +2201,7 @@ async fn payment_response_update_tracker<F: Clone, T: types::Capturable>(
21882201
.await
21892202
.map_err(|e| logger::error!(contract_based_routing_metrics_error=?e))
21902203
.ok();
2204+
}
21912205
}
21922206
.in_current_span(),
21932207
);

0 commit comments

Comments
 (0)