Skip to content

Commit

Permalink
RHINENG-2610: use latest_repo_change timestamp for repo based re-eval
Browse files Browse the repository at this point in the history
  • Loading branch information
psegedy committed Nov 3, 2023
1 parent 8bb6ead commit d11cb93
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
11 changes: 6 additions & 5 deletions base/vmaas/vmaas.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
13 changes: 8 additions & 5 deletions tasks/vmaas_sync/repo_based.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -36,7 +36,7 @@ func getCurrentRepoBasedInventoryIDs() ([]mqueue.EvalData, error) {
return nil, err
}

database.UpdateTimestampKVValue(LastEvalRepoBased, now)
database.UpdateTimestampKVValue(LastEvalRepoBased, *latestRepoChange)

return inventoryAIDs, nil
}
Expand All @@ -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{
Expand All @@ -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)
Expand All @@ -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),
Expand Down Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion tasks/vmaas_sync/repo_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit d11cb93

Please sign in to comment.