Repository navigation
chore: remove redundant structure for account with definition - #5872
Conversation
|
I've made the following changes to the PR:
These changes improve code maintainability by reducing duplication and adding test coverage for the JSON serialization aspects of the refactored code. |
29eb565 to
4c85ac4
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #5872 +/- ##
==========================================
+ Coverage 76.91% 76.97% +0.05%
==========================================
Files 492 492
Lines 67808 67806 -2
==========================================
+ Hits 52157 52195 +38
+ Misses 12812 12780 -32
+ Partials 2839 2831 -8 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
4c85ac4 to
5a455be
Compare
|
I've addressed the issue raised by @utsabc regarding the handling of non-existent account definitions. The changes include:
This ensures that when an account has a blank account definition name, the code doesn't create a misleading pointer to an empty account definition struct, which could cause issues elsewhere in the codebase. |
|
I've further refactored the code to make it more elegant by extracting a dedicated helper function func (c *ConfigT) getAccountDefinition(accountDefinitionName, accountID, accountField, destinationID, flowType string) *AccountDefinition {
if accountDefinitionName == "" {
return nil
}
if accountDefinition, exists := c.AccountDefinitions[accountDefinitionName]; exists {
return &accountDefinition
}
// Log warning if account definition not found
pkgLogger.Warnn("Account definition not found in configured accountDefinitions for "+flowType+" flow",
logger.NewStringField(accountField, accountID),
logger.NewStringField("accountDefinitionName", accountDefinitionName),
logger.NewStringField("destinationId", destinationID))
return nil
}This change:
The code now handles the case of blank |
|
I've changed the log level from warning ( |
atzoum
left a comment
There was a problem hiding this comment.
Please consider simplifying to the following two methods
// setDestinationAccounts assigns accounts to a destination based on its configuration.
// It handles two types of account associations:
//
// 1. Regular account [rudderAccountId] - Used for normal event delivery flow
// 2. Delete account [rudderDeleteAccountId] - Used for data deletion/regulation flow
//
// For each account type, it:
//
// 1. Checks if the corresponding account ID exists in the destination config
// 2. Verifies the account exists in the accounts map
// 3. Creates a copy of the account which contains its definition as well
// 4. Assigns it to the appropriate field in the destination
//
// Parameters:
// - dest: Pointer to the destination being configured
func (c *ConfigT) setDestinationAccounts(dest *DestinationT) {
// Check and set the regular account if specified in the destination config
if accountID, ok := dest.Config["rudderAccountId"].(string); ok && accountID != "" {
dest.DeliveryAccount = c.populateAccountToDestination(accountID, pkgLogger.Withn(
logger.NewStringField("accountId", accountID),
logger.NewStringField("destinationId", dest.ID),
logger.NewStringField("flowType", "delivery"),
))
}
// Check and set the delete account if specified in the destination config
if deleteAccountID, ok := dest.Config["rudderDeleteAccountId"].(string); ok && deleteAccountID != "" {
dest.DeleteAccount = c.populateAccountToDestination(deleteAccountID, pkgLogger.Withn(
logger.NewStringField("accountId", deleteAccountID),
logger.NewStringField("destinationId", dest.ID),
logger.NewStringField("flowType", "regulation"),
))
}
}
// populateAccountToDestination populates an account to a destination field based on the account ID.
// It creates an copy of the Account object by combining account details with its definition.
//
// Parameters:
// - accountID: The ID of the account to populate
// - log: The logger to use for logging errors
//
// Returns:
// - *Account: The populated account object or nil if the account doesn't exist
func (c *ConfigT) populateAccountToDestination(accountID string, log logger.Logger) *Account {
if account, ok := c.Accounts[accountID]; ok {
if accountDefinition, ok := c.AccountDefinitions[account.AccountDefinitionName]; ok {
account.AccountDefinition = &accountDefinition
} else {
log.Errorn("Account definition not found in configured definitions",
logger.NewStringField("definition", account.AccountDefinitionName),
)
}
return &account
}
pkgLogger.Errorn("Account not found in configured accounts")
return nil
}There was a problem hiding this comment.
I don't understand why we need this, what it protects us from
There was a problem hiding this comment.
We are already using accounts for oauth destinations. So for those existing accounts we are not going to get any accountDefinitionName. Returning nil will help us segregating account with accountDefinition and account without accountDefinition.
There was a problem hiding this comment.
I have comment elsewhere as well, maybe we shouldn't be calling the method if account definition is empty
There was a problem hiding this comment.
We have removed the logic of checking empty string of accountDefinitionName to the caller.
f20aeb6 to
89c39da
Compare
89c39da to
417e8e6
Compare
| if accountDefinitionName == "" { | ||
| return nil | ||
| } |
There was a problem hiding this comment.
It would be preferrable to avoid calling this method if accountDefinitionName is empty, since the caller has a better context with respect what an empty accountDefinitionName means. The logic behind the empty check here is not that straightforward
| if accountDefinitionName == "" { | |
| return nil | |
| } |
There was a problem hiding this comment.
Moved this logic to the caller.
🤖 I have created a release *beep* *boop* --- ## [1.50.0-rc.1](v1.49.0...v1.50.0-rc.1) (2025-05-26) ### Features * implement aws v2 implementation ([#5852](#5852)) ([18fd4fb](18fd4fb)) ### Bug Fixes * do not panic for invalid router payload ([#5880](#5880)) ([f4a0e7c](f4a0e7c)) * server panicking with invalid byte sequence for encoding utf8 0x00 ([#5882](#5882)) ([4c1a0de](4c1a0de)) * skip source_id when fetching warehouse schema from database ([#5886](#5886)) ([092ee2a](092ee2a)) * warehouse pending tables to skip ([#5867](#5867)) ([864fd49](864fd49)) * warehouse transformations ([#5875](#5875)) ([715ccfa](715ccfa)) ### Miscellaneous * **deps:** bump the go-deps group across 1 directory with 25 updates ([#5890](#5890)) ([3c4ddd8](3c4ddd8)) * **jobsdb:** migrate incomplete datasets in pairs excluding completed ones ([#5876](#5876)) ([9d8b573](9d8b573)) * **jobsdb:** remove support for jobDoneMigrateThres ([#5873](#5873)) ([4745d2b](4745d2b)) * make reporting client params configurable ([#5891](#5891)) ([39f7e75](39f7e75)) * move house keeping action to commit sha ([#5885](#5885)) ([d379e82](d379e82)) * refactor config change dtype for config to json.RawMessage ([#5874](#5874)) ([940adb0](940adb0)) * refactor webhook pkg to make it reusable in other repos ([#5594](#5594)) ([1ee57bc](1ee57bc)) * remove redundant structure for account with definition ([#5872](#5872)) ([89bc62b](89bc62b)) * remove support for transformer-based kafka batching ([#5870](#5870)) ([60a571c](60a571c)) * revert support new consent resolution strategy values ([#5855](#5855)) ([c7e3b37](c7e3b37)) * revert use account to decide oauth type of a destination ([#5861](#5861)) ([6232755](6232755)) * **router:** additional observability metrics ([#5887](#5887)) ([da3ba3c](da3ba3c)) * sync release v1.49.0 to main branch ([#5851](#5851)) ([78cc5a9](78cc5a9)) * use jsonrs from rudder-go-kit ([#5869](#5869)) ([39064af](39064af)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
🤖 I have created a release *beep* *boop* --- ## [1.50.0-rc.2](v1.49.0...v1.50.0-rc.2) (2025-05-26) ### Features * implement aws v2 implementation ([#5852](#5852)) ([18fd4fb](18fd4fb)) ### Bug Fixes * do not panic for invalid router payload ([#5880](#5880)) ([f4a0e7c](f4a0e7c)) * error gathering metrics, metric was collected before with the same name and label values ([#5900](#5900)) ([422f45b](422f45b)) * handle missing eventUpload config gracefully ([#5898](#5898)) ([05a926d](05a926d)) * server panicking with invalid byte sequence for encoding utf8 0x00 ([#5882](#5882)) ([4c1a0de](4c1a0de)) * skip source_id when fetching warehouse schema from database ([#5886](#5886)) ([092ee2a](092ee2a)) * warehouse pending tables to skip ([#5867](#5867)) ([864fd49](864fd49)) * warehouse transformations ([#5875](#5875)) ([715ccfa](715ccfa)) ### Miscellaneous * **deps:** bump the go-deps group across 1 directory with 25 updates ([#5890](#5890)) ([3c4ddd8](3c4ddd8)) * **jobsdb:** migrate incomplete datasets in pairs excluding completed ones ([#5876](#5876)) ([9d8b573](9d8b573)) * **jobsdb:** remove support for jobDoneMigrateThres ([#5873](#5873)) ([4745d2b](4745d2b)) * make reporting client params configurable ([#5891](#5891)) ([39f7e75](39f7e75)) * move house keeping action to commit sha ([#5885](#5885)) ([d379e82](d379e82)) * refactor config change dtype for config to json.RawMessage ([#5874](#5874)) ([940adb0](940adb0)) * refactor webhook pkg to make it reusable in other repos ([#5594](#5594)) ([1ee57bc](1ee57bc)) * remove redundant structure for account with definition ([#5872](#5872)) ([89bc62b](89bc62b)) * remove support for transformer-based kafka batching ([#5870](#5870)) ([60a571c](60a571c)) * revert support new consent resolution strategy values ([#5855](#5855)) ([c7e3b37](c7e3b37)) * revert use account to decide oauth type of a destination ([#5861](#5861)) ([6232755](6232755)) * **router:** additional observability metrics ([#5887](#5887)) ([da3ba3c](da3ba3c)) * sync release v1.49.0 to main branch ([#5851](#5851)) ([78cc5a9](78cc5a9)) * use jsonrs from rudder-go-kit ([#5869](#5869)) ([39064af](39064af)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
🤖 I have created a release *beep* *boop* --- ## [1.50.0](v1.49.0...v1.50.0) (2025-05-26) ### Features * implement aws v2 implementation ([#5852](#5852)) ([18fd4fb](18fd4fb)) ### Bug Fixes * do not panic for invalid router payload ([#5880](#5880)) ([f4a0e7c](f4a0e7c)) * error gathering metrics, metric was collected before with the same name and label values ([#5900](#5900)) ([422f45b](422f45b)) * handle missing eventUpload config gracefully ([#5898](#5898)) ([05a926d](05a926d)) * server panicking with invalid byte sequence for encoding utf8 0x00 ([#5882](#5882)) ([4c1a0de](4c1a0de)) * skip source_id when fetching warehouse schema from database ([#5886](#5886)) ([092ee2a](092ee2a)) * warehouse pending tables to skip ([#5867](#5867)) ([864fd49](864fd49)) * warehouse transformations ([#5875](#5875)) ([715ccfa](715ccfa)) ### Miscellaneous * **deps:** bump the go-deps group across 1 directory with 25 updates ([#5890](#5890)) ([3c4ddd8](3c4ddd8)) * **jobsdb:** migrate incomplete datasets in pairs excluding completed ones ([#5876](#5876)) ([9d8b573](9d8b573)) * **jobsdb:** remove support for jobDoneMigrateThres ([#5873](#5873)) ([4745d2b](4745d2b)) * make reporting client params configurable ([#5891](#5891)) ([39f7e75](39f7e75)) * move house keeping action to commit sha ([#5885](#5885)) ([d379e82](d379e82)) * refactor config change dtype for config to json.RawMessage ([#5874](#5874)) ([940adb0](940adb0)) * refactor webhook pkg to make it reusable in other repos ([#5594](#5594)) ([1ee57bc](1ee57bc)) * remove redundant structure for account with definition ([#5872](#5872)) ([89bc62b](89bc62b)) * remove support for transformer-based kafka batching ([#5870](#5870)) ([60a571c](60a571c)) * revert support new consent resolution strategy values ([#5855](#5855)) ([c7e3b37](c7e3b37)) * revert use account to decide oauth type of a destination ([#5861](#5861)) ([6232755](6232755)) * **router:** additional observability metrics ([#5887](#5887)) ([da3ba3c](da3ba3c)) * sync release v1.49.0 to main branch ([#5851](#5851)) ([78cc5a9](78cc5a9)) * use jsonrs from rudder-go-kit ([#5869](#5869)) ([39064af](39064af)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
Description
We are removing redundant structure
accountWithDefinition. This name is misleading. It is possible AccountDefinition can be undefined in account. So made it optional in account.Copilot Generated
This pull request refactors the account association logic in the backend configuration to improve code reuse and maintainability. It introduces a new helper function,
populateAccountToDestination, and removes the redundantAccountWithDefinitionstruct. Additionally, it updates the test suite to align with these changes and includes a new test for JSON serialization of destination accounts.Refactoring and Code Reuse:
populateAccountToDestinationhelper function to centralize the logic for populating account details into destinations, improving code reuse. (backend-config/account_association.go, backend-config/account_association.goR24-R58)setDestinationAccountsto use the new helper function, simplifying the logic for setting both delivery and delete accounts. (backend-config/account_association.go, backend-config/account_association.goL40-R80)Structural Changes:
AccountWithDefinitionstruct with the existingAccountstruct, adding a pointer toAccountDefinitionfor consistency and simplification. (backend-config/types.go, [1] [2] [3]Test Updates:
account_association_test.goto reflect the changes in struct field names (e.g.,IdtoID) and the removal ofAccountWithDefinition. (backend-config/account_association_test.go, [1] [2] [3] [4]Accountstruct. (backend-config/account_association_test.go, backend-config/account_association_test.goL241-R295)Dependency Addition:
jsonrspackage in the test file to support JSON serialization and deserialization in the new test case. (backend-config/account_association_test.go, backend-config/account_association_test.goR6)Linear Ticket
https://linear.app/rudderstack/issue/INT-3685/refactor-logic-for-merging-account-information-with-destination
Security