Skip to content

feat(analytics): modified authentication queries and added generate report for authentications#7483

Merged
likhinbopanna merged 6 commits intomainfrom
authentication-analytics-revamp
Mar 12, 2025
Merged

feat(analytics): modified authentication queries and added generate report for authentications#7483
likhinbopanna merged 6 commits intomainfrom
authentication-analytics-revamp

Conversation

@tsdk02
Copy link
Contributor

@tsdk02 tsdk02 commented Mar 11, 2025

Type of Change

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

Description

This PR modifies authentication queries to improve the way we distinguish between authentication flows. Previously, trans_status was used for this purpose, but it has now been replaced with authentication_type, which more explicitly differentiates between frictionless flow and challenge flow.

Additionally, this PR introduces support for authentication report generation, similar to the existing reports for payments, refunds, and disputes.

Key Changes

1. Updated Authentication Queries

  • Replaced trans_status with authentication_type in authentication queries.
  • Ensures a clearer distinction between frictionless flow and challenge flow during authentication.

2. Added Authentication Report Generation

  • Introduced report generation for authentications, aligning with the existing reporting structure for payments, 'refundsanddisputes`.

Routes for the reporting service:

  • Org level report: /analytics/v1/org/report/authentications
  • Merchant level report: /analytics/v1/merchant/report/authentications
  • Profile level report: /analytics/v1/profile/report/authentications

This PR resolves the data correctness issue raised here: https://github.com/juspay/hyperswitch-cloud/issues/8727

Additional Changes

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

Motivation and Context

  • Using authentication_type instead of trans_status improves accuracy in flow differentiation.
  • Authentication reporting enables better tracking and analytics for user authentication flows.

How did you test it?

Can check the test cases from the How did you test it? section from these 2 PRs:

Note: The Response body should be validated from this PR for all the metrics: #7451

Curl for Authentication Report:

curl --location 'http://localhost:8080/analytics/v1/org/report/authentications' \
--header 'Accept: */*' \
--header 'Accept-Language: en-US,en;q=0.9' \
--header 'Connection: keep-alive' \
--header 'Content-Type: application/json' \
--header 'Origin: http://localhost:9000' \
--header 'Referer: http://localhost:9000/' \
--header 'Sec-Fetch-Dest: empty' \
--header 'Sec-Fetch-Mode: cors' \
--header 'Sec-Fetch-Site: same-site' \
--header 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36' \
--header 'api-key: test_admin' \
--header 'authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoiNmNkZTA0NzYtMTFlMi00NGE5LTlkMjUtOTA5M2QzNDQwZjhlIiwibWVyY2hhbnRfaWQiOiJtZXJjaGFudF8xNzM1MDQxMjkzIiwicm9sZV9pZCI6Im9yZ19hZG1pbiIsImV4cCI6MTczNjYwNDY3OCwib3JnX2lkIjoib3JnX2pwanI5TkFEWlhqSENNYTU5MmF3IiwicHJvZmlsZV9pZCI6InByb19QRHUydVA3aWNuM2lXY0I3V0VVSSIsInRlbmFudF9pZCI6InB1YmxpYyJ9.7_cuWH5XygVrtIDsbh7nusrjGcQ3jbcaPKhIOo3EbM8' \
--header 'sec-ch-ua: "Chromium";v="128", "Not;A=Brand";v="24", "Google Chrome";v="128"' \
--header 'sec-ch-ua-mobile: ?0' \
--header 'sec-ch-ua-platform: "macOS"' \
--header 'Cookie: login_token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoiMDU1MmY3YzctMmNjZC00ZmU3LThkM2ItY2U1M2ExMTJhZTIwIiwibWVyY2hhbnRfaWQiOiJtZXJjaGFudF8xNzQxNjk5OTg4Iiwicm9sZV9pZCI6Im9yZ19hZG1pbiIsImV4cCI6MTc0MTg3MjgwMiwib3JnX2lkIjoib3JnX2hQamlOektmbmV6NG8wNjdVVlFwIiwicHJvZmlsZV9pZCI6InByb19kWWJpUm9NVkFkNDAwWEh6R3hYTiIsInRlbmFudF9pZCI6InB1YmxpYyJ9.1bsDkYwwk8FtWrDEYdMIsjmH7DqWOVejX2GVseu68ZQ' \
--data-raw '{
    "timeRange": {
        "startTime": "2025-01-08T13:56:15Z",
        "endTime": "2025-01-09T13:56:15.277Z"
    },
    "emails": [
        "sandeep.kumar@juspay.in"
    ]
}'

Queries:

Authentication Attempt Count:

SELECT sum(sign_flag) as count, min(created_at) as start_bucket, max(created_at) as end_bucket FROM authentications WHERE ( merchant_id = 'merchant_1740414909' AND authentication_status IN ('success', 'failed') AND created_at >= '1726079400' AND created_at <= '1727256120' ) GROUP BY toStartOfDay(created_at) HAVING sum(sign_flag) >= '1'

Authentication Count:

