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): make DE diff counter a lifetime total and add a reset API (#13599)
Prajjwal Kumareed9cb7acb26
diff --git a/crates/router/src/core/payments/routing/utils.rs b/crates/router/src/core/payments/routing/utils.rsindex 5c35115300..9ac75a30b1 100644--- a/crates/router/src/core/payments/routing/utils.rs+++ b/crates/router/src/core/payments/routing/utils.rs@@ -1126,6 +1126,26 @@ fn de_diff_count_key(profile_id: &id_type::ProfileId) -> String {)}+/// Clears the per-profile routing diff counter, releasing the kill-switch overlay (reset API).+pub async fn reset_de_diff_counter(+ state: &SessionState,+ profile_id: &id_type::ProfileId,+) -> errors::RouterResult<()> {+ let redis_conn = state+ .store+ .get_redis_conn()+ .change_context(errors::ApiErrorResponse::InternalServerError)+ .attach_printable("failed to get redis connection to reset routing diff counter")?;++ redis_conn+ .delete_key(&de_diff_count_key(profile_id).as_str().into())+ .await+ .change_context(errors::ApiErrorResponse::InternalServerError)+ .attach_printable("failed to delete routing diff counter key")?;++ Ok(())+}+/// Counts a non-volume DE-vs-HS diff and cuts the profile over to Hyperswitch at the threshold.pub async fn record_de_diff_and_maybe_trip_kill_switch(state: &SessionState,diff --git a/crates/router/src/core/routing.rs b/crates/router/src/core/routing.rsindex d5b533e475..2400ed4986 100644--- a/crates/router/src/core/routing.rs+++ b/crates/router/src/core/routing.rs@@ -2531,6 +2531,22 @@ impl RoutableConnectors {}}+/// Clears the Decision Engine routing diff kill-switch counter for a profile, so the switch can+/// trip again after the profile is re-enabled for the Decision Engine.+pub async fn reset_decision_engine_diff_counter(+ state: SessionState,+ profile_id: common_utils::id_type::ProfileId,+) -> RouterResult<service_api::ApplicationResponse<()>> {+ reset_de_diff_counter(&state, &profile_id).await?;++ router_env::logger::info!(+ profile_id=?profile_id.get_string_repr(),+ "decision_engine_euclid: routing diff counter reset via api"+ );++ Ok(service_api::ApplicationResponse::StatusOk)+}+pub async fn migrate_rules_for_profile(state: SessionState,processor: domain::Processor,diff --git a/crates/router/src/routes/app.rs b/crates/router/src/routes/app.rsindex ed92ff39bc..a77988809b 100644--- a/crates/router/src/routes/app.rs+++ b/crates/router/src/routes/app.rs@@ -1170,6 +1170,10 @@ impl Routing {let mut route = web::scope("/routing").app_data(web::Data::new(state.clone())).service(web::resource("/entry").route(web::post().to(routing::routing_entry)))+ .service(+ web::resource("/decision-engine/{profile_id}/diff-counter")+ .route(web::delete().to(routing::reset_decision_engine_diff_counter)),+ ).service(web::resource("/active").route(web::get().to(|state, req, query_params| {routing::routing_retrieve_linked_config(state, req, query_params, None)diff --git a/crates/router/src/routes/lock_utils.rs b/crates/router/src/routes/lock_utils.rsindex daee35a438..a50f7ab878 100644--- a/crates/router/src/routes/lock_utils.rs+++ b/crates/router/src/routes/lock_utils.rs@@ -87,6 +87,7 @@ impl From<Flow> for ApiIdentifier {| Flow::UpdateDynamicRoutingConfigs| Flow::DecisionManagerUpsertConfig| Flow::RoutingEvaluateRule+ | Flow::DecisionEngineDiffCounterReset| Flow::DecisionEngineRuleMigration| Flow::VolumeSplitOnRoutingType| Flow::DecisionEngineDecideGatewayCalldiff --git a/crates/router/src/routes/routing.rs b/crates/router/src/routes/routing.rsindex bac12a9875..bf4622c8e6 100644--- a/crates/router/src/routes/routing.rs+++ b/crates/router/src/routes/routing.rs@@ -1748,6 +1748,26 @@ pub async fn migrate_routing_rules_for_profile(.await}+#[instrument(skip_all, fields(flow = ?Flow::DecisionEngineDiffCounterReset))]+pub async fn reset_decision_engine_diff_counter(+ state: web::Data<AppState>,+ req: HttpRequest,+ path: web::Path<common_utils::id_type::ProfileId>,+) -> impl Responder {+ let flow = Flow::DecisionEngineDiffCounterReset;+ let profile_id = path.into_inner();+ Box::pin(oss_api::server_wrap(+ flow,+ state,+ &req,+ profile_id.clone(),+ |state, _, profile_id, _| routing::reset_decision_engine_diff_counter(state, profile_id),+ &auth::AdminApiAuth,+ api_locking::LockAction::NotApplicable,+ ))+ .await+}+async fn get_merchant_account(state: &super::SessionState,merchant_id: &common_utils::id_type::MerchantId,diff --git a/crates/router_env/src/logger/types.rs b/crates/router_env/src/logger/types.rsindex 5ac49efa7a..1571be6fd5 100644--- a/crates/router_env/src/logger/types.rs+++ b/crates/router_env/src/logger/types.rs@@ -659,6 +659,8 @@ pub enum Flow {VolumeSplitOnRoutingType,/// Routing evaluate rule flowRoutingEvaluateRule,+ /// Reset the Decision Engine routing diff kill-switch counter for a profile+ DecisionEngineDiffCounterReset,/// Relay flowRelay,/// Relay retrieve flow