Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 10 additions & 20 deletions evaluator/evaluate.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,7 @@ func confugureEvaluator() {
}

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

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

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

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

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

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

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

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

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

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

tStart := time.Now()
defer utils.ObserveSecondsSince(tStart, evaluationPartDuration.WithLabelValues("repo-analysis"))
defer utils.ObserveSecondsSince(time.Now(), evaluationPartDuration.WithLabelValues("repo-analysis"))

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

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

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

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

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

func parseVmaasJSON(inv *models.SystemInventory) (vmaas.UpdatesV3Request, error) {
tStart := time.Now()
defer utils.ObserveSecondsSince(tStart, evaluationPartDuration.WithLabelValues("parse-vmaas-json"))
defer utils.ObserveSecondsSince(time.Now(), evaluationPartDuration.WithLabelValues("parse-vmaas-json"))
return utils.ParseVmaasJSON(inv)
}

Expand Down
3 changes: 1 addition & 2 deletions evaluator/evaluate_advisories.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ func lazySaveAndLoadAdvisories(system *models.SystemPlatformV2, vmaasData *vmaas
return nil, nil
}

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

err := lazySaveAdvisories(vmaasData, system.GetInventoryID())
if err != nil {
Expand Down
3 changes: 1 addition & 2 deletions evaluator/evaluate_packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ func lazySaveAndLoadPackages(system *models.SystemPlatformV2, vmaasData *vmaas.U
return nil, 0, 0, 0, nil
}

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

err := lazySavePackages(vmaasData)
if err != nil {
Expand Down
3 changes: 1 addition & 2 deletions evaluator/inventory_views.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ func publishInventoryViewsEvent(tx *gorm.DB, systems []models.SystemPlatformV2,
return nil
}

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

orgID := origin.GetOrgID()
var requestID string
Expand Down
3 changes: 1 addition & 2 deletions evaluator/notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ func publishNewAdvisoriesNotification(tx *gorm.DB, system *models.SystemPlatform
return nil
}

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

advisories, err := getUnnotifiedAdvisories(tx, system.Inventory.RhAccountID, newAdvisories)
if err != nil {
Expand Down
3 changes: 1 addition & 2 deletions evaluator/remediations.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ func getReportedPackageUpdates(vmaasData *vmaas.UpdatesV3Response) map[string]bo
}

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

if remediationsPublisher == nil {
return nil
Expand Down
3 changes: 1 addition & 2 deletions listener/event_buffers.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ func (b *eventBuffer) bufferEvalEvents(
rhAccountID int,
ptEvent *mqueue.PayloadTrackerEvent,
) {
tStart := time.Now()
defer utils.ObserveSecondsSince(tStart, messagePartDuration.WithLabelValues("buffer-eval-events"))
defer utils.ObserveSecondsSince(time.Now(), messagePartDuration.WithLabelValues("buffer-eval-events"))

b.lock.Lock()
evalData := mqueue.EvalData{
Expand Down
3 changes: 1 addition & 2 deletions listener/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ func EventsMessageHandler(m mqueue.KafkaMessage) error {
}

func HandleDelete(event mqueue.PlatformEvent) error {
tStart := time.Now()
defer utils.ObserveSecondsSince(tStart, messageHandlingDuration.WithLabelValues(EventDelete))
defer utils.ObserveSecondsSince(time.Now(), messageHandlingDuration.WithLabelValues(EventDelete))
// TODO: Do we need locking here ?
err := database.OnConflictUpdate(database.DB, "inventory_id", "when_deleted").
Create(models.DeletedSystem{
Expand Down
3 changes: 1 addition & 2 deletions listener/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ func TemplatesMessageHandler(m mqueue.KafkaMessage) error {
}

func TemplateDelete(template mqueue.TemplateResponse) error {
tStart := time.Now()
defer utils.ObserveSecondsSince(tStart, templateMsgHandlingDuration.WithLabelValues(TemplateEventDelete))
defer utils.ObserveSecondsSince(time.Now(), templateMsgHandlingDuration.WithLabelValues(TemplateEventDelete))

// check account
accountID, err := middlewares.GetOrCreateAccount(template.OrgID)
Expand Down
12 changes: 4 additions & 8 deletions listener/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,7 @@ func checkPackagesEpoch(packages []string) error {
}

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

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

// We have received new upload, update stored host data, and re-evaluate the host against VMaaS
func processUpload(host *Host, yumUpdates *YumUpdates) (*models.SystemPlatformV2, error) {
tStart := time.Now()
defer utils.ObserveSecondsSince(tStart, messagePartDuration.WithLabelValues("upload-processing"))
defer utils.ObserveSecondsSince(time.Now(), messagePartDuration.WithLabelValues("upload-processing"))
// Ensure we have account stored
accountID, err := middlewares.GetOrCreateAccount(host.GetOrgID())
if err != nil {
Expand Down
3 changes: 1 addition & 2 deletions tasks/vmaas_sync/send_messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ func SendReevaluationMessages() error {
return err
}

tStart := time.Now()
defer utils.ObserveSecondsSince(tStart, messageSendDuration)
defer utils.ObserveSecondsSince(time.Now(), messageSendDuration)
err = mqueue.SendMessages(base.Context, evalWriter, &inventoryAIDs)
if err != nil {
utils.LogError("err", err.Error(), "sending to re-evaluate failed")
Expand Down
Loading