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: realtime user analytics #5098

Merged
merged 24 commits into from
Jun 26, 2024
Merged

Conversation

vsrivatsa-juspay
Copy link
Contributor

@vsrivatsa-juspay vsrivatsa-juspay commented Jun 24, 2024

Type of Change

  • Bugfix
  • New feature
  • Enhancement
  • Refactoring
  • Dependency updates
  • Documentation
  • CI/CD

Description

This PR introduces a real-time analytics feature that allows merchants to track distinct payment IDs on their dashboards. The key components of this feature include a script to create a ClickHouse table with a 1-minute Time-To-Live (TTL) for the data, and an analytics service that counts distinct payment IDs.
Also add the the http server for vector to collect and push logs to kafka in this PR.

Changes:

ClickHouse Table Creation Script:
Added a script to create a ClickHouse table with a 1-minute TTL. This table will store payment events and automatically purge entries older than 1 minute, ensuring that only recent data is kept for real-time analytics.

Analytics Service:
Implemented an analytics service that queries the ClickHouse table to count distinct payment IDs. This provides real-time insights into the number of unique payments processed within the last minute.

Additional Changes

  • This PR modifies the API contract
  • This PR modifies the database schema
  • This PR modifies application configuration/environment variables

Motivation and Context

How did you test it?

1. Start the necessary services using Docker Compose

docker compose up -d kafka-ui clickhouse-server

2. Load the SDK and simulate payments
3. Verify Real-Time Analytics

curl --location 'localhost:8080/analytics/v1/metrics/active_payments' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer {token}' \
--data '[
    {
        "timeRange": {
            "startTime": "2024-06-24T18:30:00Z",
            "endTime": "2024-06-24T18:31:00Z"
        },
        "metrics": [
            "active_payments"
        ]
    }
]'
{
    "queryData": [
        {
            "active_payments": 2
        }
    ],
    "metaData": [
        {
            "current_time_range": {
              "start_time": "2024-06-24T18:30:00Z",
              "end_time": "2024-06-24T18:31:00Z"
            }
        }
    ]
}

Checklist

  • I formatted the code cargo +nightly fmt --all
  • I addressed lints thrown by cargo clippy
  • I reviewed the submitted code
  • I added unit tests for my changes where possible

@vsrivatsa-juspay vsrivatsa-juspay requested review from a team as code owners June 24, 2024 11:00
@hyperswitch-bot hyperswitch-bot bot added the M-database-changes Metadata: This PR involves database schema changes label Jun 24, 2024
@vsrivatsa-juspay vsrivatsa-juspay force-pushed the feat/realtime_user_analytics branch 2 times, most recently from 224008f to 010e617 Compare June 24, 2024 11:12
@vsrivatsa-juspay vsrivatsa-juspay removed the M-database-changes Metadata: This PR involves database schema changes label Jun 24, 2024
@hyperswitch-bot hyperswitch-bot bot added the M-database-changes Metadata: This PR involves database schema changes label Jun 24, 2024
@hyperswitch-bot hyperswitch-bot bot removed the M-database-changes Metadata: This PR involves database schema changes label Jun 24, 2024
@vsrivatsa-juspay vsrivatsa-juspay requested a review from a team as a code owner June 25, 2024 09:01
@vsrivatsa-juspay vsrivatsa-juspay linked an issue Jun 25, 2024 that may be closed by this pull request
@vsrivatsa-juspay vsrivatsa-juspay added A-Analytics low-risk label to track PRs which might have less impact on hyperswitch after merge S-waiting-on-review Status: This PR has been implemented and needs to be reviewed labels Jun 25, 2024
crates/analytics/src/active_payments/core.rs Outdated Show resolved Hide resolved
config/vector.yaml Show resolved Hide resolved
Co-authored-by: Sampras Lopes <[email protected]>
lsampras
lsampras previously approved these changes Jun 25, 2024
lsampras
lsampras previously approved these changes Jun 25, 2024
ivor-juspay
ivor-juspay previously approved these changes Jun 26, 2024
@likhinbopanna likhinbopanna added this pull request to the merge queue Jun 26, 2024
Merged via the queue into main with commit cd5a1a3 Jun 26, 2024
11 checks passed
@likhinbopanna likhinbopanna deleted the feat/realtime_user_analytics branch June 26, 2024 12:09
pixincreate added a commit that referenced this pull request Jun 28, 2024
…ay/hyperswitch into iatapay-through-hyperswitch-cypress

