-
Notifications
You must be signed in to change notification settings - Fork 322
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
chore: backup support for new multitenant system #2549
Conversation
Codecov ReportBase: 43.74% // Head: 43.65% // Decreases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## master #2549 +/- ##
==========================================
- Coverage 43.74% 43.65% -0.09%
==========================================
Files 187 191 +4
Lines 39993 40486 +493
==========================================
+ Hits 17494 17675 +181
- Misses 21403 21704 +301
- Partials 1096 1107 +11
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
d108317
to
c77cdd3
Compare
c77cdd3
to
2f896da
Compare
e2bf0a7
to
ce530cf
Compare
@BonapartePC #2542 introduced a major refactoring on most backup functions. Furthermore, all backup-related functions are now moved in a separate file, backup.go. @saurav-malani may provide you with some more information regarding the scope of this aforementioned refactoring. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My only concern is test coverage.
Such large refactorings should increase overal code coverage instead of decreasing it.
fcd29ea
to
ea720ae
Compare
The coverage is a little better now. Most of the impacted files are the ones where the fileuploader is just passed but there are no tests that result in decreasing coverage a bit. |
@@ -68,7 +70,6 @@ func (jd *HandleT) backupDSLoop(ctx context.Context) { | |||
opID := jd.JournalMarkStart(backupDSOperation, opPayload) | |||
err = jd.backupDS(ctx, backupDSRange) | |||
if err != nil { | |||
stats.Default.NewTaggedStat("backup_ds_failed", stats.CountType, stats.Tags{"customVal": jd.tablePrefix, "provider": config.GetString("JOBS_BACKUP_STORAGE_PROVIDER", "S3")}).Increment() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this not change the semantics of the backup_ds_failed metric which would count all failures (including issues while calling cleanStatusTable, which gets skipped if you remove this). I see this has been moved to the uploadDumps function with a different set of labels. Should we not keep this as is and rename the stat in uploadDumps to somethinglike upload_dump_failed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to remove this here because at the point where we are making this stat we can't determine the provider
tag. This will be different for each workspace which was previously taken from the env.
jobsdb/backup.go
Outdated
g, _ := errgroup.WithContext(ctx) | ||
g.SetLimit(config.GetInt("JobsDB.JobsBackupUploadWorkers", 100)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question: Should this not be
g, ctx := errgroup.WithContext(ctx)
and we should be passing the derived ctx is passed to all the goroutines
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. added
jobsdb/backup.go
Outdated
dumps, err := jd.createTableDumps(getFailedOnlyBackupQueryFn(backupDSRange), getFileName, totalCount) | ||
if err != nil { | ||
return fmt.Errorf("error while creating table dump: %w", err) | ||
} | ||
defer func() { _ = os.Remove(path) }() | ||
|
||
err = jd.uploadTableDump(ctx, path) | ||
defer func() { | ||
for _, filePath := range dumps { | ||
os.Remove(filePath) | ||
} | ||
}() | ||
err = jd.uploadDumps(ctx, dumps) | ||
if err != nil { | ||
jd.logger.Errorf("[JobsDB] :: Failed to upload table %v", tableName) | ||
return err | ||
return fmt.Errorf("error while uploading dumps for table: %s: %w", tableName, err) | ||
} | ||
|
||
stats.Default.NewTaggedStat("total_TableDump_TimeStat", stats.TimerType, stats.Tags{"customVal": jd.tablePrefix}).Since(start) | ||
return nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor: This code is almost identical to the code in lines 241-256, 294-311 factorize it maybe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We decided to leave it this way so it is clearly shown as different steps being taken
jobsdb/backup.go
Outdated
err = jd.uploadTableDump(ctx, path) | ||
defer func() { | ||
for _, filePath := range dumps { | ||
os.Remove(filePath) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_ = os.Remove(filePath)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made the change
func (p *provider) GetFileManager(workspaceID string) (filemanager.FileManager, error) { | ||
<-p.init | ||
settings, ok := p.storageSettings[workspaceID] | ||
if !ok { | ||
return nil, fmt.Errorf("no storage settings found for workspace: %s", workspaceID) | ||
} | ||
return filemanager.DefaultFileManagerFactory.New(&filemanager.SettingsT{ | ||
Provider: settings.Bucket.Type, | ||
Config: settings.Bucket.Config, | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add a test scenario for this function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added
func NewStaticProvider(storageSettings map[string]StorageSettings) Provider { | ||
s := &provider{ | ||
init: make(chan struct{}), | ||
storageSettings: storageSettings, | ||
} | ||
close(s.init) | ||
return s |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add a test scenario for this function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
} | ||
|
||
p.onceInit.Do(func() { | ||
close(p.init) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why this appears to be not covered with tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a test for that
func (*defaultProvider) GetFileManager(_ string) (filemanager.FileManager, error) { | ||
defaultConfig := getDefaultBucket(context.Background(), config.GetString("JOBS_BACKUP_STORAGE_PROVIDER", "S3")) | ||
return filemanager.DefaultFileManagerFactory.New(&filemanager.SettingsT{ | ||
Provider: defaultConfig.Type, | ||
Config: defaultConfig.Config, | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add a test scenario for this function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
d9495e7
to
774836b
Compare
@@ -0,0 +1,62 @@ | |||
package fileuploader |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is the rational behind creating this services/fileuploader/gzwriter
? I mean it seems to be doing things very specific to our jobsDB backup (atleast as of now). Creating a gzFileHandler which has a map of path & gzipwriter. Where else are we going to use it? If no where, then won’t it be better to move it to jobsdb backup?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea is it can be used anywhere not just jobsdb so I kept it in services folder
Description
Supporting backup upload for the multitenant system. The following are the changes:
Notion Ticket
https://www.notion.so/rudderstacks/Allow-Customers-to-use-self-storage-26f45f75e38b4ef6bd872bea6187aa06
https://www.notion.so/rudderstacks/Divide-customers-events-in-jobs-table-and-upload-them-in-respective-storages-04dbf3dbd7bd435786e6a3808bed73ed
Security