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

Open
wants to merge 35 commits into
base: main
Choose a base branch
from

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

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
@jagan-jaya jagan-jaya added A-core Area: Core flows S-waiting-on-review Status: This PR has been implemented and needs to be reviewed labels May 23, 2024
crates/drainer/src/connection.rs Outdated Show resolved Hide resolved
crates/drainer/src/handler.rs Outdated Show resolved Hide resolved
crates/drainer/src/settings.rs Outdated Show resolved Hide resolved
crates/router/src/configs/defaults.rs Outdated Show resolved Hide resolved
crates/router/src/configs/settings.rs Outdated Show resolved Hide resolved
crates/router/src/routes/app.rs Outdated Show resolved Hide resolved
crates/redis_interface/src/commands.rs Outdated Show resolved Hide resolved
crates/router/src/routes/app.rs Outdated Show resolved Hide resolved
crates/storage_impl/src/redis/cache.rs Outdated Show resolved Hide resolved
crates/router/src/services/api.rs Outdated Show resolved Hide resolved
@jarnura jarnura requested a review from lsampras May 27, 2024 10:27
crates/router/src/db/api_keys.rs Show resolved Hide resolved
crates/router/src/routes/app.rs Outdated Show resolved Hide resolved
crates/router/src/routes/app.rs Outdated Show resolved Hide resolved
crates/router/src/routes/app.rs Outdated Show resolved Hide resolved
crates/router/src/services/api.rs Outdated Show resolved Hide resolved
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

3 participants