Skip to content

Commit

Permalink
chore: Resolved comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Sarthak1799 committed Dec 17, 2024
1 parent a1732d4 commit 9630a45
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 27 deletions.
26 changes: 13 additions & 13 deletions crates/api_models/src/routing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -513,12 +513,21 @@ pub struct RoutingLinkWrapper {
pub algorithm_id: RoutingAlgorithmId,
}

#[derive(Debug, Default, Clone, serde::Serialize, serde::Deserialize)]
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct DynamicAlgorithmWithTimestamp<T> {
pub algorithm_id: Option<T>,
pub timestamp: i64,
}

impl Default for DynamicAlgorithmWithTimestamp<common_utils::id_type::RoutingId> {
fn default() -> Self {
Self {
algorithm_id: None,
timestamp: common_utils::date_time::now_unix_timestamp(),
}
}
}

#[derive(Debug, Default, Clone, serde::Serialize, serde::Deserialize)]
pub struct DynamicRoutingAlgorithmRef {
pub success_based_algorithm: Option<SuccessBasedAlgorithm>,
Expand Down Expand Up @@ -739,32 +748,23 @@ impl DynamicRoutingAlgorithmRef {
DynamicRoutingType::SuccessRateBasedRouting => {
if let Some(success_based_algo) = &self.success_based_algorithm {
self.success_based_algorithm = Some(SuccessBasedAlgorithm {
algorithm_id_with_timestamp: DynamicAlgorithmWithTimestamp {
algorithm_id: None,
timestamp: common_utils::date_time::now_unix_timestamp(),
},
algorithm_id_with_timestamp: DynamicAlgorithmWithTimestamp::default(),
enabled_feature: success_based_algo.enabled_feature,
});
}
}
DynamicRoutingType::EliminationRouting => {
if let Some(elimination_based_algo) = &self.elimination_routing_algorithm {
self.elimination_routing_algorithm = Some(EliminationRoutingAlgorithm {
algorithm_id_with_timestamp: DynamicAlgorithmWithTimestamp {
algorithm_id: None,
timestamp: common_utils::date_time::now_unix_timestamp(),
},
algorithm_id_with_timestamp: DynamicAlgorithmWithTimestamp::default(),
enabled_feature: elimination_based_algo.enabled_feature,
});
}
}
DynamicRoutingType::ContractBasedRouting => {
if let Some(contract_based_algo) = &self.contract_based_routing {
self.contract_based_routing = Some(ContractRoutingAlgorithm {
algorithm_id_with_timestamp: DynamicAlgorithmWithTimestamp {
algorithm_id: None,
timestamp: common_utils::date_time::now_unix_timestamp(),
},
algorithm_id_with_timestamp: DynamicAlgorithmWithTimestamp::default(),
enabled_feature: contract_based_algo.enabled_feature,
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub enum DynamicRoutingError {
SuccessRateBasedRoutingFailure(String),

/// Error from Dynamic Routing Server while performing contract based routing
#[error("Error from Dynamic Routing Server : {0}")]
#[error("Error from Dynamic Routing Server while performing contract based routing: {0}")]
ContractBasedRoutingFailure(String),
/// Error from Dynamic Routing Server while perfrming elimination
#[error("Error from Dynamic Routing Server while perfrming elimination : {0}")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub mod contract_routing {
tonic::include_proto!("contract_routing");
}
use super::{Client, DynamicRoutingError, DynamicRoutingResult};
/// The trait Success Based Dynamic Routing would have the functions required to support the calculation and updation window
/// The trait ContractBasedDynamicRouting would have the functions required to support the calculation and updation window
#[async_trait::async_trait]
pub trait ContractBasedDynamicRouting: dyn_clone::DynClone + Send + Sync {
/// To calculate the contract scores for the list of chosen connectors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2013,7 +2013,7 @@ async fn payment_response_update_tracker<F: Clone, T: types::Capturable>(
dynamic_routing_config_params_interpolator.clone(),
)
.await
.map_err(|e| logger::error!(dynamic_routing_metrics_error=?e))
.map_err(|e| logger::error!(success_based_routing_metrics_error=?e))
.ok();

routing_helpers::push_metrics_with_update_window_for_contract_based_routing(
Expand All @@ -2024,7 +2024,7 @@ async fn payment_response_update_tracker<F: Clone, T: types::Capturable>(
dynamic_routing_config_params_interpolator,
)
.await
.map_err(|e| logger::error!(dynamic_routing_metrics_error=?e))
.map_err(|e| logger::error!(contract_based_routing_metrics_error=?e))
.ok();
}
.in_current_span(),
Expand Down
2 changes: 1 addition & 1 deletion crates/router/src/core/routing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1681,7 +1681,7 @@ pub async fn contract_based_routing_update_configs(
.invalidate_contracts(prefix_of_dynamic_routing_keys)
.await
.change_context(errors::ApiErrorResponse::GenericNotFoundError {
message: "Failed to invalidate the routing keys".to_string(),
message: "Failed to invalidate the contract based routing keys".to_string(),
})
})
.await
Expand Down
11 changes: 7 additions & 4 deletions crates/router/src/core/routing/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1003,12 +1003,12 @@ pub async fn push_metrics_with_update_window_for_contract_based_routing(
.algorithm_id
.ok_or(errors::ApiErrorResponse::InternalServerError)
.attach_printable(
"success_based_routing_algorithm_id not found in business_profile",
"contract_based_routing_algorithm_id not found in business_profile",
)?,
)
.await
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("unable to retrieve success_rate based dynamic routing configs")?;
.attach_printable("unable to retrieve contract based dynamic routing configs")?;

// check if this id is correct
let tenant_business_profile_id = generate_tenant_business_profile_id(
Expand All @@ -1033,7 +1033,10 @@ pub async fn push_metrics_with_update_window_for_contract_based_routing(
.ok_or(errors::ApiErrorResponse::InternalServerError)
.attach_printable("unable to get LabelInformation from ContractBasedRoutingConfig")?;

logger::debug!("final_label_info - {:?}", final_label_info);
logger::debug!(
"contract based routing: matched LabelInformation - {:?}",
final_label_info
);

let request_label_info = routing_types::LabelInformation {
label: format!(
Expand All @@ -1060,7 +1063,7 @@ pub async fn push_metrics_with_update_window_for_contract_based_routing(
.await
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable(
"unable to update success based routing window in dynamic routing service",
"unable to update contract based routing window in dynamic routing service",
)?;
}

Expand Down
17 changes: 12 additions & 5 deletions crates/router/src/routes/routing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1096,7 +1096,7 @@ pub async fn contract_based_routing_setup_config(
query: web::Query<api_models::routing::ToggleDynamicRoutingQuery>,
json_payload: web::Json<routing_types::ContractBasedRoutingConfig>,
) -> impl Responder {
let flow = Flow::UpdateDynamicRoutingConfigs;
let flow = Flow::ToggleDynamicRouting;
let routing_payload_wrapper = routing_types::ContractBasedRoutingSetupPayloadWrapper {
config: json_payload.into_inner(),
profile_id: path.into_inner().profile_id,
Expand Down Expand Up @@ -1145,14 +1145,14 @@ pub async fn contract_based_routing_update_configs(
let flow = Flow::UpdateDynamicRoutingConfigs;
let routing_payload_wrapper = routing_types::ContractBasedRoutingPayloadWrapper {
updated_config: json_payload.into_inner(),
algorithm_id: path.clone().algorithm_id,
profile_id: path.clone().profile_id,
algorithm_id: path.algorithm_id.clone(),
profile_id: path.profile_id.clone(),
};
Box::pin(oss_api::server_wrap(
flow,
state,
&req,
routing_payload_wrapper,
routing_payload_wrapper.clone(),
|state, _, wrapper: routing_types::ContractBasedRoutingPayloadWrapper, _| async {
Box::pin(routing::contract_based_routing_update_configs(
state,
Expand All @@ -1162,7 +1162,14 @@ pub async fn contract_based_routing_update_configs(
))
.await
},
&auth::AdminApiAuth,
auth::auth_type(
&auth::HeaderAuth(auth::ApiKeyAuth),
&auth::JWTAuthProfileFromRoute {
profile_id: routing_payload_wrapper.profile_id,
required_permission: Permission::ProfileRoutingWrite,
},
req.headers(),
),
api_locking::LockAction::NotApplicable,
))
.await
Expand Down

0 comments on commit 9630a45

Please sign in to comment.