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(euclid): add dynamic routing in core flows #6333

Open
wants to merge 20 commits into
base: main
Choose a base branch
from

Conversation

prajjwalkumar17
Copy link
Contributor

@prajjwalkumar17 prajjwalkumar17 commented Oct 16, 2024

Type of Change

  • Bugfix
  • New feature
  • Enhancement
  • Refactoring
  • Dependency updates
  • Documentation
  • CI/CD

Description

This will add dynamic_routing in core flows.
After which once the toggle route is hit with feature = dynamic_connector_selection, routable connectors will be evaluated on basis of success_based routing.

Additional Changes

  • This PR modifies the API contract
  • This PR modifies the database schema
  • This PR modifies application configuration/environment variables

Motivation and Context

Will enable success_based routing

How did you test it?

The testing flows are as follows:

  1. Toggle the route with feature as dynamic_connector_selection.
curl --location --request POST 'http://localhost:8080/account/merchant_id/business_profile/profile_id/dynamic_routing/success_based/toggle?enable=dynamic_connector_selection' \
--header 'api-key: api_key'
  1. Check the business_profile table for the enabled dynamic routing feature.

Checklist

  • I formatted the code cargo +nightly fmt --all
  • I addressed lints thrown by cargo clippy
  • I reviewed the submitted code
  • I added unit tests for my changes where possible

@prajjwalkumar17 prajjwalkumar17 requested review from a team as code owners October 16, 2024 04:25
Copy link

semanticdiff-com bot commented Oct 16, 2024

Review changes with SemanticDiff.

Analyzed 11 of 11 files.

Overall, the semantic diff is 26% smaller than the GitHub diff.

Filename Status
✔️ crates/router/src/routes/routing.rs Analyzed
✔️ crates/router/src/core/errors.rs Analyzed
✔️ crates/router/src/core/payments.rs Analyzed
✔️ crates/router/src/core/routing.rs 61.67% smaller
✔️ crates/router/src/core/routing/helpers.rs 18.44% smaller
✔️ crates/router/src/core/payments/routing.rs Analyzed
✔️ crates/router/src/core/payments/operations/payment_response.rs 61.7% smaller
✔️ crates/openapi/src/openapi.rs Analyzed
✔️ crates/openapi/src/routes/routing.rs 2.5% smaller
✔️ crates/api_models/src/routing.rs 35.01% smaller
✔️ api-reference/openapi_spec.json Analyzed

@prajjwalkumar17 prajjwalkumar17 marked this pull request as draft October 16, 2024 04:25
@prajjwalkumar17 prajjwalkumar17 linked an issue Oct 16, 2024 that may be closed by this pull request
@prajjwalkumar17 prajjwalkumar17 self-assigned this Oct 16, 2024
@prajjwalkumar17 prajjwalkumar17 added this to the October 2024 Release milestone Oct 16, 2024
@prajjwalkumar17 prajjwalkumar17 added A-routing Area: Routing A-core Area: Core flows C-feature Category: Feature request or enhancement labels Oct 16, 2024
@prajjwalkumar17 prajjwalkumar17 marked this pull request as ready for review October 17, 2024 08:45
@hyperswitch-bot hyperswitch-bot bot added the M-api-contract-changes Metadata: This PR involves API contract changes label Oct 17, 2024
Comment on lines +547 to +552
self.success_based_algorithm = Some(SuccessBasedAlgorithm {
algorithm_id_with_timestamp: DynamicAlgorithmWithTimestamp {
algorithm_id: Some(new_id),
timestamp: common_utils::date_time::now_unix_timestamp(),
},
enabled_feature,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit:
Can use constructor

crates/router/src/core/payments.rs Outdated Show resolved Hide resolved
crates/router/src/core/payments.rs Outdated Show resolved Hide resolved
crates/router/src/core/payments/routing.rs Outdated Show resolved Hide resolved
crates/router/src/core/payments/routing.rs Outdated Show resolved Hide resolved
crates/router/src/core/payments/routing.rs Outdated Show resolved Hide resolved
crates/router/src/core/payments/routing.rs Outdated Show resolved Hide resolved
crates/router/src/core/routing.rs Outdated Show resolved Hide resolved
crates/router/src/core/routing/helpers.rs Outdated Show resolved Hide resolved
crates/router/Cargo.toml Outdated Show resolved Hide resolved
crates/router/src/core/payments.rs Outdated Show resolved Hide resolved
crates/router/src/core/routing.rs Outdated Show resolved Hide resolved
Comment on lines 1321 to 1330
let _ = cache::publish_into_redact_channel(
state.store.get_cache_store().as_ref(),
cache_entries_to_redact,
)
.await
.to_not_found_response(errors::ApiErrorResponse::ResourceIdNotFound)?;
let response = record.foreign_into();
helpers::update_business_profile_active_dynamic_algorithm_ref(
db,
key_manager_state,
&key_store,
business_profile,
dynamic_routing_algorithm,
)
.await?;

metrics::ROUTING_UNLINK_CONFIG_SUCCESS_RESPONSE.add(
&metrics::CONTEXT,
1,
&add_attributes([("profile_id", profile_id.get_string_repr().to_owned())]),
);

Ok(service_api::ApplicationResponse::Json(response))
} else {
Err(errors::ApiErrorResponse::PreconditionFailed {
message: "Algorithm is already inactive".to_string(),
})?
.map_err(|e| {
logger::error!(
"unable to publish into the redact channel for evicting the success based routing config cache {e:?}"
)
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we propagate the error if publishing to cache fails? because core will still get the configs from cache and may perform SR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, propagation seems fine here.

crates/router/src/core/payments/routing.rs Outdated Show resolved Hide resolved
crates/router/src/core/payments/routing.rs Outdated Show resolved Hide resolved
crates/router/src/core/payments/routing.rs Outdated Show resolved Hide resolved
crates/router/src/core/payments/routing.rs Show resolved Hide resolved
crates/router/src/core/payments/routing.rs Outdated Show resolved Hide resolved
crates/router/src/core/payments/routing.rs Outdated Show resolved Hide resolved
@Chethan-rao
Copy link
Contributor

Please add debug logs wherever necessary

NishantJoshi00
NishantJoshi00 previously approved these changes Oct 21, 2024
crates/router/src/core/routing/helpers.rs Outdated Show resolved Hide resolved
@@ -4579,40 +4579,35 @@ where
.await
.change_context(errors::ApiErrorResponse::InternalServerError)?;

let connectors = routing::perform_eligibility_analysis_with_fallback(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see this is adding the fallback as well to the list and this list is getting sent to perform SR. We should only perform eligibility analysis on the connectors and send only these filtered connectors to perform SR instead of adding the fallback too. Fallback connectors should be appended to the list obtained after performing SR

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be addressed in this PR.

crates/router/src/core/routing/helpers.rs Outdated Show resolved Hide resolved
use crate::{core::metrics as core_metrics, routes::metrics};
#[cfg(feature = "v1")]
use crate::{core::metrics as core_metrics, routes::metrics, types::transformers::ForeignInto};
pub const DYNAMIC_ALGORITHM_NAME: &str = "Dynamic routing algorithm";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this a success routing algorithm?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-core Area: Core flows A-routing Area: Routing C-feature Category: Feature request or enhancement M-api-contract-changes Metadata: This PR involves API contract changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Integration of dynamic connector selection in core flows
3 participants