Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(routing): Added logs for routing #3097

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions crates/router/src/core/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,9 @@ where
.await
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Could not decode the conditional config")?;

logger::debug!(ConditionalConfigs=?output, "Conditional Config after dsl execute");
Sarthak1799 marked this conversation as resolved.
Show resolved Hide resolved

payment_data.payment_attempt.authentication_type = payment_data
.payment_attempt
.authentication_type
Expand Down Expand Up @@ -2532,6 +2535,8 @@ where
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Failed execution of straight through routing")?;

logger::debug!(routable_connector_choice=?connectors, "Routing: Initiating Straight through routing (from request) with list of connectors: ");

if check_eligibility {
connectors = routing::perform_eligibility_analysis_with_fallback(
&state.clone(),
Expand Down Expand Up @@ -2591,6 +2596,8 @@ where
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Failed execution of straight through routing")?;

logger::debug!(routable_connector_choice=?connectors, "Routing: Initiating Straight through routing (fallback to DB) with list of connectors: ");

if check_eligibility {
connectors = routing::perform_eligibility_analysis_with_fallback(
&state,
Expand Down Expand Up @@ -2791,6 +2798,8 @@ pub async fn route_connector_v1<F>(
where
F: Send + Clone,
{
logger::debug!("Routing: Initiating routing via merchant config");
Sarthak1799 marked this conversation as resolved.
Show resolved Hide resolved

let routing_algorithm = if cfg!(feature = "business_profile_routing") {
business_profile.routing_algorithm.clone()
} else {
Expand Down
27 changes: 26 additions & 1 deletion crates/router/src/core/payments/routing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,12 @@ pub async fn perform_static_routing_v1<F: Clone>(
algorithm_ref: routing_types::RoutingAlgorithmRef,
payment_data: &mut payments_oss::PaymentData<F>,
) -> RoutingResult<Vec<routing_types::RoutableConnectorChoice>> {
logger::debug!("Routing: Initiating Static Routing...");

let algorithm_id = if let Some(id) = algorithm_ref.algorithm_id {
id
} else {
logger::debug!("StaticRouting: fallback to merchant default config");
Sarthak1799 marked this conversation as resolved.
Show resolved Hide resolved
let fallback_config = routing_helpers::get_merchant_default_config(
&*state.clone().store,
#[cfg(not(feature = "profile_specific_fallback_routing"))]
Expand Down Expand Up @@ -294,6 +297,7 @@ async fn ensure_algorithm_cached_v1(
.attach_printable("Error checking expiry of DSL in cache")?;

if !present || expired {
logger::debug!("Routing: Routing cache not present or expired, initiating refresh...");
Sarthak1799 marked this conversation as resolved.
Show resolved Hide resolved
refresh_routing_cache_v1(
state,
key.clone(),
Expand Down Expand Up @@ -335,6 +339,8 @@ fn execute_dsl_and_get_connector_v1(
backend_input: dsl_inputs::BackendInput,
interpreter: &backend::VirInterpreterBackend<ConnectorSelection>,
) -> RoutingResult<Vec<routing_types::RoutableConnectorChoice>> {
logger::debug!("Routing: Initiating DSL execution");

let routing_output: routing_types::RoutingAlgorithm = interpreter
.execute(backend_input)
.map(|out| out.connector_selection.foreign_into())
Expand Down Expand Up @@ -486,6 +492,7 @@ pub async fn get_merchant_kgraph<'a>(
.attach_printable("when checking kgraph expiry")?;

if !kgraph_present || kgraph_expired {
logger::debug!("Routing: kgraph cache not present or expired, initiating refresh");
Sarthak1799 marked this conversation as resolved.
Show resolved Hide resolved
refresh_kgraph_cache(
state,
key_store,
Expand Down Expand Up @@ -634,6 +641,7 @@ pub async fn perform_fallback_routing<F: Clone>(
eligible_connectors: Option<&Vec<api_enums::RoutableConnectors>>,
#[cfg(feature = "business_profile_routing")] profile_id: Option<String>,
) -> RoutingResult<Vec<routing_types::RoutableConnectorChoice>> {
logger::debug!("Routing: Initiating fallback routing");
let fallback_config = routing_helpers::get_merchant_default_config(
&*state.store,
#[cfg(not(feature = "profile_specific_fallback_routing"))]
Expand Down Expand Up @@ -674,6 +682,8 @@ pub async fn perform_eligibility_analysis_with_fallback<F: Clone>(
eligible_connectors: Option<Vec<api_enums::RoutableConnectors>>,
#[cfg(feature = "business_profile_routing")] profile_id: Option<String>,
) -> RoutingResult<Vec<routing_types::RoutableConnectorChoice>> {
logger::debug!("Routing: Initiating eligibility analysis");
Sarthak1799 marked this conversation as resolved.
Show resolved Hide resolved

let mut final_selection = perform_eligibility_analysis(
state,
key_store,
Expand All @@ -686,6 +696,12 @@ pub async fn perform_eligibility_analysis_with_fallback<F: Clone>(
)
.await?;

let selected_connectors = final_selection
.iter()
.map(|item| item.connector)
.collect::<Vec<_>>();
logger::debug!(final_selected_connectors_before_fallback=?selected_connectors, "List of final selected connectors before fallback");

let fallback_selection = perform_fallback_routing(
state,
key_store,
Expand All @@ -712,7 +728,8 @@ pub async fn perform_eligibility_analysis_with_fallback<F: Clone>(
.iter()
.map(|item| item.connector)
.collect::<Vec<_>>();
logger::debug!(final_selected_connectors_for_routing=?final_selected_connectors, "List of final selected connectors for routing");

logger::debug!(final_selected_connectors_for_routing=?final_selected_connectors, "List of final selected connectors for routing after fallback");

Ok(final_selection)
}
Expand Down Expand Up @@ -942,6 +959,12 @@ async fn perform_session_routing_for_pm_type(
)
.await?;

let selected_connectors = final_selection
.iter()
.map(|item| item.connector)
.collect::<Vec<_>>();
logger::debug!(final_selected_connectors_before_fallback=?selected_connectors, "List of final selected connectors for session after filtering");

if final_selection.is_empty() {
let fallback = routing_helpers::get_merchant_default_config(
&*session_pm_input.state.clone().store,
Expand Down Expand Up @@ -972,6 +995,8 @@ async fn perform_session_routing_for_pm_type(
.await?;
}

logger::debug!(selected_connectors_for_routing=?final_selection, "List of selected connectors for session after fallback");

let mut final_choice: Option<(api::ConnectorData, Option<String>)> = None;

for selection in final_selection {
Expand Down
Loading