-
Notifications
You must be signed in to change notification settings - Fork 48
feat: add account_advisory backfill job #2285
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| package caches | ||
|
|
||
| import ( | ||
| "app/aggregator" | ||
| "app/base/database" | ||
| "app/base/utils" | ||
| "app/tasks" | ||
| "sync" | ||
|
|
||
| "gorm.io/gorm" | ||
| ) | ||
|
|
||
| func BackfillAccountAdvisory() { | ||
| var wg sync.WaitGroup | ||
| backfillAccountAdvisoryPerAccounts(&wg) | ||
| wg.Wait() | ||
| } | ||
|
|
||
| func backfillAccountAdvisoryPerAccounts(wg *sync.WaitGroup) { | ||
| var rhAccountIDs []int | ||
| err := tasks.WithReadReplicaTx(func(tx *gorm.DB) error { | ||
| return tx.Table("rh_account"). | ||
| Order("hash_partition_id(id, 128), id"). | ||
| Pluck("id", &rhAccountIDs).Error | ||
| }) | ||
| if err != nil { | ||
| utils.LogError("err", err, "unable to load rh_account IDs for account_advisory backfill") | ||
| return | ||
| } | ||
|
|
||
| utils.LogInfo("accounts", len(rhAccountIDs), "starting account_advisory backfill") | ||
|
|
||
| guard := make(chan struct{}, 4) | ||
|
MichaelMraka marked this conversation as resolved.
|
||
|
|
||
| for i, rhAccountID := range rhAccountIDs { | ||
| guard <- struct{}{} | ||
| wg.Add(1) | ||
| go func(i, rhAccountID int) { | ||
| defer func() { | ||
| <-guard | ||
| wg.Done() | ||
| }() | ||
|
|
||
| err := tasks.WithTx(func(tx *gorm.DB) error { | ||
| utils.LogInfo("i", i, "rh_account_id", rhAccountID, "backfilling account_advisory") | ||
| return tx.Exec("SELECT backfill_account_advisory(?)", rhAccountID).Error | ||
| }) | ||
|
Comment on lines
+38
to
+47
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (performance): Per-account logging at info level in a tight loop may cause excessive log volume. Per-account info-level logs before/after backfill and on drift check errors will scale with the number of accounts and can significantly increase log volume and overhead. Please consider lowering verbosity for per-account messages (e.g., debug or aggregated progress logs), while keeping actual error logs at info/error. Suggested implementation: err := tasks.WithTx(func(tx *gorm.DB) error {
utils.LogDebug("i", i, "rh_account_id", rhAccountID, "backfilling account_advisory")
return tx.Exec("SELECT backfill_account_advisory(?)", rhAccountID).Error
})To fully implement the logging-verbosity suggestion, you should also:
|
||
| if err != nil { | ||
| utils.LogError("err", err, "rh_account_id", rhAccountID, "failed to backfill account_advisory") | ||
| return | ||
| } | ||
| utils.LogInfo("i", i, "rh_account_id", rhAccountID, "backfilled account_advisory") | ||
|
|
||
| var advisoryIDs []int64 | ||
| if err := database.DB.Table("account_advisory"). | ||
| Where("rh_account_id = ?", rhAccountID). | ||
| Distinct("advisory_id"). | ||
| Pluck("advisory_id", &advisoryIDs).Error; err != nil { | ||
| utils.LogError("err", err, "rh_account_id", rhAccountID, "failed to load advisory IDs for drift check") | ||
| return | ||
| } | ||
| aggregator.CheckAdvisoryDrift(rhAccountID, advisoryIDs) | ||
| }(i, rhAccountID) | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.