From d11cb93f3fccf9ffa743b6b4dc0b397de4e8db91 Mon Sep 17 00:00:00 2001 From: Patrik Segedy Date: Fri, 3 Nov 2023 16:38:28 +0100 Subject: [PATCH] RHINENG-2610: use latest_repo_change timestamp for repo based re-eval --- base/vmaas/vmaas.go | 11 ++++++----- tasks/vmaas_sync/repo_based.go | 13 ++++++++----- tasks/vmaas_sync/repo_sync.go | 2 +- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/base/vmaas/vmaas.go b/base/vmaas/vmaas.go index 851763e8e..f16f5a17f 100644 --- a/base/vmaas/vmaas.go +++ b/base/vmaas/vmaas.go @@ -264,11 +264,12 @@ type ReposRequest struct { } type ReposResponse struct { - Page int `json:"page,omitempty"` - PageSize int `json:"page_size,omitempty"` - Pages int `json:"pages,omitempty"` - RepositoryList map[string][]map[string]interface{} `json:"repository_list,omitempty"` - LastChange *string `json:"last_change,omitempty"` + Page int `json:"page,omitempty"` + PageSize int `json:"page_size,omitempty"` + Pages int `json:"pages,omitempty"` + RepositoryList map[string][]map[string]interface{} `json:"repository_list,omitempty"` + LastChange *string `json:"last_change,omitempty"` + LatestRepoChange *types.Rfc3339Timestamp `json:"latest_repo_change,omitempty"` } type DBChangeResponse struct { diff --git a/tasks/vmaas_sync/repo_based.go b/tasks/vmaas_sync/repo_based.go index 8534645af..c5c6c8287 100644 --- a/tasks/vmaas_sync/repo_based.go +++ b/tasks/vmaas_sync/repo_based.go @@ -24,7 +24,7 @@ func getCurrentRepoBasedInventoryIDs() ([]mqueue.EvalData, error) { } now := time.Now() - redhatRepos, thirdPartyRepos, err := getUpdatedRepos(now, lastRepoBaseEval) + redhatRepos, thirdPartyRepos, latestRepoChange, err := getUpdatedRepos(now, lastRepoBaseEval) allRepos := append(redhatRepos, thirdPartyRepos...) if err != nil { @@ -36,7 +36,7 @@ func getCurrentRepoBasedInventoryIDs() ([]mqueue.EvalData, error) { return nil, err } - database.UpdateTimestampKVValue(LastEvalRepoBased, now) + database.UpdateTimestampKVValue(LastEvalRepoBased, *latestRepoChange) return inventoryAIDs, nil } @@ -61,10 +61,11 @@ func getRepoBasedInventoryIDs(repos []string) ([]mqueue.EvalData, error) { return ids, nil } -func getUpdatedRepos(syncStart time.Time, modifiedSince *string) ([]string, []string, error) { +func getUpdatedRepos(syncStart time.Time, modifiedSince *string) ([]string, []string, *time.Time, error) { page := 1 var reposRedHat []string var reposThirdParty []string + var latestRepoChange *time.Time reposSyncStart := time.Now() for { reposReq := vmaas.ReposRequest{ @@ -83,7 +84,7 @@ func getUpdatedRepos(syncStart time.Time, modifiedSince *string) ([]string, []st vmaasDataPtr, err := utils.HTTPCallRetry(base.Context, vmaasCallFunc, vmaasCallExpRetry, vmaasCallMaxRetries) if err != nil { - return nil, nil, err + return nil, nil, nil, err } vmaasCallCnt.WithLabelValues("success").Inc() repos := vmaasDataPtr.(*vmaas.ReposResponse) @@ -92,6 +93,8 @@ func getUpdatedRepos(syncStart time.Time, modifiedSince *string) ([]string, []st break } + latestRepoChange = repos.LatestRepoChange.Time() + utils.LogInfo("page", page, "pages", repos.Pages, "count", len(repos.RepositoryList), "sync_duration", utils.SinceStr(syncStart, time.Second), "repos_sync_duration", utils.SinceStr(reposSyncStart, time.Second), @@ -119,5 +122,5 @@ func getUpdatedRepos(syncStart time.Time, modifiedSince *string) ([]string, []st } utils.LogInfo("redhat", len(reposRedHat), "thirdparty", len(reposThirdParty), "Repos downloading complete") - return reposRedHat, reposThirdParty, nil + return reposRedHat, reposThirdParty, latestRepoChange, nil } diff --git a/tasks/vmaas_sync/repo_sync.go b/tasks/vmaas_sync/repo_sync.go index f942fc614..665fbd5ff 100644 --- a/tasks/vmaas_sync/repo_sync.go +++ b/tasks/vmaas_sync/repo_sync.go @@ -9,7 +9,7 @@ import ( func syncRepos(syncStart time.Time) error { // mark non-thirdparty repos known to vmaas - redhatRepos, _, err := getUpdatedRepos(syncStart, nil) + redhatRepos, _, _, err := getUpdatedRepos(syncStart, nil) if err != nil { return err }