Skip to content

Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation

chore(analytics): adding dispute id to api log events (#3450)

harsh-sharma-juspay937aea906e75
diff --git a/crates/analytics/docs/clickhouse/cluster_setup/scripts/api_event_logs.sql b/crates/analytics/docs/clickhouse/cluster_setup/scripts/api_event_logs.sql
index 0fe194a0e6..ad0fe6d778 100644
--- a/crates/analytics/docs/clickhouse/cluster_setup/scripts/api_event_logs.sql
+++ b/crates/analytics/docs/clickhouse/cluster_setup/scripts/api_event_logs.sql
@@ -18,7 +18,8 @@ CREATE TABLE hyperswitch.api_events_queue on cluster '{cluster}' (
`created_at` DateTime CODEC(T64, LZ4),
`latency` Nullable(UInt128),
`user_agent` Nullable(String),
- `ip_addr` Nullable(String)
+ `ip_addr` Nullable(String),
+ `dispute_id` Nullable(String)
) ENGINE = Kafka SETTINGS kafka_broker_list = 'hyper-c1-kafka-brokers.kafka-cluster.svc.cluster.local:9092',
kafka_topic_list = 'hyperswitch-api-log-events',
kafka_group_name = 'hyper-c1',
@@ -81,7 +82,8 @@ CREATE TABLE hyperswitch.api_events_dist on cluster '{cluster}' (
`created_at` DateTime64(3),
`latency` Nullable(UInt128),
`user_agent` Nullable(String),
- `ip_addr` Nullable(String)
+ `ip_addr` Nullable(String),
+ `dispute_id` Nullable(String)
) ENGINE = Distributed('{cluster}', 'hyperswitch', 'api_events_clustered', rand());
CREATE MATERIALIZED VIEW hyperswitch.api_events_mv on cluster '{cluster}' TO hyperswitch.api_events_dist (
@@ -105,7 +107,8 @@ CREATE MATERIALIZED VIEW hyperswitch.api_events_mv on cluster '{cluster}' TO hyp
`created_at` DateTime64(3),
`latency` Nullable(UInt128),
`user_agent` Nullable(String),
- `ip_addr` Nullable(String)
+ `ip_addr` Nullable(String),
+ `dispute_id` Nullable(String)
) AS
SELECT
merchant_id,
@@ -158,7 +161,7 @@ WHERE length(_error) > 0
ALTER TABLE hyperswitch.api_events_clustered on cluster '{cluster}' ADD COLUMN `url_path` LowCardinality(Nullable(String));
ALTER TABLE hyperswitch.api_events_clustered on cluster '{cluster}' ADD COLUMN `event_type` LowCardinality(Nullable(String));
-
+ALTER TABLE hyperswitch.api_events_clustered on cluster '{cluster}' ADD COLUMN `dispute_id` Nullable(String);
CREATE TABLE hyperswitch.api_audit_log ON CLUSTER '{cluster}' (
`merchant_id` LowCardinality(String),
@@ -209,7 +212,8 @@ CREATE MATERIALIZED VIEW hyperswitch.api_audit_log_mv ON CLUSTER `{cluster}` TO
`created_at` DateTime64(3),
`latency` Nullable(UInt128),
`user_agent` Nullable(String),
- `ip_addr` Nullable(String)
+ `ip_addr` Nullable(String),
+ `dispute_id` Nullable(String)
) AS
SELECT
merchant_id,
@@ -232,6 +236,7 @@ SELECT
created_at,
latency,
user_agent,
- ip_addr
+ ip_addr,
+ dispute_id
FROM hyperswitch.api_events_queue
WHERE length(_error) = 0
\ No newline at end of file
diff --git a/crates/analytics/docs/clickhouse/scripts/api_events.sql b/crates/analytics/docs/clickhouse/scripts/api_events.sql
index c3fc3d7b06..49a6472eaa 100644
--- a/crates/analytics/docs/clickhouse/scripts/api_events.sql
+++ b/crates/analytics/docs/clickhouse/scripts/api_events.sql
@@ -23,7 +23,8 @@ CREATE TABLE api_events_queue (
`ip_addr` String,
`hs_latency` Nullable(UInt128),
`http_method` LowCardinality(String),
- `url_path` String
+ `url_path` String,
+ `dispute_id` Nullable(String)
) ENGINE = Kafka SETTINGS kafka_broker_list = 'kafka0:29092',
kafka_topic_list = 'hyperswitch-api-log-events',
kafka_group_name = 'hyper-c1',
@@ -57,6 +58,7 @@ CREATE TABLE api_events_dist (
`hs_latency` Nullable(UInt128),
`http_method` LowCardinality(String),
`url_path` String,
+ `dispute_id` Nullable(String)
INDEX flowIndex flow_type TYPE bloom_filter GRANULARITY 1,
INDEX apiIndex api_flow TYPE bloom_filter GRANULARITY 1,
INDEX statusIndex status_code TYPE bloom_filter GRANULARITY 1
@@ -92,7 +94,8 @@ CREATE MATERIALIZED VIEW api_events_mv TO api_events_dist (
`ip_addr` String,
`hs_latency` Nullable(UInt128),
`http_method` LowCardinality(String),
- `url_path` String
+ `url_path` String,
+ `dispute_id` Nullable(String)
) AS
SELECT
merchant_id,
@@ -120,7 +123,8 @@ SELECT
ip_addr,
hs_latency,
http_method,
- url_path
+ url_path,
+ dispute_id
FROM
api_events_queue
where length(_error) = 0;
diff --git a/crates/api_models/src/events.rs b/crates/api_models/src/events.rs
index a8185d2d24..ae0525ac60 100644
--- a/crates/api_models/src/events.rs
+++ b/crates/api_models/src/events.rs
@@ -1,5 +1,6 @@
pub mod connector_onboarding;
pub mod customer;
+pub mod dispute;
pub mod gsm;
mod locker_migration;
pub mod payment;
@@ -44,8 +45,6 @@ impl_misc_api_event_type!(
RetrievePaymentLinkResponse,
MandateListConstraints,
CreateFileResponse,
- DisputeResponse,
- SubmitEvidenceRequest,
MerchantConnectorResponse,
MerchantConnectorId,
MandateResponse,
diff --git a/crates/api_models/src/events/dispute.rs b/crates/api_models/src/events/dispute.rs
new file mode 100644
index 0000000000..101dba3ca0
--- /dev/null
+++ b/crates/api_models/src/events/dispute.rs
@@ -0,0 +1,25 @@
+use common_utils::events::{ApiEventMetric, ApiEventsType};
+
+use super::{DisputeResponse, DisputeResponsePaymentsRetrieve, SubmitEvidenceRequest};
+
+impl ApiEventMetric for SubmitEvidenceRequest {
+ fn get_api_event_type(&self) -> Option<ApiEventsType> {
+ Some(ApiEventsType::Dispute {
+ dispute_id: self.dispute_id.clone(),
+ })
+ }
+}
+impl ApiEventMetric for DisputeResponsePaymentsRetrieve {
+ fn get_api_event_type(&self) -> Option<ApiEventsType> {
+ Some(ApiEventsType::Dispute {
+ dispute_id: self.dispute_id.clone(),
+ })
+ }
+}
+impl ApiEventMetric for DisputeResponse {
+ fn get_api_event_type(&self) -> Option<ApiEventsType> {
+ Some(ApiEventsType::Dispute {
+ dispute_id: self.dispute_id.clone(),
+ })
+ }
+}
diff --git a/crates/common_utils/src/events.rs b/crates/common_utils/src/events.rs
index c2bf50d96c..e755e0f9c4 100644
--- a/crates/common_utils/src/events.rs
+++ b/crates/common_utils/src/events.rs
@@ -50,6 +50,9 @@ pub enum ApiEventsType {
RustLocker,
FraudCheck,
Recon,
+ Dispute {
+ dispute_id: String,
+ },
}
impl ApiEventMetric for serde_json::Value {}
diff --git a/crates/router/src/events/api_logs.rs b/crates/router/src/events/api_logs.rs
index 78a66d2f04..3d74a02884 100644
--- a/crates/router/src/events/api_logs.rs
+++ b/crates/router/src/events/api_logs.rs
@@ -114,7 +114,6 @@ impl_misc_api_event_type!(
CreateFileRequest,
FileId,
AttachEvidenceRequest,
- DisputeId,
PaymentLinkFormData,
ConfigUpdate
);
@@ -142,3 +141,11 @@ impl ApiEventMetric for PaymentsRedirectResponseData {
})
}
}
+
+impl ApiEventMetric for DisputeId {
+ fn get_api_event_type(&self) -> Option<ApiEventsType> {
+ Some(ApiEventsType::Dispute {
+ dispute_id: self.dispute_id.clone(),
+ })
+ }
+}