feat(analytics): Add Clickhouse based analytics (#2988)

Co-authored-by: harsh_sharma_juspay <harsh.sharma@juspay.in>
Co-authored-by: Ivor Dsouza <ivor.dsouza@juspay.in>
Co-authored-by: Chethan Rao <70657455+Chethan-rao@users.noreply.github.com>
Co-authored-by: nain-F49FF806 <126972030+nain-F49FF806@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
Co-authored-by: akshay.s <akshay.s@juspay.in>
Co-authored-by: Gnanasundari24 <118818938+Gnanasundari24@users.noreply.github.com>
This commit is contained in:
Sampras Lopes
2023-11-29 17:04:53 +05:30
committed by GitHub
parent 2e57745352
commit 9df4e0193f
135 changed files with 12145 additions and 901 deletions

View File

@ -12,6 +12,7 @@ pub mod events;
pub mod file;
pub mod fraud_check;
pub mod gsm;
mod kafka_store;
pub mod locker_mock_up;
pub mod mandate;
pub mod merchant_account;
@ -31,11 +32,24 @@ pub mod user_role;
use data_models::payments::{
payment_attempt::PaymentAttemptInterface, payment_intent::PaymentIntentInterface,
};
use diesel_models::{
fraud_check::{FraudCheck, FraudCheckNew, FraudCheckUpdate},
organization::{Organization, OrganizationNew, OrganizationUpdate},
};
use error_stack::ResultExt;
use masking::PeekInterface;
use redis_interface::errors::RedisError;
use storage_impl::{redis::kv_store::RedisConnInterface, MockDb};
use storage_impl::{errors::StorageError, redis::kv_store::RedisConnInterface, MockDb};
use crate::{errors::CustomResult, services::Store};
pub use self::kafka_store::KafkaStore;
use self::{fraud_check::FraudCheckInterface, organization::OrganizationInterface};
pub use crate::{
errors::CustomResult,
services::{
kafka::{KafkaError, KafkaProducer, MQResult},
Store,
},
};
#[derive(PartialEq, Eq)]
pub enum StorageImpl {
@ -58,7 +72,7 @@ pub trait StorageInterface:
+ ephemeral_key::EphemeralKeyInterface
+ events::EventInterface
+ file::FileMetadataInterface
+ fraud_check::FraudCheckInterface
+ FraudCheckInterface
+ locker_mock_up::LockerMockUpInterface
+ mandate::MandateInterface
+ merchant_account::MerchantAccountInterface
@ -79,7 +93,7 @@ pub trait StorageInterface:
+ RedisConnInterface
+ RequestIdStore
+ business_profile::BusinessProfileInterface
+ organization::OrganizationInterface
+ OrganizationInterface
+ routing_algorithm::RoutingAlgorithmInterface
+ gsm::GsmInterface
+ user::UserInterface
@ -151,7 +165,6 @@ where
T: serde::de::DeserializeOwned,
{
use common_utils::ext_traits::ByteSliceExt;
use error_stack::ResultExt;
let bytes = db.get_key(key).await?;
bytes
@ -160,3 +173,72 @@ where
}
dyn_clone::clone_trait_object!(StorageInterface);
impl RequestIdStore for KafkaStore {
fn add_request_id(&mut self, request_id: String) {
self.diesel_store.add_request_id(request_id)
}
}
#[async_trait::async_trait]
impl FraudCheckInterface for KafkaStore {
async fn insert_fraud_check_response(
&self,
new: FraudCheckNew,
) -> CustomResult<FraudCheck, StorageError> {
self.diesel_store.insert_fraud_check_response(new).await
}
async fn update_fraud_check_response_with_attempt_id(
&self,
fraud_check: FraudCheck,
fraud_check_update: FraudCheckUpdate,
) -> CustomResult<FraudCheck, StorageError> {
self.diesel_store
.update_fraud_check_response_with_attempt_id(fraud_check, fraud_check_update)
.await
}
async fn find_fraud_check_by_payment_id(
&self,
payment_id: String,
merchant_id: String,
) -> CustomResult<FraudCheck, StorageError> {
self.diesel_store
.find_fraud_check_by_payment_id(payment_id, merchant_id)
.await
}
async fn find_fraud_check_by_payment_id_if_present(
&self,
payment_id: String,
merchant_id: String,
) -> CustomResult<Option<FraudCheck>, StorageError> {
self.diesel_store
.find_fraud_check_by_payment_id_if_present(payment_id, merchant_id)
.await
}
}
#[async_trait::async_trait]
impl OrganizationInterface for KafkaStore {
async fn insert_organization(
&self,
organization: OrganizationNew,
) -> CustomResult<Organization, StorageError> {
self.diesel_store.insert_organization(organization).await
}
async fn find_organization_by_org_id(
&self,
org_id: &str,
) -> CustomResult<Organization, StorageError> {
self.diesel_store.find_organization_by_org_id(org_id).await
}
async fn update_organization_by_org_id(
&self,
org_id: &str,
update: OrganizationUpdate,
) -> CustomResult<Organization, StorageError> {
self.diesel_store
.update_organization_by_org_id(org_id, update)
.await
}
}