Skip to content

Commit

Permalink
RHINENG-11978: fix missing metrics after evaluator refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Dugowitch committed Aug 15, 2024
1 parent a0aaa63 commit 1ba0024
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions evaluator/evaluate_advisories.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ func loadMissingNamesIDs(missingNames []string, extendedAdvisories extendedAdvis
// and tracks them in extendedAdvisoryMap.
func evaluateChanges(vmaasData *vmaas.UpdatesV3Response, stored SystemAdvisoryMap) (
extendedAdvisoryMap, error) {
defer utils.ObserveSecondsSince(time.Now(), evaluationPartDuration.WithLabelValues("advisories-evaluate"))
reported := getReportedAdvisories(vmaasData)
extendedAdvisories := make(extendedAdvisoryMap, len(reported)+len(stored))
missingNames := make([]string, 0, len(reported))
Expand Down Expand Up @@ -123,6 +124,7 @@ func evaluateChanges(vmaasData *vmaas.UpdatesV3Response, stored SystemAdvisoryMa

// LazySaveAdvisories finds advisories reported by VMaaS and missing in the DB and lazy saves them.
func lazySaveAdvisories(vmaasData *vmaas.UpdatesV3Response, inventoryID string) error {
defer utils.ObserveSecondsSince(time.Now(), evaluationPartDuration.WithLabelValues("advisories-lazy-save"))
reportedNames := getReportedAdvisories(vmaasData)
if len(reportedNames) < 1 {
return nil
Expand Down Expand Up @@ -321,6 +323,8 @@ func processAdvisories(system *models.SystemPlatform, advisoriesByName extendedA
models.SystemAdvisoriesSlice) {
deleteIDs := make([]int64, 0, len(advisoriesByName))
advisoryObjs := make(models.SystemAdvisoriesSlice, 0, len(advisoriesByName))
installableCnt := 0
applicableCnt := 0
for _, advisory := range advisoriesByName {
switch advisory.change {
case Remove:
Expand All @@ -337,8 +341,19 @@ func processAdvisories(system *models.SystemPlatform, advisoriesByName extendedA
StatusID: advisory.StatusID,
}
advisoryObjs = append(advisoryObjs, adv)
fallthrough
case Keep:
if advisory.StatusID == INSTALLABLE {
installableCnt++
} else { // APPLICABLE
applicableCnt++
}
}
}
updatesCnt.WithLabelValues("installable").Add(float64(installableCnt))
utils.LogInfo("inventoryID", system.InventoryID, "installable", installableCnt, "installable advisories")
updatesCnt.WithLabelValues("applicable").Add(float64(applicableCnt))
utils.LogInfo("inventoryID", system.InventoryID, "applicable", applicableCnt, "applicable advisories")
return deleteIDs, advisoryObjs
}

Expand All @@ -350,11 +365,14 @@ func updateSystemAdvisories(tx *gorm.DB, system *models.SystemPlatform,
if err != nil {
return err
}
updatesCnt.WithLabelValues("patched").Add(float64(len(deleteIDs)))
utils.LogInfo("inventoryID", system.InventoryID, "fixed", len(deleteIDs), "fixed advisories")

return upsertSystemAdvisories(tx, advisoryObjs)
}

func loadSystemAdvisories(tx *gorm.DB, accountID int, systemID int64) (SystemAdvisoryMap, error) {
defer utils.ObserveSecondsSince(time.Now(), evaluationPartDuration.WithLabelValues("advisories-load"))
var data []models.SystemAdvisories
err := tx.Preload("Advisory").Find(&data, "system_id = ? AND rh_account_id = ?", systemID, accountID).Error
if err != nil {
Expand Down

0 comments on commit 1ba0024

Please sign in to comment.