mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-02 04:04:43 +08:00
feat(analytics): Add v2 payment analytics (payment-intents analytics) (#5150)
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
@ -3,6 +3,7 @@ pub mod core;
|
||||
pub mod disputes;
|
||||
pub mod errors;
|
||||
pub mod metrics;
|
||||
pub mod payment_intents;
|
||||
pub mod payments;
|
||||
mod query;
|
||||
pub mod refunds;
|
||||
@ -39,6 +40,10 @@ use api_models::analytics::{
|
||||
},
|
||||
auth_events::{AuthEventMetrics, AuthEventMetricsBucketIdentifier},
|
||||
disputes::{DisputeDimensions, DisputeFilters, DisputeMetrics, DisputeMetricsBucketIdentifier},
|
||||
payment_intents::{
|
||||
PaymentIntentDimensions, PaymentIntentFilters, PaymentIntentMetrics,
|
||||
PaymentIntentMetricsBucketIdentifier,
|
||||
},
|
||||
payments::{PaymentDimensions, PaymentFilters, PaymentMetrics, PaymentMetricsBucketIdentifier},
|
||||
refunds::{RefundDimensions, RefundFilters, RefundMetrics, RefundMetricsBucketIdentifier},
|
||||
sdk_events::{
|
||||
@ -60,6 +65,7 @@ use strum::Display;
|
||||
use self::{
|
||||
active_payments::metrics::{ActivePaymentsMetric, ActivePaymentsMetricRow},
|
||||
auth_events::metrics::{AuthEventMetric, AuthEventMetricRow},
|
||||
payment_intents::metrics::{PaymentIntentMetric, PaymentIntentMetricRow},
|
||||
payments::{
|
||||
distribution::{PaymentDistribution, PaymentDistributionRow},
|
||||
metrics::{PaymentMetric, PaymentMetricRow},
|
||||
@ -313,6 +319,111 @@ impl AnalyticsProvider {
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn get_payment_intent_metrics(
|
||||
&self,
|
||||
metric: &PaymentIntentMetrics,
|
||||
dimensions: &[PaymentIntentDimensions],
|
||||
merchant_id: &str,
|
||||
filters: &PaymentIntentFilters,
|
||||
granularity: &Option<Granularity>,
|
||||
time_range: &TimeRange,
|
||||
) -> types::MetricsResult<Vec<(PaymentIntentMetricsBucketIdentifier, PaymentIntentMetricRow)>>
|
||||
{
|
||||
// Metrics to get the fetch time for each payment intent metric
|
||||
metrics::request::record_operation_time(
|
||||
async {
|
||||
match self {
|
||||
Self::Sqlx(pool) => {
|
||||
metric
|
||||
.load_metrics(
|
||||
dimensions,
|
||||
merchant_id,
|
||||
filters,
|
||||
granularity,
|
||||
time_range,
|
||||
pool,
|
||||
)
|
||||
.await
|
||||
}
|
||||
Self::Clickhouse(pool) => {
|
||||
metric
|
||||
.load_metrics(
|
||||
dimensions,
|
||||
merchant_id,
|
||||
filters,
|
||||
granularity,
|
||||
time_range,
|
||||
pool,
|
||||
)
|
||||
.await
|
||||
}
|
||||
Self::CombinedCkh(sqlx_pool, ckh_pool) => {
|
||||
let (ckh_result, sqlx_result) = tokio::join!(metric
|
||||
.load_metrics(
|
||||
dimensions,
|
||||
merchant_id,
|
||||
filters,
|
||||
granularity,
|
||||
time_range,
|
||||
ckh_pool,
|
||||
),
|
||||
metric
|
||||
.load_metrics(
|
||||
dimensions,
|
||||
merchant_id,
|
||||
filters,
|
||||
granularity,
|
||||
time_range,
|
||||
sqlx_pool,
|
||||
));
|
||||
match (&sqlx_result, &ckh_result) {
|
||||
(Ok(ref sqlx_res), Ok(ref ckh_res)) if sqlx_res != ckh_res => {
|
||||
router_env::logger::error!(clickhouse_result=?ckh_res, postgres_result=?sqlx_res, "Mismatch between clickhouse & postgres payment intents analytics metrics")
|
||||
},
|
||||
_ => {}
|
||||
|
||||
};
|
||||
|
||||
ckh_result
|
||||
}
|
||||
Self::CombinedSqlx(sqlx_pool, ckh_pool) => {
|
||||
let (ckh_result, sqlx_result) = tokio::join!(metric
|
||||
.load_metrics(
|
||||
dimensions,
|
||||
merchant_id,
|
||||
filters,
|
||||
granularity,
|
||||
time_range,
|
||||
ckh_pool,
|
||||
),
|
||||
metric
|
||||
.load_metrics(
|
||||
dimensions,
|
||||
merchant_id,
|
||||
filters,
|
||||
granularity,
|
||||
time_range,
|
||||
sqlx_pool,
|
||||
));
|
||||
match (&sqlx_result, &ckh_result) {
|
||||
(Ok(ref sqlx_res), Ok(ref ckh_res)) if sqlx_res != ckh_res => {
|
||||
router_env::logger::error!(clickhouse_result=?ckh_res, postgres_result=?sqlx_res, "Mismatch between clickhouse & postgres payment intents analytics metrics")
|
||||
},
|
||||
_ => {}
|
||||
|
||||
};
|
||||
|
||||
sqlx_result
|
||||
}
|
||||
}
|
||||
},
|
||||
&metrics::METRIC_FETCH_TIME,
|
||||
metric,
|
||||
self,
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn get_refund_metrics(
|
||||
&self,
|
||||
metric: &RefundMetrics,
|
||||
@ -756,11 +867,13 @@ pub struct ReportConfig {
|
||||
pub enum AnalyticsFlow {
|
||||
GetInfo,
|
||||
GetPaymentMetrics,
|
||||
GetPaymentIntentMetrics,
|
||||
GetRefundsMetrics,
|
||||
GetSdkMetrics,
|
||||
GetAuthMetrics,
|
||||
GetActivePaymentsMetrics,
|
||||
GetPaymentFilters,
|
||||
GetPaymentIntentFilters,
|
||||
GetRefundFilters,
|
||||
GetSdkEventFilters,
|
||||
GetApiEvents,
|
||||
|
||||
Reference in New Issue
Block a user