Skip to content

Commit 44f8d67

Browse files
committed
refactor: remove tStart variable when it is not needed
1 parent 2c0fa69 commit 44f8d67

11 files changed

Lines changed: 23 additions & 46 deletions

File tree

evaluator/evaluate.go

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,7 @@ func confugureEvaluator() {
135135
}
136136

137137
func Evaluate(ctx context.Context, event *mqueue.PlatformEvent, inventoryID, evaluationType string) error {
138-
tStart := time.Now()
139-
defer utils.ObserveSecondsSince(tStart, evaluationDuration.WithLabelValues(evaluationType))
138+
defer utils.ObserveSecondsSince(time.Now(), evaluationDuration.WithLabelValues(evaluationType))
140139

141140
utils.LogInfo("inventoryID", inventoryID, "Evaluating system")
142141
if enableBypass {
@@ -282,8 +281,7 @@ func tryGetYumUpdates(system *models.SystemPlatformV2) (*vmaas.UpdatesV3Response
282281

283282
func evaluateWithVmaas(updatesData *vmaas.UpdatesV3Response,
284283
system *models.SystemPlatformV2, event *mqueue.PlatformEvent) (*vmaas.UpdatesV3Response, error) {
285-
tStart := time.Now()
286-
defer utils.ObserveSecondsSince(tStart, evaluationPartDuration.WithLabelValues("evaluate-with-vmaas-full"))
284+
defer utils.ObserveSecondsSince(time.Now(), evaluationPartDuration.WithLabelValues("evaluate-with-vmaas-full"))
287285

288286
err := evaluateAndStore(system, updatesData, event)
289287
if err != nil {
@@ -293,8 +291,7 @@ func evaluateWithVmaas(updatesData *vmaas.UpdatesV3Response,
293291
}
294292

295293
func getUpdatesData(ctx context.Context, system *models.SystemPlatformV2) (*vmaas.UpdatesV3Response, error) {
296-
tStart := time.Now()
297-
defer utils.ObserveSecondsSince(tStart, evaluationPartDuration.WithLabelValues("get-updates-data"))
294+
defer utils.ObserveSecondsSince(time.Now(), evaluationPartDuration.WithLabelValues("get-updates-data"))
298295

299296
var yumUpdates *vmaas.UpdatesV3Response
300297
var yumErr error
@@ -335,8 +332,7 @@ func getUpdatesData(ctx context.Context, system *models.SystemPlatformV2) (*vmaa
335332
}
336333

337334
func getVmaasUpdates(ctx context.Context, system *models.SystemPlatformV2) (*vmaas.UpdatesV3Response, error) {
338-
tStart := time.Now()
339-
defer utils.ObserveSecondsSince(tStart, evaluationPartDuration.WithLabelValues("vmaas-updates-prepare"))
335+
defer utils.ObserveSecondsSince(time.Now(), evaluationPartDuration.WithLabelValues("vmaas-updates-prepare"))
340336

341337
var vmaasDataCopy vmaas.UpdatesV3Response
342338
// first check if we have data in cache
@@ -448,8 +444,7 @@ func tryGetSystem(accountID int, inventoryID string,
448444
}
449445

450446
func commitWithObserve(tx *gorm.DB) error {
451-
tStart := time.Now()
452-
defer utils.ObserveSecondsSince(tStart, evaluationPartDuration.WithLabelValues("commit-to-db"))
447+
defer utils.ObserveSecondsSince(time.Now(), evaluationPartDuration.WithLabelValues("commit-to-db"))
453448

454449
err := tx.Commit().Error
455450
if err != nil {
@@ -528,8 +523,7 @@ func analyzeRepos(system *models.SystemPlatformV2) (thirdParty bool, err error)
528523
return false, nil
529524
}
530525

531-
tStart := time.Now()
532-
defer utils.ObserveSecondsSince(tStart, evaluationPartDuration.WithLabelValues("repo-analysis"))
526+
defer utils.ObserveSecondsSince(time.Now(), evaluationPartDuration.WithLabelValues("repo-analysis"))
533527

534528
// if system has associated at least one third party repo
535529
// it's marked as third party system
@@ -563,8 +557,7 @@ func incrementAdvisoryTypeCounts(advisory models.AdvisoryMetadata, enhCount, bug
563557
// nolint: funlen
564558
func updateSystemPlatform(tx *gorm.DB, system *models.SystemPlatformV2,
565559
advisories SystemAdvisoryMap, installed, installable, applicable int) error {
566-
tStart := time.Now()
567-
defer utils.ObserveSecondsSince(tStart, evaluationPartDuration.WithLabelValues("system-update"))
560+
defer utils.ObserveSecondsSince(time.Now(), evaluationPartDuration.WithLabelValues("system-update"))
568561
if system.Inventory.LastUpload != nil {
569562
defer utils.ObserveSecondsSince(*system.Inventory.LastUpload, uploadEvaluationDelay)
570563
}
@@ -652,8 +645,7 @@ func updateSystemPlatform(tx *gorm.DB, system *models.SystemPlatformV2,
652645
}
653646

654647
func callVMaas(ctx context.Context, request *vmaas.UpdatesV3Request) (*vmaas.UpdatesV3Response, error) {
655-
tStart := time.Now()
656-
defer utils.ObserveSecondsSince(tStart, evaluationPartDuration.WithLabelValues("vmaas-updates-call"))
648+
defer utils.ObserveSecondsSince(time.Now(), evaluationPartDuration.WithLabelValues("vmaas-updates-call"))
657649

658650
vmaasCallFunc := func() (interface{}, *http.Response, error) {
659651
utils.LogTrace("request", *request, "vmaas /updates request")
@@ -677,8 +669,7 @@ func callVMaas(ctx context.Context, request *vmaas.UpdatesV3Request) (*vmaas.Upd
677669
}
678670

679671
func loadSystemData(accountID int, inventoryID string) (*models.SystemPlatformV2, error) {
680-
tStart := time.Now()
681-
defer utils.ObserveSecondsSince(tStart, evaluationPartDuration.WithLabelValues("data-loading"))
672+
defer utils.ObserveSecondsSince(time.Now(), evaluationPartDuration.WithLabelValues("data-loading"))
682673

683674
var system models.SystemPlatformV2
684675
err := database.DB.Table("system_inventory si").
@@ -704,8 +695,7 @@ func validSystem(accountID int, systemID int64) bool {
704695
}
705696

706697
func parseVmaasJSON(inv *models.SystemInventory) (vmaas.UpdatesV3Request, error) {
707-
tStart := time.Now()
708-
defer utils.ObserveSecondsSince(tStart, evaluationPartDuration.WithLabelValues("parse-vmaas-json"))
698+
defer utils.ObserveSecondsSince(time.Now(), evaluationPartDuration.WithLabelValues("parse-vmaas-json"))
709699
return utils.ParseVmaasJSON(inv)
710700
}
711701

evaluator/evaluate_advisories.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ func lazySaveAndLoadAdvisories(system *models.SystemPlatformV2, vmaasData *vmaas
4141
return nil, nil
4242
}
4343

44-
tStart := time.Now()
45-
defer utils.ObserveSecondsSince(tStart, evaluationPartDuration.WithLabelValues("advisories-lazy-save-and-load"))
44+
defer utils.ObserveSecondsSince(time.Now(), evaluationPartDuration.WithLabelValues("advisories-lazy-save-and-load"))
4645

4746
err := lazySaveAdvisories(vmaasData, system.GetInventoryID())
4847
if err != nil {

evaluator/evaluate_packages.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ func lazySaveAndLoadPackages(system *models.SystemPlatformV2, vmaasData *vmaas.U
2222
return nil, 0, 0, 0, nil
2323
}
2424

25-
tStart := time.Now()
26-
defer utils.ObserveSecondsSince(tStart, evaluationPartDuration.WithLabelValues("packages-lazy-save-and-load"))
25+
defer utils.ObserveSecondsSince(time.Now(), evaluationPartDuration.WithLabelValues("packages-lazy-save-and-load"))
2726

2827
err := lazySavePackages(vmaasData)
2928
if err != nil {

evaluator/inventory_views.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ func publishInventoryViewsEvent(tx *gorm.DB, systems []models.SystemPlatformV2,
2929
return nil
3030
}
3131

32-
tStart := time.Now()
33-
defer utils.ObserveSecondsSince(tStart, evaluationPartDuration.WithLabelValues("inventory-views-publish"))
32+
defer utils.ObserveSecondsSince(time.Now(), evaluationPartDuration.WithLabelValues("inventory-views-publish"))
3433

3534
orgID := origin.GetOrgID()
3635
var requestID string

evaluator/notifications.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,7 @@ func publishNewAdvisoriesNotification(tx *gorm.DB, system *models.SystemPlatform
7474
return nil
7575
}
7676

77-
tStart := time.Now()
78-
defer utils.ObserveSecondsSince(tStart, evaluationPartDuration.WithLabelValues("advisory-notification-publish"))
77+
defer utils.ObserveSecondsSince(time.Now(), evaluationPartDuration.WithLabelValues("advisory-notification-publish"))
7978

8079
advisories, err := getUnnotifiedAdvisories(tx, system.Inventory.RhAccountID, newAdvisories)
8180
if err != nil {

evaluator/remediations.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@ func getReportedPackageUpdates(vmaasData *vmaas.UpdatesV3Response) map[string]bo
7171
}
7272

7373
func publishRemediationsState(system *models.SystemPlatformV2, response *vmaas.UpdatesV3Response) error {
74-
tStart := time.Now()
75-
defer utils.ObserveSecondsSince(tStart, evaluationPartDuration.WithLabelValues("remediations-publish"))
74+
defer utils.ObserveSecondsSince(time.Now(), evaluationPartDuration.WithLabelValues("remediations-publish"))
7675

7776
if remediationsPublisher == nil {
7877
return nil

listener/event_buffers.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ func (b *eventBuffer) bufferEvalEvents(
3535
rhAccountID int,
3636
ptEvent *mqueue.PayloadTrackerEvent,
3737
) {
38-
tStart := time.Now()
39-
defer utils.ObserveSecondsSince(tStart, messagePartDuration.WithLabelValues("buffer-eval-events"))
38+
defer utils.ObserveSecondsSince(time.Now(), messagePartDuration.WithLabelValues("buffer-eval-events"))
4039

4140
b.lock.Lock()
4241
evalData := mqueue.EvalData{

listener/events.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ func EventsMessageHandler(m mqueue.KafkaMessage) error {
6363
}
6464

6565
func HandleDelete(event mqueue.PlatformEvent) error {
66-
tStart := time.Now()
67-
defer utils.ObserveSecondsSince(tStart, messageHandlingDuration.WithLabelValues(EventDelete))
66+
defer utils.ObserveSecondsSince(time.Now(), messageHandlingDuration.WithLabelValues(EventDelete))
6867
// TODO: Do we need locking here ?
6968
err := database.OnConflictUpdate(database.DB, "inventory_id", "when_deleted").
7069
Create(models.DeletedSystem{

listener/templates.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@ func TemplatesMessageHandler(m mqueue.KafkaMessage) error {
5555
}
5656

5757
func TemplateDelete(template mqueue.TemplateResponse) error {
58-
tStart := time.Now()
59-
defer utils.ObserveSecondsSince(tStart, templateMsgHandlingDuration.WithLabelValues(TemplateEventDelete))
58+
defer utils.ObserveSecondsSince(time.Now(), templateMsgHandlingDuration.WithLabelValues(TemplateEventDelete))
6059

6160
// check account
6261
accountID, err := middlewares.GetOrCreateAccount(template.OrgID)

listener/upload.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,7 @@ func checkPackagesEpoch(packages []string) error {
255255
}
256256

257257
func sendPayloadStatus(w mqueue.Writer, event mqueue.PayloadTrackerEvent, status string, statusMsg string) {
258-
tStart := time.Now()
259-
defer utils.ObserveSecondsSince(tStart, messagePartDuration.WithLabelValues("payload-tracker-status"))
258+
defer utils.ObserveSecondsSince(time.Now(), messagePartDuration.WithLabelValues("payload-tracker-status"))
260259
if status != "" {
261260
event.Status = status
262261
}
@@ -311,8 +310,7 @@ func hostTemplate(tx *gorm.DB, accountID int, host *Host) *int64 {
311310
// Stores or updates base system profile, returning inventory + patch aggregate.
312311
func updateSystemPlatform(tx *gorm.DB, accountID int, host *Host,
313312
yumUpdates *YumUpdates, updatesReq *vmaas.UpdatesV3Request) (*models.SystemPlatformV2, error) {
314-
tStart := time.Now()
315-
defer utils.ObserveSecondsSince(tStart, messagePartDuration.WithLabelValues("update-system-platform"))
313+
defer utils.ObserveSecondsSince(time.Now(), messagePartDuration.WithLabelValues("update-system-platform"))
316314
// NOTE: if we add a map to vmaas.UpdatesV3Request in the future, we need to use
317315
// `encoder.Encode(updatesReq, encoder.SortMapKeys)` to compute the hash correctly
318316
updatesReqJSON, err := sonic.Marshal(updatesReq)
@@ -547,8 +545,7 @@ func fixEpelRepos(sys *inventory.SystemProfile, repos []string) []string {
547545

548546
func updateRepos(tx *gorm.DB, profile inventory.SystemProfile, rhAccountID int,
549547
systemID int64, repos []string) (addedRepos int64, addedSysRepos int64, deletedSysRepos int64, err error) {
550-
tStart := time.Now()
551-
defer utils.ObserveSecondsSince(tStart, messagePartDuration.WithLabelValues("update-repos"))
548+
defer utils.ObserveSecondsSince(time.Now(), messagePartDuration.WithLabelValues("update-repos"))
552549
repos = fixEpelRepos(&profile, repos)
553550
repoIDs, addedRepos, err := ensureReposInDB(tx, repos)
554551
if err != nil {
@@ -743,8 +740,7 @@ func processModules(systemProfile *inventory.SystemProfile) *[]vmaas.UpdatesV3Re
743740

744741
// We have received new upload, update stored host data, and re-evaluate the host against VMaaS
745742
func processUpload(host *Host, yumUpdates *YumUpdates) (*models.SystemPlatformV2, error) {
746-
tStart := time.Now()
747-
defer utils.ObserveSecondsSince(tStart, messagePartDuration.WithLabelValues("upload-processing"))
743+
defer utils.ObserveSecondsSince(time.Now(), messagePartDuration.WithLabelValues("upload-processing"))
748744
// Ensure we have account stored
749745
accountID, err := middlewares.GetOrCreateAccount(host.GetOrgID())
750746
if err != nil {

0 commit comments

Comments
 (0)