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(db): Add TenantID field to KafkaEvent struct #4598

Merged
merged 4 commits into from May 15, 2024

Conversation

subhajit20
Copy link
Contributor

@subhajit20 subhajit20 commented May 9, 2024

Type of Change

#4595

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

Description

  • Add TenantID to the KafkaEvent struct and add the extra param to the KafkaEvent constructor
  • Made changes to the required placed

Additional Changes

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

Motivation and Context

  • Supporting multi-tenancy

How did you test it?

image

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

@subhajit20 subhajit20 requested a review from a team as a code owner May 9, 2024 04:56
@subhajit20 subhajit20 changed the title [Feature]: Add TenantID field to KafkaEvent struct refactor(db): Add TenantID field to KafkaEvent struct May 9, 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.

Also can you share screenshots of the generated events from the kafka-ui ?

)))
self.log_event(&KafkaEvent::old(
&KafkaPaymentAttempt::from_storage(&negative_event),
TenantID("default".to_string()),
Copy link
Member

Choose a reason for hiding this comment

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

can you use the tenant_id stored in the kafkastore instead?

Copy link
Contributor Author

@subhajit20 subhajit20 May 9, 2024

Choose a reason for hiding this comment

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

Yes I have used that TenantID here only ... I have imported that at the top in kafka.rs file

Copy link
Member

Choose a reason for hiding this comment

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

I mean that can you add a parameter in the log_payment_attempt function to accept a tenant_id and use that instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes done that!

@@ -30,6 +30,7 @@ use crate::types::storage::Dispute;

// Using message queue result here to avoid confusion with Kafka result provided by library
pub type MQResult<T> = CustomResult<T, KafkaError>;
use crate::db::kafka_store::TenantID;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here is the line @lsampras

@subhajit20 subhajit20 requested a review from lsampras May 9, 2024 18:11
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.

Some minor refactors needed,

Also can you run the formatting & clippy checks locally there might be some linting problems here.

Would also prefer if you are able to run it locally and share screenshots for the same

@@ -1109,7 +1109,7 @@ impl PaymentAttemptInterface for KafkaStore {

if let Err(er) = self
.kafka_producer
.log_payment_attempt(&attempt, None)
.log_payment_attempt(&attempt, None, TenantID("default".to_string()))
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
.log_payment_attempt(&attempt, None, TenantID("default".to_string()))
.log_payment_attempt(&attempt, None, self.tenant_id)

Can we use the tenant_id stored in KafkaStore struct as such

Comment on lines 295 to 298
self.log_event(&KafkaEvent::old(
&KafkaPaymentAttempt::from_storage(delete_old_attempt),
TenantID("default".to_string()),
))
Copy link
Member

Choose a reason for hiding this comment

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

Can we follow the same pattern as we did for log_payment_attempt function for every other usage as well?

there shouldn't be any new initializations of TenantID in this PR, since it is already defined in KafkaStore which is what we'll be using instead

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I this commit solves this issue,
let me know if further changes needed. @lsampras

@subhajit20 subhajit20 requested a review from lsampras May 14, 2024 06:47
@lsampras lsampras linked an issue May 14, 2024 that may be closed by this pull request
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.

@subhajit20 the code changes look good, Will you be able to test this out locally & share the screenshots of updated Kafka events?

@lsampras
Copy link
Member

The kafka events seem to have tenant-ID present

image

@lsampras lsampras added A-framework Area: Framework C-feature Category: Feature request or enhancement A-Analytics labels May 15, 2024
@Gnanasundari24 Gnanasundari24 added this pull request to the merge queue May 15, 2024
Merged via the queue into juspay:main with commit 24214bc May 15, 2024
14 of 15 checks passed
@lsampras
Copy link
Member

Thanks for the contribution @subhajit20.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Analytics A-framework Area: Framework C-feature Category: Feature request or enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature] Add tenant-ID as a field to all KafkaStore events
4 participants