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): Contract based routing integration #6761

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

Conversation

Sarthak1799
Copy link
Contributor

@Sarthak1799 Sarthak1799 commented Dec 5, 2024

Type of Change

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

Description

  • Built an interface for Contract based routing
  • Integrated Contract based routing with hyperswitch
  • Built new APIs for contract routing config setup
  • Refactored some existing dynamic routing code

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?

  1. Enable Contract routing config
curl --location --request POST 'http://localhost:8080/account/sarthak2/business_profile/pro_YozTgS8HebvBlk0UaeWW/dynamic_routing/contracts/toggle?enable=dynamic_connector_selection' \
--header 'api-key: dev_1aD8YuFd6Ovanf3oOtAYobqI6qw4ZBRSfw6BgYbifWHpaopkisBtm8obNXkFbVJn' \
--header 'Content-Type: application/json' \
--data-raw '{
    "config": {
        "constants": [0.7,0.35],
        "time_scale": "day"
    },
    "label_info": [{
        "label": "stripe",
        "target_count": 10000,
        "incremental_count": 0,
        "target_time": 1780486655,
        "mca_id": "mca_5Mk0Qcum2tnbmKoyqeuL"
    }]
}'

Response -

{
    "id": "routing_FlQ49V71J8ZCXEwPzFy9",
    "profile_id": "pro_YozTgS8HebvBlk0UaeWW",
    "name": "Contract based dynamic routing algorithm",
    "kind": "dynamic",
    "description": "",
    "created_at": 1734009361,
    "modified_at": 1734009361,
    "algorithm_for": "payment"
}
  1. Set Volume split for dynamic routing
curl --location --request POST 'http://localhost:8080/account/sarthak2/business_profile/pro_YozTgS8HebvBlk0UaeWW/dynamic_routing/set_volume_split?split=80' \
--header 'api-key: dev_1aD8YuFd6Ovanf3oOtAYobqI6qw4ZBRSfw6BgYbifWHpaopkisBtm8obNXkFbVJn'
  1. Create a Payment
    Metrics Population post payment -
image

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 5, 2024
@Sarthak1799 Sarthak1799 requested review from a team as code owners December 5, 2024 20:19
@Sarthak1799 Sarthak1799 added A-core Area: Core flows A-routing Area: Routing labels Dec 5, 2024
@Sarthak1799 Sarthak1799 linked an issue Dec 12, 2024 that may be closed by this pull request
2 tasks
crates/api_models/src/routing.rs Outdated Show resolved Hide resolved
crates/router/src/routes/routing.rs Outdated Show resolved Hide resolved
crates/router/src/routes/routing.rs Outdated Show resolved Hide resolved
crates/router/src/routes/routing.rs Outdated Show resolved Hide resolved
self.config.as_mut().map(|config| config.update(new_config));
}
if let Some(new_label_info) = new.label_info {
self.label_info = Some(new_label_info)
Copy link
Contributor

Choose a reason for hiding this comment

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

is it ok to loose the entire list of LabelInformation? or should we consider more granular way of updating, like whether to append to existing list or completely override

crates/router/src/core/routing/helpers.rs Outdated Show resolved Hide resolved
crates/router/src/core/routing/helpers.rs Outdated Show resolved Hide resolved
crates/router/src/core/routing/helpers.rs Outdated Show resolved Hide resolved
crates/router/src/core/routing/helpers.rs Outdated Show resolved Hide resolved
crates/router/src/core/routing/helpers.rs Show resolved Hide resolved
@hyperswitch-bot hyperswitch-bot bot added the M-api-contract-changes Metadata: This PR involves API contract changes label Dec 18, 2024
@Sarthak1799 Sarthak1799 requested a review from a team as a code owner December 20, 2024 10:34
.github/CODEOWNERS Outdated Show resolved Hide resolved
crates/api_models/src/routing.rs Show resolved Hide resolved
}
}
} else {
self.label_info = Some(vec![new_label_info.clone()]);
Copy link
Contributor

Choose a reason for hiding this comment

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

is it ok to loose old entries in this vector as you are completely overriding it?

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 case would only arise when we don't have any existing entries in the vec

crates/router/src/core/routing/helpers.rs Outdated Show resolved Hide resolved
crates/router/src/core/routing/helpers.rs Outdated Show resolved Hide resolved
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 M-api-contract-changes Metadata: This PR involves API contract changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEATURE] Contract Routing Integration
3 participants