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(dynamic_routing): analytics improvement using separate postgres table #6723

Merged
merged 33 commits into from
Dec 7, 2024

Conversation

prajjwalkumar17
Copy link
Contributor

@prajjwalkumar17 prajjwalkumar17 commented Dec 2, 2024

Type of Change

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

Description

Previously we were pushing the Dynamic routing metrics to Prometheus, but due to high cardinality of some values(payment_id) we were not able to add that in our attributes, hence we are pushing this after creating a new table in our Database (dynamic_routing_stats).

The further enhancement will be done in this track:
#6756

Additional Changes

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

Motivation and Context

Required to get the payment_id for our metrics purpose.

How did you test it?

Can be tested in the following ways:

  1. enable success_based_routing(feature = metrics) for merchant.
curl --location --request POST 'http://localhost:8080/account/m_id/business_profile/pro_id/dynamic_routing/success_based/toggle?enable=metrics' \
--header 'api-key:api_key'
  1. Make a payment afterwards.
  2. Check the dynamic_routing_stats table for the specific value associated with the payment_id.
Screenshot 2024-12-06 at 6 31 56 PM

Migration

CREATE TYPE "SuccessBasedRoutingConclusiveState" AS ENUM(
  'true_positive',
  'false_positive',
  'true_negative',
  'false_negative'
);

CREATE TABLE IF NOT EXISTS dynamic_routing_stats (
    payment_id VARCHAR(64) NOT NULL,
    attempt_id VARCHAR(64) NOT NULL,
    merchant_id VARCHAR(64) NOT NULL,
    profile_id VARCHAR(64) NOT NULL,
    amount BIGINT NOT NULL,
    success_based_routing_connector VARCHAR(64) NOT NULL,
    payment_connector VARCHAR(64) NOT NULL,
    currency "Currency",
    payment_method VARCHAR(64),
    capture_method "CaptureMethod",
    authentication_type "AuthenticationType",
    payment_status "AttemptStatus" NOT NULL,
    conclusive_classification "SuccessBasedRoutingConclusiveState" NOT NULL,
    created_at TIMESTAMP NOT NULL,
    PRIMARY KEY(attempt_id, merchant_id)
);
CREATE INDEX profile_id_index ON dynamic_routing_stats (profile_id);

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

@prajjwalkumar17 prajjwalkumar17 requested review from a team as code owners December 2, 2024 17:06
@prajjwalkumar17 prajjwalkumar17 marked this pull request as draft December 2, 2024 17:06
@hyperswitch-bot hyperswitch-bot bot added the M-database-changes Metadata: This PR involves database schema changes label Dec 2, 2024
@prajjwalkumar17 prajjwalkumar17 linked an issue Dec 3, 2024 that may be closed by this pull request
@prajjwalkumar17 prajjwalkumar17 self-assigned this Dec 3, 2024
@prajjwalkumar17 prajjwalkumar17 added A-routing Area: Routing C-feature Category: Feature request or enhancement labels Dec 3, 2024
@prajjwalkumar17 prajjwalkumar17 added this to the December 2024 Release milestone Dec 3, 2024
@prajjwalkumar17 prajjwalkumar17 changed the title feature(dynamic_routing): analytics improvement using separate postgres table feature(euclid): analytics improvement using separate postgres table Dec 3, 2024
@prajjwalkumar17 prajjwalkumar17 changed the title feature(euclid): analytics improvement using separate postgres table feat(dynamic_routing): analytics improvement using separate postgres table Dec 3, 2024
@prajjwalkumar17 prajjwalkumar17 marked this pull request as ready for review December 3, 2024 06:36
crates/diesel_models/src/dynamic_routing_stats.rs Outdated Show resolved Hide resolved
crates/router/src/core/routing/helpers.rs Outdated Show resolved Hide resolved
crates/diesel_models/src/dynamic_routing_stats.rs Outdated Show resolved Hide resolved
crates/diesel_models/src/dynamic_routing_stats.rs Outdated Show resolved Hide resolved
crates/router/src/core/routing/helpers.rs Outdated Show resolved Hide resolved
Chethan-rao
Chethan-rao previously approved these changes Dec 5, 2024
SanchithHegde
SanchithHegde previously approved these changes Dec 5, 2024
@likhinbopanna likhinbopanna added this pull request to the merge queue Dec 6, 2024
@prajjwalkumar17 prajjwalkumar17 removed this pull request from the merge queue due to a manual request Dec 6, 2024
Chethan-rao
Chethan-rao previously approved these changes Dec 6, 2024
@likhinbopanna likhinbopanna added this pull request to the merge queue Dec 7, 2024
Merged via the queue into main with commit 5918014 Dec 7, 2024
16 of 18 checks passed
@likhinbopanna likhinbopanna deleted the analytics_sr branch December 7, 2024 09:31
kashif-m pushed a commit that referenced this pull request Dec 12, 2024
…table (#6723)

Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-routing Area: Routing C-feature Category: Feature request or enhancement M-database-changes Metadata: This PR involves database schema changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature(routing): Stats table for dynamic_routing
4 participants