SELECT sum(sign_flag) as count, min(created_at) as start_bucket, max(created_at) as end_bucket FROM authentications WHERE ( merchant_id = 'merchant_1740414909' AND created_at >= '1726079400' AND created_at <= '1727256120' ) GROUP BY toStartOfDay(created_at) HAVING sum(sign_flag) >= '1'

Authentication Success Count:

SELECT sum(sign_flag) as count, min(created_at) as start_bucket, max(created_at) as end_bucket FROM authentications WHERE ( merchant_id = 'merchant_1740414909' AND authentication_status = 'success' AND created_at >= '1726079400' AND created_at <= '1727256120' ) GROUP BY toStartOfDay(created_at) HAVING sum(sign_flag) >= '1'

Challenge Attempt Count:

SELECT sum(sign_flag) as count, min(created_at) as start_bucket, max(created_at) as end_bucket FROM authentications WHERE ( merchant_id = 'merchant_1740414909' AND authentication_type = 'challenge' AND authentication_status in ('success', 'failed') AND created_at >= '1726079400' AND created_at <= '1727256120' ) GROUP BY toStartOfDay(created_at) HAVING sum(sign_flag) >= '1'

Challenge Flow Count:

SELECT sum(sign_flag) as count, min(created_at) as start_bucket, max(created_at) as end_bucket FROM authentications WHERE ( merchant_id = 'merchant_1740414909' AND authentication_type = 'challenge' AND created_at >= '1726079400' AND created_at <= '1727256120' ) GROUP BY toStartOfDay(created_at) HAVING sum(sign_flag) >= '1'

Challenge Success Count:

SELECT sum(sign_flag) as count, min(created_at) as start_bucket, max(created_at) as end_bucket FROM authentications WHERE ( merchant_id = 'merchant_1740414909' AND authentication_status = 'success' AND authentication_type = 'challenge' AND created_at >= '1726079400' AND created_at <= '1727256120' ) GROUP BY toStartOfDay(created_at) HAVING sum(sign_flag) >= '1'

Frictionless Flow Count:

SELECT sum(sign_flag) as count, min(created_at) as start_bucket, max(created_at) as end_bucket FROM authentications WHERE ( merchant_id = 'merchant_1740414909' AND authentication_type = 'frictionless' AND created_at >= '1738402351' AND created_at <= '1740216751' ) GROUP BY toStartOfDay(created_at) HAVING sum(sign_flag) >= '1'

Frictionless Success Count:

SELECT sum(sign_flag) as count, min(created_at) as start_bucket, max(created_at) as end_bucket FROM authentications WHERE ( merchant_id = 'merchant_1740414909' AND authentication_type = 'frictionless' AND authentication_status = 'success' AND created_at >= '1738402351' AND created_at <= '1740216751' ) GROUP BY toStartOfDay(created_at) HAVING sum(sign_flag) >= '1'

Authentication Funnel: (2nd step):

SELECT sum(sign_flag) as count, min(created_at) as start_bucket, max(created_at) as end_bucket FROM authentications WHERE ( merchant_id = 'merchant_1740414909' AND trans_status IS NOT NULL AND created_at >= '1738434600' AND created_at <= '1740734520' )

Authentication Funnel: (3rd step):

SELECT sum(sign_flag) as count, min(created_at) as start_bucket, max(created_at) as end_bucket FROM authentications WHERE ( merchant_id = 'merchant_1740414909' AND trans_status IS NOT NULL AND authentication_status IN ('success', 'failed') AND created_at >= '1738434600' AND created_at <= '1740734520' )

Authentication Error Message:

SELECT error_message, sum(sign_flag) AS count, min(created_at) as start_bucket, max(created_at) as end_bucket FROM authentications WHERE ( merchant_id = 'merchant_1741712401' AND authentication_status = 'failed' AND error_message IS NOT NULL AND created_at >= '1738434600' AND created_at <= '1740734520' ) GROUP BY error_message HAVING sum(sign_flag) >= '1' ORDER BY count desc

Sample Output:
You should be able to receive an email with the authentication report to the email specified in the request.

Similarly, just replace org with merchant and profile in the URL for the corresponding authentication report at the merchant and profile level.

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

@tsdk02 tsdk02 added C-bug Category: Bug C-feature Category: Feature request or enhancement A-Analytics labels Mar 11, 2025
@tsdk02 tsdk02 self-assigned this Mar 11, 2025
@tsdk02 tsdk02 requested a review from a team as a code owner March 11, 2025 17:25
@semanticdiff-com
Copy link

semanticdiff-com bot commented Mar 11, 2025

@likhinbopanna likhinbopanna added this pull request to the merge queue Mar 12, 2025
Merged via the queue into main with commit 9683b2a Mar 12, 2025
15 of 20 checks passed
@likhinbopanna likhinbopanna deleted the authentication-analytics-revamp branch March 12, 2025 11:35
tsdk02 added a commit that referenced this pull request Mar 12, 2025
…eport for authentications (#7483)

Co-authored-by: Sandeep Kumar <sandeep.kumar@Sandeep-Kumar-LVF93XQXPC.local>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Analytics C-bug Category: Bug C-feature Category: Feature request or enhancement

Projects

None yet

4 participants