Skip to content

Conversation

spritianeja03
Copy link
Contributor

@spritianeja03 spritianeja03 commented Apr 29, 2025

Type of Change

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

Description

Add a new route for updating the elimination routing config when it is toggled

Additional Changes

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

Motivation and Context

This PR closes #7939

How did you test it?

  1. Toggle elimination routing
    request
curl --location --request POST 'http://localhost:8080/account/merchant_174600xxxx/business_profile/pro_h9ecR6baV3b1eDvfxxxB/dynamic_routing/elimination/toggle?enable=metrics' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: dev_YWu8PFM4pqgBjknNsvHimHsB*******'

response

{
    "id": "routing_yfRG8iqWlBreVTVlnYwB",
    "profile_id": "pro_h9ecR6baV3b1eDvfxxxB",
    "name": "Elimination based dynamic routing algorithm",
    "kind": "dynamic",
    "description": "",
    "created_at": 1746007881,
    "modified_at": 1746007881,
    "algorithm_for": "payment"
}
  1. Update elimination routing config
    request
curl --location --request PATCH 'http://localhost:8080/account/merchant_174600xxxx/business_profile/pro_h9ecR6baV3b1eDvfxxxB/dynamic_routing/elimination/config/routing_yfRG8iqWlBreVTVlxxxB' \
--header 'api-key: dev_YWu8PFM4pqgBjknNsvHimHsBW1O9CBVy3*******' \
--header 'Content-Type: application/json' \
--data '{
  "params": [
    "Currency",
    "CardBin",
    "Country",
    "PaymentMethod",
    "PaymentMethodType",
    "AuthenticationType",
    "CardNetwork"
  ]
}'

response

{
    "id": "routing_YYu14QIGKRrWgJ8QllpR",
    "profile_id": "pro_h9ecR6baV3b1eDvfxxxB",
    "name": "Elimination based dynamic routing algorithm",
    "kind": "dynamic",
    "description": "",
    "created_at": 1746008246,
    "modified_at": 1746008246,
    "algorithm_for": "payment"
}

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

@spritianeja03 spritianeja03 added the A-routing Area: Routing label Apr 29, 2025
@spritianeja03 spritianeja03 added this to the April 2025 Release milestone Apr 29, 2025
@spritianeja03 spritianeja03 self-assigned this Apr 29, 2025
Copy link

semanticdiff-com bot commented Apr 29, 2025

Review changes with  SemanticDiff

Changed Files
File Status
  crates/router/src/routes/app.rs  63% smaller
  crates/api_models/src/events/routing.rs  55% smaller
  crates/router/src/core/routing.rs  16% smaller
  crates/api_models/src/routing.rs  0% smaller
  crates/router/src/routes/routing.rs  0% smaller

@spritianeja03 spritianeja03 changed the title feat(routing): Add route to update config for elimination routing feat(routing): Add support to update config for elimination routing Apr 29, 2025
@spritianeja03 spritianeja03 marked this pull request as ready for review April 29, 2025 12:36
@spritianeja03 spritianeja03 requested review from a team as code owners April 29, 2025 12:36
prajjwalkumar17
prajjwalkumar17 previously approved these changes May 2, 2025
algorithm_id: common_utils::id_type::RoutingId,
profile_id: common_utils::id_type::ProfileId,
) -> RouterResponse<routing_types::RoutingDictionaryRecord> {
use external_services::grpc_client::dynamic_routing::elimination_based_client::EliminationBasedRouting;
Copy link
Contributor

Choose a reason for hiding this comment

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

move this to the top

Comment on lines 1490 to 1493
metrics::ROUTING_UPDATE_CONFIG_FOR_PROFILE.add(
1,
router_env::metric_attributes!(("profile_id", profile_id.clone())),
);
Copy link
Contributor

Choose a reason for hiding this comment

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

can we add algo_type as attribute to get the count of updates of specific algo
cc: @prajjwalkumar17

Copy link
Member

Choose a reason for hiding this comment

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

Yes can be made as an attribute, but the RoutingAlgorithmKind we use in RoutingAlgorithm table has type as DyanamicAlgorithm, we can create an enum something like DynamicRoutingAlgorithmKind which will have types as SuccessBasedRoutingAlgorithm, EliminationAlgorithm, ContractRoutingAlgorithm and this can be used only to fill the respective metric's attributes in the respective function calls, no DB changes required only assign the enum in function and add to metrics call, this needs to be done for all the dynamic routing functions for create as well as update.

cc: @spritianeja03

Comment on lines 1543 to 1548
let _ = cache::redact_from_redis_and_publish(
state.store.get_cache_store().as_ref(),
cache_entries_to_redact,
)
.await
.map_err(|e| logger::error!("unable to publish into the redact channel for evicting the elimination 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.

Suggested change
let _ = cache::redact_from_redis_and_publish(
state.store.get_cache_store().as_ref(),
cache_entries_to_redact,
)
.await
.map_err(|e| logger::error!("unable to publish into the redact channel for evicting the elimination routing config cache {e:?}"));
cache::redact_from_redis_and_publish(
state.store.get_cache_store().as_ref(),
cache_entries_to_redact,
)
.await
.map_err(|e| logger::error!("unable to publish into the redact channel for evicting the elimination routing config cache {e:?}")).ok();

)
.await
.change_context(errors::ApiErrorResponse::GenericNotFoundError {
message: "Failed to invalidate the routing keys".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
message: "Failed to invalidate the routing keys".to_string(),
message: "Failed to invalidate the elimination routing keys".to_string(),

state.get_grpc_headers(),
)
.await
.change_context(errors::ApiErrorResponse::GenericNotFoundError {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not GenericNotFoundError error. all other algo's update handler too has this error mapped to GenericNotFoundError. please change it in other update flows as well

@Gnanasundari24 Gnanasundari24 added this pull request to the merge queue May 12, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks May 12, 2025
@Gnanasundari24 Gnanasundari24 enabled auto-merge May 12, 2025 13:49
@Gnanasundari24 Gnanasundari24 added this pull request to the merge queue May 12, 2025
Merged via the queue into main with commit d07a85c May 12, 2025
15 of 20 checks passed
@Gnanasundari24 Gnanasundari24 deleted the toggle-elimination-routing branch May 12, 2025 16:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-routing Area: Routing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEATURE]: Add support for updating elimination config
5 participants