Skip to content
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

RHINENG-11978: fix missing metrics after evaluator refactor #1462

Merged
merged 1 commit into from
Aug 20, 2024
Merged
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
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,21 @@ 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")
updatesCnt.WithLabelValues("patched").Add(float64(len(deleteIDs)))
utils.LogInfo("inventoryID", system.InventoryID, "fixed", len(deleteIDs), "fixed advisories")
return deleteIDs, advisoryObjs
}

Expand All @@ -355,6 +372,7 @@ func updateSystemAdvisories(tx *gorm.DB, system *models.SystemPlatform,
}

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
Loading