mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-03 13:30:39 +08:00
feat: realtime user analytics (#5098)
Co-authored-by: Sampras Lopes <Sampras.lopes@juspay.in>
This commit is contained in:
@ -7,6 +7,7 @@ pub mod payments;
|
||||
mod query;
|
||||
pub mod refunds;
|
||||
|
||||
pub mod active_payments;
|
||||
pub mod api_event;
|
||||
pub mod auth_events;
|
||||
pub mod connector_events;
|
||||
@ -32,6 +33,7 @@ pub mod utils;
|
||||
use std::sync::Arc;
|
||||
|
||||
use api_models::analytics::{
|
||||
active_payments::{ActivePaymentsMetrics, ActivePaymentsMetricsBucketIdentifier},
|
||||
api_event::{
|
||||
ApiEventDimensions, ApiEventFilters, ApiEventMetrics, ApiEventMetricsBucketIdentifier,
|
||||
},
|
||||
@ -56,6 +58,7 @@ use storage_impl::config::Database;
|
||||
use strum::Display;
|
||||
|
||||
use self::{
|
||||
active_payments::metrics::{ActivePaymentsMetric, ActivePaymentsMetricRow},
|
||||
auth_events::metrics::{AuthEventMetric, AuthEventMetricRow},
|
||||
payments::{
|
||||
distribution::{PaymentDistribution, PaymentDistributionRow},
|
||||
@ -514,7 +517,7 @@ impl AnalyticsProvider {
|
||||
&self,
|
||||
metric: &SdkEventMetrics,
|
||||
dimensions: &[SdkEventDimensions],
|
||||
pub_key: &str,
|
||||
publishable_key: &str,
|
||||
filters: &SdkEventFilters,
|
||||
granularity: &Option<Granularity>,
|
||||
time_range: &TimeRange,
|
||||
@ -523,14 +526,21 @@ impl AnalyticsProvider {
|
||||
Self::Sqlx(_pool) => Err(report!(MetricsError::NotImplemented)),
|
||||
Self::Clickhouse(pool) => {
|
||||
metric
|
||||
.load_metrics(dimensions, pub_key, filters, granularity, time_range, pool)
|
||||
.load_metrics(
|
||||
dimensions,
|
||||
publishable_key,
|
||||
filters,
|
||||
granularity,
|
||||
time_range,
|
||||
pool,
|
||||
)
|
||||
.await
|
||||
}
|
||||
Self::CombinedCkh(_sqlx_pool, ckh_pool) | Self::CombinedSqlx(_sqlx_pool, ckh_pool) => {
|
||||
metric
|
||||
.load_metrics(
|
||||
dimensions,
|
||||
pub_key,
|
||||
publishable_key,
|
||||
filters,
|
||||
granularity,
|
||||
// Since SDK events are ckh only use ckh here
|
||||
@ -542,6 +552,32 @@ impl AnalyticsProvider {
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn get_active_payments_metrics(
|
||||
&self,
|
||||
metric: &ActivePaymentsMetrics,
|
||||
merchant_id: &str,
|
||||
publishable_key: &str,
|
||||
) -> types::MetricsResult<
|
||||
Vec<(
|
||||
ActivePaymentsMetricsBucketIdentifier,
|
||||
ActivePaymentsMetricRow,
|
||||
)>,
|
||||
> {
|
||||
match self {
|
||||
Self::Sqlx(_pool) => Err(report!(MetricsError::NotImplemented)),
|
||||
Self::Clickhouse(pool) => {
|
||||
metric
|
||||
.load_metrics(merchant_id, publishable_key, pool)
|
||||
.await
|
||||
}
|
||||
Self::CombinedCkh(_sqlx_pool, ckh_pool) | Self::CombinedSqlx(_sqlx_pool, ckh_pool) => {
|
||||
metric
|
||||
.load_metrics(merchant_id, publishable_key, ckh_pool)
|
||||
.await
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn get_auth_event_metrics(
|
||||
&self,
|
||||
metric: &AuthEventMetrics,
|
||||
@ -723,6 +759,7 @@ pub enum AnalyticsFlow {
|
||||
GetRefundsMetrics,
|
||||
GetSdkMetrics,
|
||||
GetAuthMetrics,
|
||||
GetActivePaymentsMetrics,
|
||||
GetPaymentFilters,
|
||||
GetRefundFilters,
|
||||
GetSdkEventFilters,
|
||||
|
||||
Reference in New Issue
Block a user