-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(dynamic_routing): analytics improvement using separate postgres …
…table (#6723) Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
- Loading branch information
1 parent
357e8a0
commit 5918014
Showing
16 changed files
with
256 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
use diesel::{Insertable, Queryable, Selectable}; | ||
|
||
use crate::schema::dynamic_routing_stats; | ||
|
||
#[derive(Clone, Debug, Eq, Insertable, PartialEq)] | ||
#[diesel(table_name = dynamic_routing_stats)] | ||
pub struct DynamicRoutingStatsNew { | ||
pub payment_id: common_utils::id_type::PaymentId, | ||
pub attempt_id: String, | ||
pub merchant_id: common_utils::id_type::MerchantId, | ||
pub profile_id: common_utils::id_type::ProfileId, | ||
pub amount: common_utils::types::MinorUnit, | ||
pub success_based_routing_connector: String, | ||
pub payment_connector: String, | ||
pub currency: Option<common_enums::Currency>, | ||
pub payment_method: Option<common_enums::PaymentMethod>, | ||
pub capture_method: Option<common_enums::CaptureMethod>, | ||
pub authentication_type: Option<common_enums::AuthenticationType>, | ||
pub payment_status: common_enums::AttemptStatus, | ||
pub conclusive_classification: common_enums::SuccessBasedRoutingConclusiveState, | ||
pub created_at: time::PrimitiveDateTime, | ||
} | ||
|
||
#[derive(Clone, Debug, Eq, PartialEq, Queryable, Selectable, Insertable)] | ||
#[diesel(table_name = dynamic_routing_stats, primary_key(payment_id), check_for_backend(diesel::pg::Pg))] | ||
pub struct DynamicRoutingStats { | ||
pub payment_id: common_utils::id_type::PaymentId, | ||
pub attempt_id: String, | ||
pub merchant_id: common_utils::id_type::MerchantId, | ||
pub profile_id: common_utils::id_type::ProfileId, | ||
pub amount: common_utils::types::MinorUnit, | ||
pub success_based_routing_connector: String, | ||
pub payment_connector: String, | ||
pub currency: Option<common_enums::Currency>, | ||
pub payment_method: Option<common_enums::PaymentMethod>, | ||
pub capture_method: Option<common_enums::CaptureMethod>, | ||
pub authentication_type: Option<common_enums::AuthenticationType>, | ||
pub payment_status: common_enums::AttemptStatus, | ||
pub conclusive_classification: common_enums::SuccessBasedRoutingConclusiveState, | ||
pub created_at: time::PrimitiveDateTime, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
use super::generics; | ||
use crate::{ | ||
dynamic_routing_stats::{DynamicRoutingStats, DynamicRoutingStatsNew}, | ||
PgPooledConn, StorageResult, | ||
}; | ||
|
||
impl DynamicRoutingStatsNew { | ||
pub async fn insert(self, conn: &PgPooledConn) -> StorageResult<DynamicRoutingStats> { | ||
generics::generic_insert(conn, self).await | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
use error_stack::report; | ||
use router_env::{instrument, tracing}; | ||
use storage_impl::MockDb; | ||
|
||
use super::Store; | ||
use crate::{ | ||
connection, | ||
core::errors::{self, CustomResult}, | ||
db::kafka_store::KafkaStore, | ||
types::storage, | ||
}; | ||
|
||
#[async_trait::async_trait] | ||
pub trait DynamicRoutingStatsInterface { | ||
async fn insert_dynamic_routing_stat_entry( | ||
&self, | ||
dynamic_routing_stat_new: storage::DynamicRoutingStatsNew, | ||
) -> CustomResult<storage::DynamicRoutingStats, errors::StorageError>; | ||
} | ||
|
||
#[async_trait::async_trait] | ||
impl DynamicRoutingStatsInterface for Store { | ||
#[instrument(skip_all)] | ||
async fn insert_dynamic_routing_stat_entry( | ||
&self, | ||
dynamic_routing_stat: storage::DynamicRoutingStatsNew, | ||
) -> CustomResult<storage::DynamicRoutingStats, errors::StorageError> { | ||
let conn = connection::pg_connection_write(self).await?; | ||
dynamic_routing_stat | ||
.insert(&conn) | ||
.await | ||
.map_err(|error| report!(errors::StorageError::from(error))) | ||
} | ||
} | ||
|
||
#[async_trait::async_trait] | ||
impl DynamicRoutingStatsInterface for MockDb { | ||
#[instrument(skip_all)] | ||
async fn insert_dynamic_routing_stat_entry( | ||
&self, | ||
_dynamic_routing_stat: storage::DynamicRoutingStatsNew, | ||
) -> CustomResult<storage::DynamicRoutingStats, errors::StorageError> { | ||
Err(errors::StorageError::MockDbError)? | ||
} | ||
} | ||
|
||
#[async_trait::async_trait] | ||
impl DynamicRoutingStatsInterface for KafkaStore { | ||
#[instrument(skip_all)] | ||
async fn insert_dynamic_routing_stat_entry( | ||
&self, | ||
dynamic_routing_stat: storage::DynamicRoutingStatsNew, | ||
) -> CustomResult<storage::DynamicRoutingStats, errors::StorageError> { | ||
self.diesel_store | ||
.insert_dynamic_routing_stat_entry(dynamic_routing_stat) | ||
.await | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub use diesel_models::dynamic_routing_stats::{DynamicRoutingStats, DynamicRoutingStatsNew}; |
3 changes: 3 additions & 0 deletions
3
migrations/2024-12-02-095127_add_new_table_dynamic_routing_stats/down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
-- This file should undo anything in `up.sql` | ||
DROP TABLE IF EXISTS dynamic_routing_stats; | ||
DROP TYPE IF EXISTS "SuccessBasedRoutingConclusiveState"; |
26 changes: 26 additions & 0 deletions
26
migrations/2024-12-02-095127_add_new_table_dynamic_routing_stats/up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
--- Your SQL goes here | ||
CREATE TYPE "SuccessBasedRoutingConclusiveState" AS ENUM( | ||
'true_positive', | ||
'false_positive', | ||
'true_negative', | ||
'false_negative' | ||
); | ||
|
||
CREATE TABLE IF NOT EXISTS dynamic_routing_stats ( | ||
payment_id VARCHAR(64) NOT NULL, | ||
attempt_id VARCHAR(64) NOT NULL, | ||
merchant_id VARCHAR(64) NOT NULL, | ||
profile_id VARCHAR(64) NOT NULL, | ||
amount BIGINT NOT NULL, | ||
success_based_routing_connector VARCHAR(64) NOT NULL, | ||
payment_connector VARCHAR(64) NOT NULL, | ||
currency "Currency", | ||
payment_method VARCHAR(64), | ||
capture_method "CaptureMethod", | ||
authentication_type "AuthenticationType", | ||
payment_status "AttemptStatus" NOT NULL, | ||
conclusive_classification "SuccessBasedRoutingConclusiveState" NOT NULL, | ||
created_at TIMESTAMP NOT NULL, | ||
PRIMARY KEY(attempt_id, merchant_id) | ||
); | ||
CREATE INDEX profile_id_index ON dynamic_routing_stats (profile_id); |