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
@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
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 S-waiting-on-review Status: This PR has been implemented and needs to be reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants