Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(analytics): Add Clickhouse based analytics #2988

Merged
merged 40 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
12d9e40
feat(analytics): add clickhouse support for analytics
lsampras Nov 22, 2023
7477ea7
feat(events): add kafka as alternate event handler
lsampras Nov 22, 2023
bac204b
chore(lints): fix fmt lints
lsampras Nov 22, 2023
23e6758
feat(events): add kafka events
lsampras Nov 23, 2023
a9202b6
fix(lints): fix fmt lints
lsampras Nov 23, 2023
9cc8dd8
impl kafka store
harsh-sharma-juspay Nov 23, 2023
af1d824
impl kafka store
harsh-sharma-juspay Nov 23, 2023
89d6a74
fix(report): remove explicit validation for report settings config
lsampras Nov 24, 2023
8a0aac0
impl kafka store
harsh-sharma-juspay Nov 25, 2023
6a209bc
feat(kafka): add kafka config event handler
lsampras Nov 27, 2023
d7e3c87
fix(events): add basic default configurations for kafka events
lsampras Nov 27, 2023
7089de5
chore(lints): fix fmt lints
lsampras Nov 27, 2023
a03b7bc
Merge remote-tracking branch 'origin/main' into analytics_oss_migration
lsampras Nov 27, 2023
35a40ac
olap feature analytics
harsh-sharma-juspay Nov 28, 2023
5f18a74
chore(lints): fix dockerfile lints
lsampras Nov 28, 2023
ac8f6ab
docs(analytics): add kafka & ckh local setup
lsampras Nov 28, 2023
335ce3e
made event handler trait pub
ivor11 Nov 28, 2023
8e740fa
fix(lints): fix cargo hack lints
lsampras Nov 28, 2023
07ea55f
impl default for EventsHandler
ivor11 Nov 28, 2023
1daaaef
updating audit logs
harsh-sharma-juspay Nov 28, 2023
b00da58
Merge branch 'analytics_oss_migration' of github.com:juspay/hyperswit…
harsh-sharma-juspay Nov 28, 2023
aecdd92
CI: update the credentails for generating token in release new versio…
Chethan-rao Nov 27, 2023
d6a2802
refactor(masking): use empty enums as masking:Strategy<T> types (#2874)
nain-F49FF806 Nov 28, 2023
1f3279b
feat(currency_conversion): add currency conversion feature (#2948)
lsampras Nov 28, 2023
083a539
feat(payment_methods): receive `card_holder_name` in confirm flow whe…
Chethan-rao Nov 28, 2023
e673b0c
Merge remote-tracking branch 'origin/main' into analytics_oss_migration
lsampras Nov 28, 2023
661f273
filter api_name to api_flow
harsh-sharma-juspay Nov 28, 2023
3cac077
Merge branch 'analytics_oss_migration' of github.com:juspay/hyperswit…
harsh-sharma-juspay Nov 28, 2023
68776fa
refactor: Added min idle and max lifetime for database config (#2900)
lsampras Nov 28, 2023
3729e0f
Merge remote-tracking branch 'origin/main' into analytics_oss_migration
lsampras Nov 28, 2023
7dc22a9
fix(lints): remove duplicate definitions
lsampras Nov 28, 2023
67b7e00
error dist response structure refactor
ivor11 Nov 29, 2023
4c08c7d
fix(events): allow validation to be called publicly
lsampras Nov 29, 2023
308f776
Merge remote-tracking branch 'origin/main' into analytics_oss_migration
lsampras Nov 29, 2023
cf95548
fix(kafkastore): add missing impls to kafka store
lsampras Nov 29, 2023
d363980
chore: run formatter
hyperswitch-bot[bot] Nov 29, 2023
1cb371e
filter api_name to api_flow
harsh-sharma-juspay Nov 29, 2023
eb1fa30
chore(lints): fix clippy lints
lsampras Nov 29, 2023
51f669c
chore(lints): fix clippy lints
lsampras Nov 29, 2023
056cc54
chore(lints): fix clippy lints
lsampras Nov 29, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
119 changes: 119 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions config/development.toml
lsampras marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -459,3 +459,33 @@ delay_between_retries_in_milliseconds = 500

[kv_config]
ttl = 900 # 15 * 60 seconds

[events]
source = "logs"

[events.kafka]
brokers = ["localhost:9092"]
intent_analytics_topic = "hyperswitch-payment-intent-events"
attempt_analytics_topic = "hyperswitch-payment-attempt-events"
refund_analytics_topic = "hyperswitch-refund-events"
api_logs_topic = "hyperswitch-api-log-events"
connector_events_topic = "hyperswitch-connector-api-events"

[analytics]
source = "sqlx"

[analytics.clickhouse]
username = "default"
# password = ""
host = "http://localhost:8123"
database_name = "default"

[analytics.sqlx]
username = "db_user"
password = "db_pass"
host = "localhost"
port = 5432
dbname = "hyperswitch_db"
pool_size = 5
connection_timeout = 10
queue_strategy = "Fifo"
36 changes: 36 additions & 0 deletions crates/analytics/Cargo.toml
lsampras marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
[package]
name = "analytics"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html


[dependencies]
# First party crates
api_models = { version = "0.1.0", path = "../api_models" }
storage_impl = { version = "0.1.0", path = "../storage_impl" }
common_utils = { version = "0.1.0", path = "../common_utils"}
external_services = { version = "0.1.0", path = "../external_services", default-features = false}
masking = { version = "0.1.0", path = "../masking" }
router_env = { version = "0.1.0", path = "../router_env", features = ["log_extra_implicit_fields", "log_custom_entries_to_extra"] }
diesel_models = { version = "0.1.0", path = "../diesel_models", features = ["kv_store"] }

#Third Party dependencies
actix-web = "4.3.1"
async-trait = "0.1.68"
aws-config = { version = "0.55.3" }
aws-sdk-lambda = { version = "0.28.0" }
aws-smithy-types = { version = "0.55.3" }
bigdecimal = { version = "0.3.1", features = ["serde"] }
error-stack = "0.3.1"
futures = "0.3.28"
once_cell = "1.18.0"
reqwest = { version = "0.11.18", features = ["serde_json"] }
serde = { version = "1.0.163", features = ["derive", "rc"] }
serde_json = "1.0.96"
sqlx = { version = "0.6.3", features = ["postgres", "runtime-actix", "runtime-actix-native-tls", "time", "bigdecimal"] }
strum = { version = "0.24.1", features = ["derive"] }
thiserror = "1.0.43"
time = { version = "0.3.21", features = ["serde", "serde-well-known", "std"] }
tokio = { version = "1.28.2", features = ["macros", "rt-multi-thread"] }
45 changes: 45 additions & 0 deletions crates/analytics/docs/clickhouse/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#### Starting the containers

In our use case we rely on kafka for ingesting events.
hence we can use docker compose to start all the components

```
docker compose up -d clickhouse-server kafka-ui
```

> kafka-ui is a visual tool for inspecting kafka on localhost:8090

#### Setting up Clickhouse

Once clickhouse is up & running you need to create the required tables for it

you can either visit the url (http://localhost:8123/play) in which the clickhouse-server is running to get a playground
Alternatively you can bash into the clickhouse container & execute commands manually
```
# On your local terminal in hyperswitch-cloud folder
docker compose exec clickhouse-server bash

# Inside the clickhouse-server container shell
clickhouse-client --user default

# Inside the clickhouse-client shell
SHOW TABLES;
CREATE TABLE ......
```

The table creation scripts are provided [here](./scripts)

#### Running/Debugging your application
Once setup you can run your application either via docker compose or normally via cargo run

Remember to enable the kafka_events via development.toml/docker_compose.toml files

Inspect the [kafka-ui](http://localhost:8090) to check the messages being inserted in queue

If the messages/topic are available then you can run select queries on your clickhouse table to ensure data is being populated...

If the data is not being populated in clickhouse, you can check the error logs in clickhouse server via
```
# Inside the clickhouse-server container shell
tail -f /var/log/clickhouse-server/clickhouse-server.err.log
```
Loading