Skip to content

Commit f0019b0

Browse files
feat: Fix global elimination redis key issue (#198)
1 parent f6efa41 commit f0019b0

18 files changed

Lines changed: 853 additions & 32 deletions

File tree

Cargo.lock

Lines changed: 22 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ rust-version = "1.85.0"
99

1010
[features]
1111
default = ["middleware","mysql"]
12-
release = ["middleware", "kms-aws","mysql"]
12+
release = ["middleware", "kms-aws","mysql", "redis_compression"]
1313
kms-aws = ["dep:aws-config", "dep:aws-sdk-kms"]
1414
kms-hashicorp-vault = ["dep:vaultrs"]
1515
limit = []
@@ -19,6 +19,7 @@ external_key_manager = []
1919
external_key_manager_mtls = ["external_key_manager", "reqwest/rustls-tls"]
2020
postgres = []
2121
mysql = []
22+
redis_compression = ["dep:zstd"]
2223

2324
[dependencies]
2425
aws-config = { version = "1.5.5", optional = true }
@@ -36,6 +37,7 @@ jemallocator = "0.5"
3637
jemalloc-ctl = "0.5"
3738
prometheus = "0.13"
3839
lazy_static = "1.4"
40+
zstd = { version = "0.12", optional = true }
3941

4042
async-bb8-diesel = { git = "https://github.com/jarnura/async-bb8-diesel", rev = "53b4ab901aab7635c8215fd1c2d542c8db443094" }
4143
redis_interface = { git = "https://github.com/juspay/hyperswitch.git", tag = "2024.09.30.0" }

config/development.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ max_capacity = 5000
5353
service_config_redis_prefix = "DE_service_config_"
5454
service_config_ttl = 300 # 5 minutes
5555

56+
[compression_filepath]
57+
zstd_compression_filepath = "/tmp/extra-paths/redis-zstd-dictionaries/sbx"
58+
5659
[tenant_secrets]
5760
public = { schema = "public" }
5861

src/app.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,10 @@ impl TenantAppState {
7171

7272
Ok(Self {
7373
db,
74-
redis_conn: Arc::new(RedisConnectionWrapper::new(redis_conn)),
74+
redis_conn: Arc::new(RedisConnectionWrapper::new(
75+
redis_conn,
76+
global_config.compression_filepath.clone(),
77+
)),
7578
api_client,
7679
config: tenant_config,
7780
})

src/config.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ pub struct GlobalConfig {
4242
pub routing_config: Option<TomlConfig>,
4343
#[serde(default)]
4444
pub debit_routing_config: network_decider::types::DebitRoutingConfig,
45+
pub compression_filepath: Option<CompressionFilepath>,
4546
}
4647

4748
#[derive(Clone, Debug)]
@@ -121,6 +122,11 @@ impl CacheConfig {
121122
}
122123
}
123124

125+
#[derive(Clone, serde::Deserialize, Debug)]
126+
pub struct CompressionFilepath {
127+
pub zstd_compression_filepath: String,
128+
}
129+
124130
#[derive(serde::Deserialize, Debug, Clone)]
125131
pub struct TenantSecrets {
126132
/// schema name for the tenant (defaults to tenant_id)

src/decider/gatewaydecider/flow_new.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use super::utils as Utils;
2222
// use optics_core::{preview, review};
2323
use crate::decider::gatewaydecider::constants as C;
2424
use crate::logger;
25+
use crate::redis::feature::RedisDataStruct;
2526
use crate::types::card::txn_card_info::TxnCardInfo;
2627
use crate::types::merchant as ETM;
2728
use crate::types::merchant::merchant_gateway_account::MerchantGatewayAccount;
@@ -71,7 +72,7 @@ pub async fn decider_full_payload_hs_function(
7172
Some(card_bin) => Some(card_bin),
7273
None => match dreq.txnCardInfo.card_isin {
7374
Some(c_isin) => {
74-
let res_bin = Utils::get_card_bin_from_token_bin(6, c_isin.as_str()).await;
75+
let res_bin = Utils::get_card_bin_from_token_bin(6, c_isin.as_str(), None).await;
7576
Some(res_bin)
7677
}
7778
None => dreq.txnCardInfo.card_isin.clone(),
@@ -105,6 +106,7 @@ pub async fn decider_full_payload_hs_function(
105106
dpPriorityLogicScript: dreq.priorityLogicScript,
106107
dpEDCCApplied: dreq.isEdccApplied,
107108
dpShouldConsumeResult: dreq.shouldConsumeResult,
109+
dpRedisCompressionConfig: None,
108110
};
109111

110112
if dreq_.ranking_algorithm == Some(RankingAlgorithm::NtwBasedRouting) {
@@ -534,6 +536,8 @@ pub async fn run_decider_flow(
534536
.unwrap_or_default()
535537
.as_str(),
536538
C::GATEWAY_SCORE_KEYS_TTL,
539+
None,
540+
RedisDataStruct::STRING,
537541
)
538542
.await
539543
.unwrap_or_default();

src/decider/gatewaydecider/flows.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use super::runner::get_gateway_priority;
22
use super::types::UnifiedError;
3+
use crate::redis::feature::{RedisCompressionConfigCombined, RedisDataStruct};
34
use axum::response::IntoResponse;
45
use serde_json::json;
56
use serde_json::Value as AValue;
@@ -127,6 +128,7 @@ pub trait ResponseDecider {
127128

128129
pub async fn decider_full_payload_hs_function(
129130
dreq: T::DomainDeciderRequest,
131+
redis_compression_config: Option<RedisCompressionConfigCombined>,
130132
) -> Result<(T::DecidedGateway, Vec<(String, Vec<String>)>), T::ErrorResponse> {
131133
let merchant_prefs = match ETM::merchant_iframe_preferences::getMerchantIPrefsByMId(
132134
dreq.txnDetail.merchantId.0.clone(),
@@ -165,7 +167,12 @@ pub async fn decider_full_payload_hs_function(
165167
Some(card_bin) => Some(card_bin),
166168
None => match dreq.txnCardInfo.card_isin {
167169
Some(c_isin) => {
168-
let res_bin = Utils::get_card_bin_from_token_bin(6, c_isin.as_str()).await;
170+
let res_bin = Utils::get_card_bin_from_token_bin(
171+
6,
172+
c_isin.as_str(),
173+
redis_compression_config.clone(),
174+
)
175+
.await;
169176
Some(res_bin)
170177
}
171178
None => dreq.txnCardInfo.card_isin.clone(),
@@ -199,6 +206,7 @@ pub async fn decider_full_payload_hs_function(
199206
dpPriorityLogicScript: dreq.priorityLogicScript,
200207
dpEDCCApplied: dreq.isEdccApplied,
201208
dpShouldConsumeResult: dreq.shouldConsumeResult,
209+
dpRedisCompressionConfig: redis_compression_config,
202210
};
203211
run_decider_flow(decider_params, true).await
204212
}
@@ -698,6 +706,8 @@ pub async fn run_decider_flow(
698706
.unwrap_or_default()
699707
.as_str(),
700708
C::GATEWAY_SCORE_KEYS_TTL,
709+
deciderParams.dpRedisCompressionConfig.clone(),
710+
RedisDataStruct::STRING,
701711
)
702712
.await
703713
.unwrap_or_default();

src/decider/gatewaydecider/gw_scoring.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use rand_distr::{Beta, Binomial, Distribution};
3030
use serde::{Deserialize, Serialize};
3131
use time::{OffsetDateTime, PrimitiveDateTime};
3232
// use crate::types::card_brand_routes as ETCBR;
33-
use crate::redis::feature::{self as M, is_feature_enabled};
33+
use crate::redis::feature::{self as M, is_feature_enabled, RedisCompressionConfigCombined};
3434
use crate::types::gateway_routing_input as ETGRI;
3535
// use crate::types::gateway_health as ETGH;
3636
use crate::types::card as ETCT;
@@ -3009,6 +3009,7 @@ pub async fn trigger_reset_gateway_score(
30093009
decider_flow,
30103010
txn_detail.clone(),
30113011
reset_gateway_input.clone(),
3012+
decider_flow.get().dpRedisCompressionConfig.clone(),
30123013
)
30133014
.await;
30143015
reset_gateway_sr_list.push(reset_gateway_input.clone());
@@ -3071,6 +3072,7 @@ pub async fn reset_gateway_score(
30713072
decider_flow: &mut DeciderFlow<'_>,
30723073
txn_detail: ETTD::TxnDetail,
30733074
reset_gateway_input: ResetGatewayInput,
3075+
redis_compression_config: Option<RedisCompressionConfigCombined>,
30743076
) {
30753077
let current_timestamp = get_current_date_in_millis();
30763078
match (
@@ -3081,6 +3083,14 @@ pub async fn reset_gateway_score(
30813083
(Some(key), Some(threshold), Some(max_count)) => {
30823084
let penality_factor = Utils::get_penality_factor_(decider_flow).await;
30833085
let score = get_merchant_elimination_gateway_score(key.clone()).await;
3086+
logger::debug!(
3087+
tag = "scoringFlow",
3088+
action = "scoringFlow",
3089+
"Current Gateway Score for {:?} : key {:?} before reset attempt: {:?}",
3090+
txn_detail.txnId,
3091+
key,
3092+
score
3093+
);
30843094
let (is_eligible_for_reset, reset_cached_gateway_score) = match score {
30853095
Some(score) => {
30863096
let current_score = score.score;
@@ -3141,6 +3151,7 @@ pub async fn reset_gateway_score(
31413151
key.clone(),
31423152
reset_cached_gateway_score.clone(),
31433153
safe_remaining_ttl,
3154+
redis_compression_config,
31443155
)
31453156
.await;
31463157
match result {

src/decider/gatewaydecider/runner.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,9 @@ pub async fn execute_priority_logic(
509509
let resolve_bin = match utils::fetch_extended_card_bin(&req.txnCardInfo) {
510510
Some(card_bin) => Some(card_bin),
511511
None => match req.txnCardInfo.card_isin {
512-
Some(c_isin) => Some(utils::get_card_bin_from_token_bin(6, c_isin.as_str()).await),
512+
Some(c_isin) => {
513+
Some(utils::get_card_bin_from_token_bin(6, c_isin.as_str(), None).await)
514+
}
513515
None => None,
514516
},
515517
};

src/decider/gatewaydecider/types.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::app::{get_tenant_app_state, TenantAppState};
22
use crate::decider::network_decider;
3+
use crate::redis::feature::RedisCompressionConfigCombined;
34
use crate::types::country::country_iso::CountryISO2;
45
use crate::types::currency::Currency;
56
use crate::types::money::internal as ETMo;
@@ -1297,6 +1298,7 @@ pub struct DeciderParams {
12971298
pub dpPriorityLogicScript: Option<String>,
12981299
pub dpEDCCApplied: Option<bool>,
12991300
pub dpShouldConsumeResult: Option<bool>,
1301+
pub dpRedisCompressionConfig: Option<RedisCompressionConfigCombined>,
13001302
}
13011303

13021304
#[derive(Debug, Serialize, Deserialize)]

0 commit comments

Comments
 (0)