From 262f22f5ef7bd82bdd3fa878a19607095f34c7f2 Mon Sep 17 00:00:00 2001 From: Wang Yan Date: Wed, 2 Sep 2020 17:11:05 +0800 Subject: [PATCH] fix gc log issue (#12943) 1, Do not log redis url, just log the user input from UI. 2, Format the artifact trash items. Signed-off-by: wang yan --- .../job/impl/gc/garbage_collection.go | 25 +++++++++++-------- src/pkg/artifactrash/model/model.go | 6 +++++ 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/jobservice/job/impl/gc/garbage_collection.go b/src/jobservice/job/impl/gc/garbage_collection.go index cba55179d..0616bcd45 100644 --- a/src/jobservice/job/impl/gc/garbage_collection.go +++ b/src/jobservice/job/impl/gc/garbage_collection.go @@ -112,7 +112,6 @@ func (gc *GarbageCollector) init(ctx job.Context, params job.Parameters) error { // parseParams set the parameters according to the GC API call. func (gc *GarbageCollector) parseParams(params job.Parameters) { // redis url - gc.logger.Info(params) gc.redisURL = params["redis_url_reg"].(string) // delete untagged: default is to delete the untagged artifact @@ -141,6 +140,9 @@ func (gc *GarbageCollector) parseParams(params job.Parameters) { gc.dryRun = dryRun } } + + gc.logger.Infof("Garbage Collection parameters: [delete_untagged: %t, dry_run: %t, time_window: %d]", + gc.deleteUntagged, gc.dryRun, gc.timeWindowHours) } // Run implements the interface in job/Interface @@ -395,18 +397,21 @@ func (gc *GarbageCollector) deletedArt(ctx job.Context) (map[string][]model.Arti } // group the deleted artifact by digest. The repositories of blob is needed when to delete as a manifest. - for _, art := range arts { - _, exist := artMap[art.Digest] - if !exist { - artMap[art.Digest] = []model.ArtifactTrash{art} - } else { - repos := artMap[art.Digest] - repos = append(repos, art) - artMap[art.Digest] = repos + if len(arts) > 0 { + gc.logger.Info("artifact trash candidates.") + for _, art := range arts { + gc.logger.Info(art.String()) + _, exist := artMap[art.Digest] + if !exist { + artMap[art.Digest] = []model.ArtifactTrash{art} + } else { + repos := artMap[art.Digest] + repos = append(repos, art) + artMap[art.Digest] = repos + } } } - gc.logger.Info("required candidate: %+v", arts) return artMap, nil } diff --git a/src/pkg/artifactrash/model/model.go b/src/pkg/artifactrash/model/model.go index c1cd5688d..238e36a25 100644 --- a/src/pkg/artifactrash/model/model.go +++ b/src/pkg/artifactrash/model/model.go @@ -15,6 +15,7 @@ package model import ( + "fmt" "github.com/astaxie/beego/orm" "time" ) @@ -37,3 +38,8 @@ type ArtifactTrash struct { func (at *ArtifactTrash) TableName() string { return "artifact_trash" } + +func (at *ArtifactTrash) String() string { + return fmt.Sprintf("ID-%d MediaType-%s ManifestMediaType-%s RepositoryName-%s Digest-%s CreationTime-%s", + at.ID, at.MediaType, at.ManifestMediaType, at.RepositoryName, at.Digest, at.CreationTime.Format("2006-01-02 15:04:05")) +}