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): Integrate global success rates #6950

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

Conversation

Sarthak1799
Copy link
Contributor

Type of Change

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

Description

Integrate global Success rates for dynamic 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

How did you test it?

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

@Sarthak1799 Sarthak1799 self-assigned this Dec 26, 2024
@Sarthak1799 Sarthak1799 requested review from a team as code owners December 26, 2024 13:46
Copy link

semanticdiff-com bot commented Dec 26, 2024

Review changes with  SemanticDiff

Changed Files
File Status
  crates/router/src/core/payments/routing.rs  90% smaller
  crates/external_services/src/grpc_client/dynamic_routing/success_rate_client.rs  9% smaller
  crates/router/src/core/routing/helpers.rs  3% smaller
  crates/api_models/src/routing.rs  0% smaller
  proto/success_rate.proto Unsupported file format

@@ -809,6 +811,13 @@ pub struct CurrentBlockThreshold {
pub max_total_count: Option<u64>,
}

#[derive(serde::Serialize, serde::Deserialize, Debug, Default, Clone, ToSchema)]
pub enum SuccessRateSpecificityLevel {
Copy link
Contributor

Choose a reason for hiding this comment

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

this type has to be mentioned in openapi.rs files?

Comment on lines +861 to +863
if let Some(level) = new.specificity_level {
self.specificity_level = Some(level)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

why?

Suggested change
if let Some(level) = new.specificity_level {
self.specificity_level = Some(level)
}
self.specificity_level = new.specificity_level;

@@ -49,6 +52,15 @@ pub trait SuccessBasedDynamicRouting: dyn_clone::DynClone + Send + Sync {
id: String,
headers: GrpcHeaders,
) -> DynamicRoutingResult<InvalidateWindowsResponse>;
/// To calculate both global and merchant specific success rate for the list of chosen connectors
async fn calculate_global_success_rate(
Copy link
Contributor

Choose a reason for hiding this comment

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

include merchant too here in method name

.fetch_entity_and_global_success_rate(request)
.await
.change_context(DynamicRoutingError::SuccessRateBasedRoutingFailure(
"Failed to fetch the success rate".to_string(),
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
"Failed to fetch the success rate".to_string(),
"Failed to fetch the entity and global success rate".to_string(),

.first()
.ok_or(errors::ApiErrorResponse::InternalServerError)
.attach_printable(
"unable to fetch the first connector from list of connectors obtained from dynamic routing service",
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
"unable to fetch the first connector from list of connectors obtained from dynamic routing service",
"unable to fetch the first connector from list of global connectors obtained from dynamic routing service",

))?;

let outcome = get_success_based_metrics_outcome_for_payment(
payment_status_attribute,
payment_connector.to_string(),
first_success_based_connector.to_string(),
first_merchant_success_based_connector.to_string(),
);

let dynamic_routing_stats = DynamicRoutingStatsNew {
Copy link
Contributor

Choose a reason for hiding this comment

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

should we create a new column here which stores the globally_top_performing_connector at the time this particular payment was made?
cc: @prajjwalkumar17

@Chethan-rao
Copy link
Contributor

Chethan-rao commented Dec 30, 2024

there's conflicts too. please add test cases as well

Comment on lines +814 to +815
#[derive(serde::Serialize, serde::Deserialize, Debug, Default, Clone, ToSchema)]
pub enum SuccessRateSpecificityLevel {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
#[derive(serde::Serialize, serde::Deserialize, Debug, Default, Clone, ToSchema)]
pub enum SuccessRateSpecificityLevel {
#[derive(serde::Serialize, serde::Deserialize, Debug, Default, Clone, ToSchema)]
#[serde(rename_all = "snake_case")]
pub enum SuccessRateSpecificityLevel {

@@ -801,6 +802,7 @@ pub struct SuccessBasedRoutingConfigBody {
pub default_success_rate: Option<f64>,
pub max_aggregates_size: Option<u32>,
pub current_block_threshold: Option<CurrentBlockThreshold>,
pub specificity_level: Option<SuccessRateSpecificityLevel>,
Copy link
Contributor

@Chethan-rao Chethan-rao Dec 30, 2024

Choose a reason for hiding this comment

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

Instead of making this optional and manually filling this field for the old entries, we can make this a required field but derive a #[serde(default)] attribute on top so that when getting deserialised, serde will take care of setting this to a default value instead of you doing it. this shouldn't cause any backwards compatibility issues. what do you think?

Suggested change
pub specificity_level: Option<SuccessRateSpecificityLevel>,
#[serde(default)]
pub specificity_level: SuccessRateSpecificityLevel,

Comment on lines +1343 to +1346
success_based_routing_configs.config.as_mut().map(|config| {
config.specificity_level =
Some(api_models::routing::SuccessRateSpecificityLevel::Merchant)
});
Copy link
Contributor

Choose a reason for hiding this comment

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

you can remove this now because serde will take care of it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants