mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-29 17:19:15 +08:00
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:
@ -3,13 +3,12 @@ use std::{
|
||||
hash::{Hash, Hasher},
|
||||
};
|
||||
|
||||
use common_enums::enums::{AttemptStatus, AuthenticationType, Currency, PaymentMethod};
|
||||
use common_utils::events::ApiEventMetric;
|
||||
|
||||
use super::{NameDescription, TimeRange};
|
||||
use crate::{analytics::MetricsResponse, enums::Connector};
|
||||
use crate::enums::{
|
||||
AttemptStatus, AuthenticationType, Connector, Currency, PaymentMethod, PaymentMethodType,
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug, Default, serde::Deserialize, masking::Serialize)]
|
||||
#[derive(Clone, Debug, Default, serde::Deserialize, serde::Serialize)]
|
||||
pub struct PaymentFilters {
|
||||
#[serde(default)]
|
||||
pub currency: Vec<Currency>,
|
||||
@ -21,6 +20,8 @@ pub struct PaymentFilters {
|
||||
pub auth_type: Vec<AuthenticationType>,
|
||||
#[serde(default)]
|
||||
pub payment_method: Vec<PaymentMethod>,
|
||||
#[serde(default)]
|
||||
pub payment_method_type: Vec<PaymentMethodType>,
|
||||
}
|
||||
|
||||
#[derive(
|
||||
@ -44,6 +45,7 @@ pub enum PaymentDimensions {
|
||||
// Consult the Dashboard FE folks since these also affects the order of metrics on FE
|
||||
Connector,
|
||||
PaymentMethod,
|
||||
PaymentMethodType,
|
||||
Currency,
|
||||
#[strum(serialize = "authentication_type")]
|
||||
#[serde(rename = "authentication_type")]
|
||||
@ -73,6 +75,35 @@ pub enum PaymentMetrics {
|
||||
PaymentSuccessCount,
|
||||
PaymentProcessedAmount,
|
||||
AvgTicketSize,
|
||||
RetriesCount,
|
||||
ConnectorSuccessRate,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, serde::Serialize)]
|
||||
pub struct ErrorResult {
|
||||
pub reason: String,
|
||||
pub count: i64,
|
||||
pub percentage: f64,
|
||||
}
|
||||
|
||||
#[derive(
|
||||
Clone,
|
||||
Copy,
|
||||
Debug,
|
||||
Hash,
|
||||
PartialEq,
|
||||
Eq,
|
||||
serde::Serialize,
|
||||
serde::Deserialize,
|
||||
strum::Display,
|
||||
strum::EnumIter,
|
||||
strum::AsRefStr,
|
||||
)]
|
||||
#[strum(serialize_all = "snake_case")]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum PaymentDistributions {
|
||||
#[strum(serialize = "error_message")]
|
||||
PaymentErrorMessage,
|
||||
}
|
||||
|
||||
pub mod metric_behaviour {
|
||||
@ -109,6 +140,7 @@ pub struct PaymentMetricsBucketIdentifier {
|
||||
#[serde(rename = "authentication_type")]
|
||||
pub auth_type: Option<AuthenticationType>,
|
||||
pub payment_method: Option<String>,
|
||||
pub payment_method_type: Option<String>,
|
||||
#[serde(rename = "time_range")]
|
||||
pub time_bucket: TimeRange,
|
||||
// Coz FE sucks
|
||||
@ -124,6 +156,7 @@ impl PaymentMetricsBucketIdentifier {
|
||||
connector: Option<String>,
|
||||
auth_type: Option<AuthenticationType>,
|
||||
payment_method: Option<String>,
|
||||
payment_method_type: Option<String>,
|
||||
normalized_time_range: TimeRange,
|
||||
) -> Self {
|
||||
Self {
|
||||
@ -132,6 +165,7 @@ impl PaymentMetricsBucketIdentifier {
|
||||
connector,
|
||||
auth_type,
|
||||
payment_method,
|
||||
payment_method_type,
|
||||
time_bucket: normalized_time_range,
|
||||
start_time: normalized_time_range.start_time,
|
||||
}
|
||||
@ -145,6 +179,7 @@ impl Hash for PaymentMetricsBucketIdentifier {
|
||||
self.connector.hash(state);
|
||||
self.auth_type.map(|i| i.to_string()).hash(state);
|
||||
self.payment_method.hash(state);
|
||||
self.payment_method_type.hash(state);
|
||||
self.time_bucket.hash(state);
|
||||
}
|
||||
}
|
||||
@ -166,6 +201,10 @@ pub struct PaymentMetricsBucketValue {
|
||||
pub payment_success_count: Option<u64>,
|
||||
pub payment_processed_amount: Option<u64>,
|
||||
pub avg_ticket_size: Option<f64>,
|
||||
pub payment_error_message: Option<Vec<ErrorResult>>,
|
||||
pub retries_count: Option<u64>,
|
||||
pub retries_amount_processed: Option<u64>,
|
||||
pub connector_success_rate: Option<f64>,
|
||||
}
|
||||
|
||||
#[derive(Debug, serde::Serialize)]
|
||||
@ -175,6 +214,3 @@ pub struct MetricsBucketResponse {
|
||||
#[serde(flatten)]
|
||||
pub dimensions: PaymentMetricsBucketIdentifier,
|
||||
}
|
||||
|
||||
impl ApiEventMetric for MetricsBucketResponse {}
|
||||
impl ApiEventMetric for MetricsResponse<MetricsBucketResponse> {}
|
||||
|
||||
Reference in New Issue
Block a user