From c72d365fdeac13e3aa65b4c3d1f876b9c419168e Mon Sep 17 00:00:00 2001 From: Chethan Rao <70657455+Chethan-rao@users.noreply.github.com> Date: Fri, 13 Jun 2025 12:02:49 +0530 Subject: [PATCH] refactor(dynamic_routing): add support for shuffle on tie flag to success_based routing (#8241) Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com> --- api-reference-v2/openapi_spec.json | 4 ++++ .../hyperswitch_intelligent_router_open_api_spec.yml | 1 + api-reference/openapi_spec.json | 4 ++++ crates/api_models/src/routing.rs | 5 +++++ .../src/grpc_client/dynamic_routing/success_rate_client.rs | 1 + proto/success_rate.proto | 5 +++-- 6 files changed, 18 insertions(+), 2 deletions(-) diff --git a/api-reference-v2/openapi_spec.json b/api-reference-v2/openapi_spec.json index f126039079..cfe8027c87 100644 --- a/api-reference-v2/openapi_spec.json +++ b/api-reference-v2/openapi_spec.json @@ -23862,6 +23862,10 @@ "type": "number", "format": "double", "nullable": true + }, + "shuffle_on_tie_during_exploitation": { + "type": "boolean", + "nullable": true } } }, diff --git a/api-reference/hyperswitch_intelligent_router_open_api_spec.yml b/api-reference/hyperswitch_intelligent_router_open_api_spec.yml index 7372a083b8..c3c1d3458c 100644 --- a/api-reference/hyperswitch_intelligent_router_open_api_spec.yml +++ b/api-reference/hyperswitch_intelligent_router_open_api_spec.yml @@ -45,6 +45,7 @@ paths: default_success_rate: 0.95 specificity_level: ENTITY exploration_percent: 20.0 + shuffle_on_tie_during_exploitation: true responses: "200": description: Success rate calculated successfully diff --git a/api-reference/openapi_spec.json b/api-reference/openapi_spec.json index d12b7b3be1..7bb7f3b382 100644 --- a/api-reference/openapi_spec.json +++ b/api-reference/openapi_spec.json @@ -28802,6 +28802,10 @@ "type": "number", "format": "double", "nullable": true + }, + "shuffle_on_tie_during_exploitation": { + "type": "boolean", + "nullable": true } } }, diff --git a/crates/api_models/src/routing.rs b/crates/api_models/src/routing.rs index ed1915764c..aea14c23fe 100644 --- a/crates/api_models/src/routing.rs +++ b/crates/api_models/src/routing.rs @@ -1016,6 +1016,7 @@ impl Default for SuccessBasedRoutingConfig { }), specificity_level: SuccessRateSpecificityLevel::default(), exploration_percent: Some(20.0), + shuffle_on_tie_during_exploitation: Some(false), }), decision_engine_configs: None, } @@ -1044,6 +1045,7 @@ pub struct SuccessBasedRoutingConfigBody { #[serde(default)] pub specificity_level: SuccessRateSpecificityLevel, pub exploration_percent: Option, + pub shuffle_on_tie_during_exploitation: Option, } #[derive(serde::Serialize, serde::Deserialize, Debug, Clone, ToSchema)] @@ -1173,6 +1175,9 @@ impl SuccessBasedRoutingConfigBody { if let Some(exploration_percent) = new.exploration_percent { self.exploration_percent = Some(exploration_percent); } + if let Some(shuffle_on_tie_during_exploitation) = new.shuffle_on_tie_during_exploitation { + self.shuffle_on_tie_during_exploitation = Some(shuffle_on_tie_during_exploitation); + } } } diff --git a/crates/external_services/src/grpc_client/dynamic_routing/success_rate_client.rs b/crates/external_services/src/grpc_client/dynamic_routing/success_rate_client.rs index b63f435327..00f3e1f159 100644 --- a/crates/external_services/src/grpc_client/dynamic_routing/success_rate_client.rs +++ b/crates/external_services/src/grpc_client/dynamic_routing/success_rate_client.rs @@ -291,6 +291,7 @@ impl ForeignTryFrom for CalSuccessRateConfig { SuccessRateSpecificityLevel::Global => Some(ProtoSpecificityLevel::Global.into()), }, exploration_percent: config.exploration_percent, + shuffle_on_tie_during_exploitation: config.shuffle_on_tie_during_exploitation, }) } } diff --git a/proto/success_rate.proto b/proto/success_rate.proto index efdd439cac..cdcde99fa8 100644 --- a/proto/success_rate.proto +++ b/proto/success_rate.proto @@ -24,6 +24,7 @@ message CalSuccessRateConfig { double default_success_rate = 2; optional SuccessRateSpecificityLevel specificity_level = 3; optional double exploration_percent = 4; + optional bool shuffle_on_tie_during_exploitation = 5; } enum SuccessRateSpecificityLevel { @@ -78,13 +79,13 @@ message UpdateSuccessRateWindowResponse { UpdationStatus status = 1; } - // API-3 types +// API-3 types message InvalidateWindowsRequest { string id = 1; } message InvalidateWindowsResponse { - enum InvalidationStatus { + enum InvalidationStatus { WINDOW_INVALIDATION_SUCCEEDED = 0; WINDOW_INVALIDATION_FAILED = 1; }