* 'iatapay-through-hyperswitch-cypress' of github.com:juspay/hyperswitch:
  feat(router): skip apple pay session call if the browser is not Safari (#5136)
  fix(opensearch): show search results only if user has access permission to the index  (#5097)
  chore(version): 2024.06.27.0
  feat(users): add endpoint for terminate auth select (#5135)
  feat(users): implemented openidconnect (#5124)
  feat(router): add payments manual-update api (#5045)
  fix(docs): open-api fix for payment response (#5103)
  refactor(connector): [AdyenPlatform]Throw 4xx instead of 5xx for source_balance_account (#4990)
  feat: realtime user analytics (#5098)
  refactor(connector): added amount conversion framework for cashtocode (#4857)
  feat(email): Add `auth_id` in email types and send `auth_id` in email URLs (#5120)
  refactor(connector): add amount framework to payme & Trustpay with googlePay, ApplePay for bluesnap, Noon & Trustpay (#4833)
  fix(connector): [BOA/CYBS] make risk information message optional (#5107)
  chore(version): 2024.06.25.1
  fix(router): skip serialize if none for assurance_details_required in googlepay session response (#5118)
  refactor: separate DB queries and HTML creation for payout links (#4967)
  feat(router): updated `last_used_at` field for apple pay and google pay for CITs (#5087)
  fix(payment_methods): use existing field value of `nick_name` in db if not sent during request (#5105)
  chore(version): 2024.06.25.0
pixincreate added a commit that referenced this pull request Jun 28, 2024
…ay/hyperswitch into refactor-error-handling-in-cypress

* 'iatapay-through-hyperswitch-cypress' of github.com:juspay/hyperswitch:
  chore: clean up
  feat(router): skip apple pay session call if the browser is not Safari (#5136)
  fix(opensearch): show search results only if user has access permission to the index  (#5097)
  chore(version): 2024.06.27.0
  feat(users): add endpoint for terminate auth select (#5135)
  feat(users): implemented openidconnect (#5124)
  feat(router): add payments manual-update api (#5045)
  fix(docs): open-api fix for payment response (#5103)
  refactor(connector): [AdyenPlatform]Throw 4xx instead of 5xx for source_balance_account (#4990)
  feat: realtime user analytics (#5098)
  refactor(connector): added amount conversion framework for cashtocode (#4857)
  feat(email): Add `auth_id` in email types and send `auth_id` in email URLs (#5120)
  refactor(connector): add amount framework to payme & Trustpay with googlePay, ApplePay for bluesnap, Noon & Trustpay (#4833)
  fix(connector): [BOA/CYBS] make risk information message optional (#5107)
  chore(version): 2024.06.25.1
  fix(router): skip serialize if none for assurance_details_required in googlepay session response (#5118)
  refactor: separate DB queries and HTML creation for payout links (#4967)
  feat(router): updated `last_used_at` field for apple pay and google pay for CITs (#5087)
  fix(payment_methods): use existing field value of `nick_name` in db if not sent during request (#5105)
  chore(version): 2024.06.25.0
@SanchithHegde SanchithHegde removed S-waiting-on-review Status: This PR has been implemented and needs to be reviewed low-risk label to track PRs which might have less impact on hyperswitch after merge labels Jun 30, 2024
@vsrivatsa-juspay vsrivatsa-juspay mentioned this pull request Jul 2, 2024
14 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add vector service to accept events from SDK
5 participants