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

refactor(events): populate object identifiers in outgoing webhooks analytics events during retries #5067

Merged
merged 5 commits into from
Jun 24, 2024

Conversation

SanchithHegde
Copy link
Member

Type of Change

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

Description

As of now, the analytics events raised during outgoing webhook retries do not include object identifiers such as the payment ID, refund ID, etc., and in turn, they are not populated in ClickHouse. The object identifiers are only available in the events raised for the initial webhook delivery attempts.

This PR updates the outgoing webhooks code to include the object identifiers in the analytics events for all retries. This is being done by storing the object identifiers in a new column in the events table, called metadata.

In addition, this PR extracts out common code to implement FromSql and ToSql traits on types converted to/from JSON/JSONB into a declarative macro.

Additional Changes

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

This PR adds a metadata column to the events table.

Motivation and Context

Ensuring that all webhook events including retries are correctly associated with the object in question (payment, refund, etc.), and that they are correctly displayed on the control center when viewing events for that resource.

How did you test it?

  1. Configure an incorrect webhook URL in the business profile so that outgoing webhooks are retried.

  2. Perform an action that triggers an outgoing webhook, such as creating a successful payment.

  3. Monitor the events raised for the payment ID in Kafka and ClickHouse:

    Kafka: Searching for messages under the hyperswitch-outgoing-webhook-events topic with the payment ID has multiple events, including retries:

    Screenshot of events sent over Kafka

    ClickHouse: Searching for rows by payment ID in the outgoing_webhook_events table returns multiple rows, all having the payment_id populated, and only the initial attempt having the content field populated.

    SELECT * FROM outgoing_webhook_events WHERE payment_id = 'pay_123' ORDER BY created_at ASC;

    Screenshot of events available in ClickHouse

  4. The analytics API to obtain outgoing webhook event logs returns all of the events, and each of them contain the payment ID:

    curl '{{baseUrl}}/analytics/v1/outgoing_webhook_event_logs?payment_id={{payment_id}}' -H 'Authorization: Bearer <JWT_TOKEN>'

    The control center should also be ideally displaying all the events in the payment details page, that does not seem to be case however in control center version v1.30.1.

  5. Verify similar behavior for the other webhooks with their corresponding identifiers: refunds, payouts, etc.

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

@SanchithHegde SanchithHegde added S-waiting-on-review Status: This PR has been implemented and needs to be reviewed M-database-changes Metadata: This PR involves database schema changes C-refactor Category: Refactor A-webhooks Area: Webhook flows A-Analytics labels Jun 20, 2024
@SanchithHegde SanchithHegde added this to the June 2024 Release milestone Jun 20, 2024
@SanchithHegde SanchithHegde self-assigned this Jun 20, 2024
@SanchithHegde SanchithHegde requested review from a team as code owners June 20, 2024 19:31
crates/common_utils/src/macros.rs Show resolved Hide resolved
@@ -0,0 +1 @@
ALTER TABLE events DROP COLUMN metadata;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ALTER TABLE events DROP COLUMN metadata;
ALTER TABLE events DROP COLUMN IF EXISTS metadata;

@@ -0,0 +1 @@
ALTER TABLE events ADD COLUMN metadata JSONB DEFAULT NULL;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ALTER TABLE events ADD COLUMN metadata JSONB DEFAULT NULL;
ALTER TABLE events ADD COLUMN IF NOT EXISTS metadata JSONB DEFAULT NULL;

@likhinbopanna likhinbopanna added this pull request to the merge queue Jun 24, 2024
Merged via the queue into main with commit b878405 Jun 24, 2024
11 checks passed
@likhinbopanna likhinbopanna deleted the events-add-metadata-with-object-identifiers branch June 24, 2024 07:41
@SanchithHegde SanchithHegde removed the S-waiting-on-review Status: This PR has been implemented and needs to be reviewed label Jun 24, 2024
pixincreate added a commit that referenced this pull request Jun 24, 2024
…ough-hyperswitch-cypress

* 'main' of github.com:juspay/hyperswitch:
  feat(router): add support for googlepay step up flow (#2744)
  fix(access_token): use `merchant_connector_id` in access token (#5106)
  feat: added kafka events for authentication create and update (#4991)
  feat(ci): add vector to handle logs pipeline (#5021)
  feat(users): Decision manager flow changes for SSO (#4995)
  ci(cypress): Fix payment method id for non supported connectors (#5075)
  refactor(core): introduce an interface to switch between old and new connector integration implementations on the connectors (#5013)
  refactor(events): populate object identifiers in outgoing webhooks analytics events during retries (#5067)
  Refactor: [Fiserv] Remove Default Case Handling (#4767)
  chore(version): 2024.06.24.0
  fix(router): avoid considering pre-routing results during `perform_session_token_routing` (#5076)
  refactor(redis): spawn one subscriber thread for handling all the published messages to different channel (#5064)
  feat(users): setup user authentication methods schema and apis (#4999)
  feat(payment_methods): Implement Process tracker workflow for Payment method Status update (#4668)
  chore(version): 2024.06.20.1
  chore(postman): update Postman collection files
  fix(payment_methods): support last used for off session token payments (#5039)
  ci(postman): add net_amount field test cases (#3286)
  refactor(connector): [Mifinity]dynamic fields for mifinity (#5056)
  refactor(payment_method): [Klarna] store and populate payment_type for klarna_sdk Paylater in response (#4956)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Analytics A-webhooks Area: Webhook flows C-refactor Category: Refactor M-database-changes Metadata: This PR involves database schema changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants