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 4 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 @@ -478,6 +478,9 @@ where
.await
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Could not decode the conditional config")?;

logger::debug!(decision_manager_output=?output, "Decision Manager output after execution");

payment_data.payment_attempt.authentication_type = payment_data
.payment_attempt
.authentication_type
Expand Down Expand Up @@ -2595,6 +2598,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 @@ -2654,6 +2659,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 @@ -2854,6 +2861,8 @@ pub async fn route_connector_v1<F>(
where
F: Send + Clone,
{
logger::debug!("Routing: Initiating routing via profile config");

let routing_algorithm = if cfg!(feature = "business_profile_routing") {
business_profile.routing_algorithm.clone()
} else {
Expand Down
29 changes: 28 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,14 @@ 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: no active routing algorithm, fallback to profile default config"
);
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 +299,7 @@ async fn ensure_algorithm_cached_v1(
.attach_printable("Error checking expiry of DSL in cache")?;

if !present || expired {
logger::debug!("Routing: Routing algorithm record not available in routing cache or expired, initiating refresh...");
refresh_routing_cache_v1(
state,
key.clone(),
Expand Down Expand Up @@ -335,6 +341,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 +494,7 @@ pub async fn get_merchant_kgraph<'a>(
.attach_printable("when checking kgraph expiry")?;

if !kgraph_present || kgraph_expired {
logger::debug!("Routing: profile kgraph record not available in kgraph cache or expired, initiating refresh");
refresh_kgraph_cache(
state,
key_store,
Expand Down Expand Up @@ -634,6 +643,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 +684,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 for fallback connectors");

let mut final_selection = perform_eligibility_analysis(
state,
key_store,
Expand All @@ -686,6 +698,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 +730,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 +961,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 +997,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