refactor(euclid): log refactors for dynamic routing (#6052)

Co-authored-by: Aprabhat19 <amishaprabhat@gmail.com>
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
Co-authored-by: Amisha Prabhat <55580080+Aprabhat19@users.noreply.github.com>
Co-authored-by: Chethan Rao <70657455+Chethan-rao@users.noreply.github.com>
This commit is contained in:
Prajjwal Kumar
2024-09-26 22:01:48 +05:30
committed by GitHub
parent cfcf9187b9
commit 7e03da7578
4 changed files with 70 additions and 51 deletions

View File

@ -594,13 +594,8 @@ pub async fn refresh_success_based_routing_cache(
pub async fn fetch_success_based_routing_configs(
state: &SessionState,
business_profile: &domain::Profile,
dynamic_routing_algorithm: serde_json::Value,
) -> RouterResult<routing_types::SuccessBasedRoutingConfig> {
let dynamic_routing_algorithm = business_profile.dynamic_routing_algorithm.clone().ok_or(
errors::ApiErrorResponse::GenericNotFoundError {
message: "unable to find dynamic_routing_algorithm in business profile".to_string(),
},
)?;
let dynamic_routing_algorithm_ref = dynamic_routing_algorithm
.parse_value::<routing_types::DynamicRoutingAlgorithmRef>("DynamicRoutingAlgorithmRef")
.change_context(errors::ApiErrorResponse::InternalServerError)
@ -613,8 +608,12 @@ pub async fn fetch_success_based_routing_configs(
.to_string(),
})?
.algorithm_id
// error can be possible when the feature is toggled off.
.ok_or(errors::ApiErrorResponse::GenericNotFoundError {
message: "unable to find algorithm id in success based algorithm config".to_string(),
message: format!(
"unable to find algorithm_id in success based algorithm config as the feature is disabled for profile_id: {}",
business_profile.get_id().get_string_repr()
),
})?;
let key = format!(
@ -658,6 +657,7 @@ pub async fn push_metrics_for_success_based_routing(
payment_attempt: &storage::PaymentAttempt,
routable_connectors: Vec<routing_types::RoutableConnectorChoice>,
business_profile: &domain::Profile,
dynamic_routing_algorithm: serde_json::Value,
) -> RouterResult<()> {
let client = state
.grpc_client
@ -675,10 +675,10 @@ pub async fn push_metrics_for_success_based_routing(
)?;
let success_based_routing_configs =
fetch_success_based_routing_configs(state, business_profile)
fetch_success_based_routing_configs(state, business_profile, dynamic_routing_algorithm)
.await
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("unable to retrieve success_rate configs")?;
.attach_printable("unable to retrieve success_rate based dynamic routing configs")?;
let tenant_business_profile_id = format!(
"{}:{}",
@ -749,41 +749,35 @@ pub async fn push_metrics_for_success_based_routing(
"currency",
payment_attempt
.currency
.ok_or(errors::ApiErrorResponse::InternalServerError)
.attach_printable("payment currency not found in payment_attempt")?
.to_string(),
.map_or_else(|| "None".to_string(), |currency| currency.to_string()),
),
(
"payment_method",
payment_attempt
.payment_method
.ok_or(errors::ApiErrorResponse::InternalServerError)
.attach_printable("payment method not found in payment_attempt")?
.to_string(),
payment_attempt.payment_method.map_or_else(
|| "None".to_string(),
|payment_method| payment_method.to_string(),
),
),
(
"payment_method_type",
payment_attempt
.payment_method_type
.ok_or(errors::ApiErrorResponse::InternalServerError)
.attach_printable("payment method type not found in payment_attempt")?
.to_string(),
payment_attempt.payment_method_type.map_or_else(
|| "None".to_string(),
|payment_method_type| payment_method_type.to_string(),
),
),
(
"capture_method",
payment_attempt
.capture_method
.ok_or(errors::ApiErrorResponse::InternalServerError)
.attach_printable("capture method not found in payment_attempt")?
.to_string(),
payment_attempt.capture_method.map_or_else(
|| "None".to_string(),
|capture_method| capture_method.to_string(),
),
),
(
"authentication_type",
payment_attempt
.authentication_type
.ok_or(errors::ApiErrorResponse::InternalServerError)
.attach_printable("authentication type not found in payment_attempt")?
.to_string(),
payment_attempt.authentication_type.map_or_else(
|| "None".to_string(),
|authentication_type| authentication_type.to_string(),
),
),
("payment_status", payment_attempt.status.to_string()),
("conclusive_classification", outcome.to_string()),