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(multitenancy): add support for multitenancy and handle the same in router, producer, consumer, drainer and analytics #4630

Merged
merged 42 commits into from
Jun 3, 2024

Conversation

jagan-jaya
Copy link
Contributor

@jagan-jaya jagan-jaya commented May 13, 2024

Type of Change

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

Description

  1. Add tenant id in sessionState and populate it from request header. All component should take tenant_id only from sessionState
  2. Prefix_tenant_id with redis key. Separate connection management for redis is not needed
  3. Add redirection url based on the tenant base_url
  4. Process tracker to handle tenant-id. To be handled in producer, consumer and drainer

Additional Changes

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

Motivation and Context

To establish tenancy in our application and start using the default tenant as 'Hyperswitch' and also offer a 'test' tenant in all environments

How did you test it?

Test for Scheduler

  1. Enable multitenancy by changing [multitenancy] in development.toml
  2. Create multiple tenants by adding [multitenancy.tenants] in development.toml
  3. Start Router, Producer and Consumer
  4. Create a payment by passing x-tenant-id as <your-tenant> in the request header in localhost:8080
  5. Do the same for both tenants and verify if the payment related data are stored in the respective schema of each tenant
  6. Simultaneously each payment should have an process tracker entry in individual schema
  7. Verify if the process tracker status for both task is changing to terminal state in DB indicating that producer and consumer are able to pick up the task from different schema and update the status respectively

Test for Drainer

  1. Enable multitenancy by changing [multitenancy] in development.toml
  2. Create multiple tenants by adding [multitenancy.tenants] in development.toml
  3. Start Router and Drainer cargo r --bin drainer
  4. Create a merchant by passing x-tenant-id as <your-tenant> in the request header in localhost:8080
  5. Enable KV for the merchant using below curl
--header 'Content-Type: application/json' \
--header 'api-key: {{admin_api_key}}' \
--data '{
  "kv_enabled": true
}'
  1. Create a payment by passing x-tenant-id as <your-tenant> in the request header in localhost:8080
  2. Once the payment get succeeded, make sure payment_intent and payment_attempt table are updated

Test for Redirection

  1. Enable multitenancy by changing [multitenancy] in development.toml
  2. Create multiple tenants by adding [multitenancy.tenants] in development.toml
  3. Start Router and make a 3DS payment, the redirection url should be correct as per the tenant configuration

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

@jagan-jaya jagan-jaya changed the title Multitenancy: add tenant id in sessionState and populate it from request header. All component should take tenant_id only from sessionState feat(multitenancy): add tenant id in sessionState and populate it from request header. All component should take tenant_id only from sessionState May 13, 2024
@jagan-jaya jagan-jaya marked this pull request as ready for review May 17, 2024 11:46
@jagan-jaya jagan-jaya requested review from a team as code owners May 17, 2024 11:46
@jagan-jaya jagan-jaya self-assigned this May 17, 2024
@jagan-jaya jagan-jaya added the C-feature Category: Feature request or enhancement label May 17, 2024
@jagan-jaya jagan-jaya changed the title feat(multitenancy): add tenant id in sessionState and populate it from request header. All component should take tenant_id only from sessionState feat(multitenancy): add support for multitenancy and handle the same in router, producer, consumer, drainer and analytics May 17, 2024
NishantJoshi00
NishantJoshi00 previously approved these changes May 31, 2024
jarnura
jarnura previously approved these changes May 31, 2024
lsampras
lsampras previously approved these changes May 31, 2024
Copy link
Member

@lsampras lsampras left a comment

Choose a reason for hiding this comment

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

analytics changes look good

@jagan-jaya jagan-jaya dismissed stale reviews from lsampras, jarnura, and NishantJoshi00 via d5d5f84 June 3, 2024 09:51
jarnura
jarnura previously approved these changes Jun 3, 2024
Aprabhat19
Aprabhat19 previously approved these changes Jun 3, 2024
lsampras
lsampras previously approved these changes Jun 3, 2024
@Gnanasundari24 Gnanasundari24 enabled auto-merge June 3, 2024 10:28
@jagan-jaya jagan-jaya dismissed stale reviews from lsampras, Aprabhat19, and jarnura via 3294ed8 June 3, 2024 11:13
@jarnura jarnura disabled auto-merge June 3, 2024 11:22
@jarnura jarnura enabled auto-merge June 3, 2024 11:23
@jarnura jarnura added this pull request to the merge queue Jun 3, 2024
Merged via the queue into main with commit 15d6c3e Jun 3, 2024
10 checks passed
@jarnura jarnura deleted the multitenancy branch June 3, 2024 12:43
pixincreate added a commit that referenced this pull request Jun 4, 2024
…atus_pt

* 'main' of github.com:juspay/hyperswitch:
  chore(version): 2024.06.04.0
  fix: include client_version and client_source in retried payments (#4826)
  refactor(users): Changes for Home and Signout APIs for TOTP Redis flows (#4851)
  feat(users): Create config for TOTP Issuer (#4776)
  feat(multitenancy): add support for multitenancy and handle the same in router, producer, consumer, drainer and analytics (#4630)
  feat(connector): [AUTHORIZEDOTNET] Support payment_method_id in recurring mandate payment (#4841)
  refactor(connector): airwallex convert init payment to preprocessing (#4842)
  feat(router): send `three_ds_requestor_url` in authentication_response for external 3ds flow (#4828)
  feat(consolidated-kafka-events): add consolidated kafka payment events (#4798)
  refactor(connector): [Klarna] Add shipping Address in Klarna Session and Payment Request (#4836)
  fix(connector): make few fields optional in struct NetceteraErrorDetails (#4827)
  chore(cypress): remove logs that expose `globalState` (#4844)
pixincreate added a commit that referenced this pull request Jun 4, 2024
* 'main' of github.com:juspay/hyperswitch:
  feat(cypress): Add service level testing for Payouts (#4744)
  feat(auth): Create and use `SinglePurposeOrLoginTokenAuth` (#4830)
  refactor(connector): [Adyen] handle redirection error response (#4862)
  refactor(api_models): rename Card struct for payouts to avoid overrides in auto generated open API spec (#4861)
  chore(version): 2024.06.04.1
  fix(connector): [Adyen]add required fields for afterpay clearpay (#4858)
  chore(version): 2024.06.04.0
  fix: include client_version and client_source in retried payments (#4826)
  refactor(users): Changes for Home and Signout APIs for TOTP Redis flows (#4851)
  feat(users): Create config for TOTP Issuer (#4776)
  feat(multitenancy): add support for multitenancy and handle the same in router, producer, consumer, drainer and analytics (#4630)
  feat(connector): [AUTHORIZEDOTNET] Support payment_method_id in recurring mandate payment (#4841)
  refactor(connector): airwallex convert init payment to preprocessing (#4842)
  feat(router): send `three_ds_requestor_url` in authentication_response for external 3ds flow (#4828)
  feat(consolidated-kafka-events): add consolidated kafka payment events (#4798)
Comment on lines 917 to +920
pub async fn server_wrap_util<'a, 'b, U, T, Q, F, Fut, E, OErr>(
flow: &'a impl router_env::types::FlowMetric,
state: web::Data<AppState>,
incoming_request_header: &HeaderMap,
Copy link
Member

Choose a reason for hiding this comment

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

We should skip this else the request headers will be logged by tracing

@SanchithHegde SanchithHegde removed the S-waiting-on-review Status: This PR has been implemented and needs to be reviewed label Jun 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-core Area: Core flows C-feature Category: Feature request or enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants