feat(analytics): authentication analytics (#4429)

Co-authored-by: Sampras Lopes <lsampras@pm.me>
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
Vrishab Srivatsa
2024-05-10 15:38:26 +05:30
committed by GitHub
parent 86e05501cb
commit 24d154248c
28 changed files with 790 additions and 418 deletions

View File

@ -7,6 +7,7 @@ use router_env::logger;
use time::PrimitiveDateTime;
use super::{
auth_events::metrics::AuthEventMetricRow,
health_check::HealthCheck,
payments::{
distribution::PaymentDistributionRow, filters::FilterRow, metrics::PaymentMetricRow,
@ -132,10 +133,11 @@ impl AnalyticsDataSource for ClickhouseClient {
| AnalyticsCollection::Dispute => {
TableEngine::CollapsingMergeTree { sign: "sign_flag" }
}
AnalyticsCollection::SdkEvents => TableEngine::BasicTree,
AnalyticsCollection::ApiEvents => TableEngine::BasicTree,
AnalyticsCollection::ConnectorEvents => TableEngine::BasicTree,
AnalyticsCollection::OutgoingWebhookEvent => TableEngine::BasicTree,
AnalyticsCollection::SdkEvents
| AnalyticsCollection::ApiEvents
| AnalyticsCollection::ConnectorEvents
| AnalyticsCollection::ConnectorEventsAnalytics
| AnalyticsCollection::OutgoingWebhookEvent => TableEngine::BasicTree,
}
}
}
@ -158,6 +160,7 @@ impl super::refunds::filters::RefundFilterAnalytics for ClickhouseClient {}
impl super::sdk_events::filters::SdkEventFilterAnalytics for ClickhouseClient {}
impl super::sdk_events::metrics::SdkEventMetricAnalytics for ClickhouseClient {}
impl super::sdk_events::events::SdkEventsFilterAnalytics for ClickhouseClient {}
impl super::auth_events::metrics::AuthEventMetricAnalytics for ClickhouseClient {}
impl super::api_event::events::ApiLogsFilterAnalytics for ClickhouseClient {}
impl super::api_event::filters::ApiEventFilterAnalytics for ClickhouseClient {}
impl super::api_event::metrics::ApiEventMetricAnalytics for ClickhouseClient {}
@ -320,6 +323,16 @@ impl TryInto<SdkEventFilter> for serde_json::Value {
}
}
impl TryInto<AuthEventMetricRow> for serde_json::Value {
type Error = Report<ParsingError>;
fn try_into(self) -> Result<AuthEventMetricRow, Self::Error> {
serde_json::from_value(self).change_context(ParsingError::StructParseFailure(
"Failed to parse AuthEventMetricRow in clickhouse results",
))
}
}
impl TryInto<ApiEventFilter> for serde_json::Value {
type Error = Report<ParsingError>;
@ -361,6 +374,7 @@ impl ToSql<ClickhouseClient> for AnalyticsCollection {
Self::Refund => Ok("refunds".to_string()),
Self::SdkEvents => Ok("sdk_events_audit".to_string()),
Self::ApiEvents => Ok("api_events_audit".to_string()),
Self::ConnectorEventsAnalytics => Ok("connector_events".to_string()),
Self::PaymentIntent => Ok("payment_intents".to_string()),
Self::ConnectorEvents => Ok("connector_events_audit".to_string()),
Self::OutgoingWebhookEvent => Ok("outgoing_webhook_events_audit".to_string()),
@ -423,6 +437,20 @@ where
alias.map_or_else(|| "".to_owned(), |alias| format!(" as {}", alias))
)
}
Self::Percentile {
field,
alias,
percentile,
} => {
format!(
"quantilesExact(0.{})({})[1]{}",
percentile.map_or_else(|| "50".to_owned(), |percentile| percentile.to_string()),
field
.to_sql(table_engine)
.attach_printable("Failed to percentile aggregate")?,
alias.map_or_else(|| "".to_owned(), |alias| format!(" as {}", alias))
)
}
})
}
}