mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-28 04:04:55 +08:00
feat(routing): Add audit trail for routing (#8188)
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
@ -25,6 +25,7 @@ pub mod outgoing_webhook_event;
|
||||
pub mod payment_intents;
|
||||
pub mod payments;
|
||||
pub mod refunds;
|
||||
pub mod routing_events;
|
||||
pub mod sdk_events;
|
||||
pub mod search;
|
||||
|
||||
|
||||
6
crates/api_models/src/analytics/routing_events.rs
Normal file
6
crates/api_models/src/analytics/routing_events.rs
Normal file
@ -0,0 +1,6 @@
|
||||
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
|
||||
pub struct RoutingEventsRequest {
|
||||
pub payment_id: common_utils::id_type::PaymentId,
|
||||
pub refund_id: Option<String>,
|
||||
pub dispute_id: Option<String>,
|
||||
}
|
||||
@ -29,7 +29,8 @@ use crate::{
|
||||
admin::*,
|
||||
analytics::{
|
||||
api_event::*, auth_events::*, connector_events::ConnectorEventsRequest,
|
||||
outgoing_webhook_event::OutgoingWebhookLogsRequest, sdk_events::*, search::*, *,
|
||||
outgoing_webhook_event::OutgoingWebhookLogsRequest, routing_events::RoutingEventsRequest,
|
||||
sdk_events::*, search::*, *,
|
||||
},
|
||||
api_keys::*,
|
||||
cards_info::*,
|
||||
@ -142,7 +143,8 @@ impl_api_event_type!(
|
||||
OrganizationCreateRequest,
|
||||
OrganizationUpdateRequest,
|
||||
OrganizationId,
|
||||
CustomerListRequest
|
||||
CustomerListRequest,
|
||||
RoutingEventsRequest
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
@ -1046,7 +1046,7 @@ pub struct CurrentBlockThreshold {
|
||||
pub max_total_count: Option<u64>,
|
||||
}
|
||||
|
||||
#[derive(serde::Serialize, serde::Deserialize, Debug, Default, Clone, ToSchema)]
|
||||
#[derive(serde::Serialize, serde::Deserialize, Debug, Default, Clone, Copy, ToSchema)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum SuccessRateSpecificityLevel {
|
||||
#[default]
|
||||
@ -1283,3 +1283,247 @@ impl RoutableConnectorChoiceWithBucketName {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub struct CalSuccessRateConfigEventRequest {
|
||||
pub min_aggregates_size: Option<u32>,
|
||||
pub default_success_rate: Option<f64>,
|
||||
pub specificity_level: SuccessRateSpecificityLevel,
|
||||
pub exploration_percent: Option<f64>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub struct CalSuccessRateEventRequest {
|
||||
pub id: String,
|
||||
pub params: String,
|
||||
pub labels: Vec<String>,
|
||||
pub config: Option<CalSuccessRateConfigEventRequest>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub struct EliminationRoutingEventBucketConfig {
|
||||
pub bucket_size: Option<u64>,
|
||||
pub bucket_leak_interval_in_secs: Option<u64>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub struct EliminationRoutingEventRequest {
|
||||
pub id: String,
|
||||
pub params: String,
|
||||
pub labels: Vec<String>,
|
||||
pub config: Option<EliminationRoutingEventBucketConfig>,
|
||||
}
|
||||
|
||||
/// API-1 types
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub struct CalContractScoreEventRequest {
|
||||
pub id: String,
|
||||
pub params: String,
|
||||
pub labels: Vec<String>,
|
||||
pub config: Option<ContractBasedRoutingConfig>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub struct LabelWithScoreEventResponse {
|
||||
pub score: f64,
|
||||
pub label: String,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub struct CalSuccessRateEventResponse {
|
||||
pub labels_with_score: Vec<LabelWithScoreEventResponse>,
|
||||
pub routing_apporach: RoutingApproach,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum RoutingApproach {
|
||||
Exploitation,
|
||||
Exploration,
|
||||
Elimination,
|
||||
ContractBased,
|
||||
Default,
|
||||
}
|
||||
|
||||
impl RoutingApproach {
|
||||
pub fn from_decision_engine_approach(approach: &str) -> Self {
|
||||
match approach {
|
||||
"SR_SELECTION_V3_ROUTING" => Self::Exploitation,
|
||||
"SR_V3_HEDGING" => Self::Exploration,
|
||||
_ => Self::Default,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for RoutingApproach {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
Self::Exploitation => write!(f, "Exploitation"),
|
||||
Self::Exploration => write!(f, "Exploration"),
|
||||
Self::Elimination => write!(f, "Elimination"),
|
||||
Self::ContractBased => write!(f, "ContractBased"),
|
||||
Self::Default => write!(f, "Default"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub struct BucketInformationEventResponse {
|
||||
pub is_eliminated: bool,
|
||||
pub bucket_name: Vec<String>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub struct EliminationInformationEventResponse {
|
||||
pub entity: Option<BucketInformationEventResponse>,
|
||||
pub global: Option<BucketInformationEventResponse>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub struct LabelWithStatusEliminationEventResponse {
|
||||
pub label: String,
|
||||
pub elimination_information: Option<EliminationInformationEventResponse>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub struct EliminationEventResponse {
|
||||
pub labels_with_status: Vec<LabelWithStatusEliminationEventResponse>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub struct ScoreDataEventResponse {
|
||||
pub score: f64,
|
||||
pub label: String,
|
||||
pub current_count: u64,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub struct CalContractScoreEventResponse {
|
||||
pub labels_with_score: Vec<ScoreDataEventResponse>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub struct CalGlobalSuccessRateConfigEventRequest {
|
||||
pub entity_min_aggregates_size: u32,
|
||||
pub entity_default_success_rate: f64,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub struct CalGlobalSuccessRateEventRequest {
|
||||
pub entity_id: String,
|
||||
pub entity_params: String,
|
||||
pub entity_labels: Vec<String>,
|
||||
pub global_labels: Vec<String>,
|
||||
pub config: Option<CalGlobalSuccessRateConfigEventRequest>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub struct UpdateSuccessRateWindowConfig {
|
||||
pub max_aggregates_size: Option<u32>,
|
||||
pub current_block_threshold: Option<CurrentBlockThreshold>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub struct UpdateLabelWithStatusEventRequest {
|
||||
pub label: String,
|
||||
pub status: bool,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub struct UpdateSuccessRateWindowEventRequest {
|
||||
pub id: String,
|
||||
pub params: String,
|
||||
pub labels_with_status: Vec<UpdateLabelWithStatusEventRequest>,
|
||||
pub config: Option<UpdateSuccessRateWindowConfig>,
|
||||
pub global_labels_with_status: Vec<UpdateLabelWithStatusEventRequest>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub struct UpdateSuccessRateWindowEventResponse {
|
||||
pub status: UpdationStatusEventResponse,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum UpdationStatusEventResponse {
|
||||
WindowUpdationSucceeded,
|
||||
WindowUpdationFailed,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub struct LabelWithBucketNameEventRequest {
|
||||
pub label: String,
|
||||
pub bucket_name: String,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub struct UpdateEliminationBucketEventRequest {
|
||||
pub id: String,
|
||||
pub params: String,
|
||||
pub labels_with_bucket_name: Vec<LabelWithBucketNameEventRequest>,
|
||||
pub config: Option<EliminationRoutingEventBucketConfig>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub struct UpdateEliminationBucketEventResponse {
|
||||
pub status: EliminationUpdationStatusEventResponse,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum EliminationUpdationStatusEventResponse {
|
||||
BucketUpdationSucceeded,
|
||||
BucketUpdationFailed,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub struct ContractLabelInformationEventRequest {
|
||||
pub label: String,
|
||||
pub target_count: u64,
|
||||
pub target_time: u64,
|
||||
pub current_count: u64,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub struct UpdateContractRequestEventRequest {
|
||||
pub id: String,
|
||||
pub params: String,
|
||||
pub labels_information: Vec<ContractLabelInformationEventRequest>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub struct UpdateContractEventResponse {
|
||||
pub status: ContractUpdationStatusEventResponse,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum ContractUpdationStatusEventResponse {
|
||||
ContractUpdationSucceeded,
|
||||
ContractUpdationFailed,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user