diff --git a/pkg/api/cookiestore.go b/pkg/api/cookiestore.go index 94769d34..46a542f9 100644 --- a/pkg/api/cookiestore.go +++ b/pkg/api/cookiestore.go @@ -30,7 +30,11 @@ type CookieStore struct { func (c *CookieStore) RunSessionCleaner(sch *scheduler.Scheduler) { if c.needsCleanup { - sch.SubmitGenerator(&SessionCleanup{rootDir: c.rootDir}, cookiesMaxAge, scheduler.LowPriority) + sch.SubmitGenerator( + &SessionCleanup{rootDir: c.rootDir}, + cookiesMaxAge*time.Second, + scheduler.LowPriority, + ) } } @@ -122,6 +126,10 @@ type SessionCleanup struct { done bool } +func (gen *SessionCleanup) Name() string { + return "SessionCleanupGenerator" +} + func (gen *SessionCleanup) Next() (scheduler.Task, error) { sessions, err := getExpiredSessions(gen.rootDir) if err != nil { diff --git a/pkg/extensions/extension_scrub.go b/pkg/extensions/extension_scrub.go index 6fa31e8d..553fcc26 100644 --- a/pkg/extensions/extension_scrub.go +++ b/pkg/extensions/extension_scrub.go @@ -55,6 +55,10 @@ type taskGenerator struct { done bool } +func (gen *taskGenerator) Name() string { + return "ScrubGenerator" +} + func (gen *taskGenerator) Next() (scheduler.Task, error) { repo, err := gen.imgStore.GetNextRepository(gen.lastRepo) if err != nil { diff --git a/pkg/extensions/imagetrust/image_trust.go b/pkg/extensions/imagetrust/image_trust.go index dcdf5c02..ce992c20 100644 --- a/pkg/extensions/imagetrust/image_trust.go +++ b/pkg/extensions/imagetrust/image_trust.go @@ -200,6 +200,10 @@ type sigValidityTaskGenerator struct { log log.Logger } +func (gen *sigValidityTaskGenerator) Name() string { + return "SignatureValidationGenerator" +} + func (gen *sigValidityTaskGenerator) Next() (scheduler.Task, error) { if len(gen.repos) == 0 { ctx := context.Background() diff --git a/pkg/extensions/search/cve/scan.go b/pkg/extensions/search/cve/scan.go index 1e684bd6..b84a4ada 100644 --- a/pkg/extensions/search/cve/scan.go +++ b/pkg/extensions/search/cve/scan.go @@ -115,6 +115,10 @@ func (gen *scanTaskGenerator) isScheduled(digest string) bool { return ok } +func (gen *scanTaskGenerator) Name() string { + return "CVEScanGenerator" +} + func (gen *scanTaskGenerator) Next() (scheduler.Task, error) { // metaRB requires us to use a context for authorization userAc := reqCtx.NewUserAccessControl() diff --git a/pkg/extensions/search/cve/update.go b/pkg/extensions/search/cve/update.go index 89f62efd..06a81096 100644 --- a/pkg/extensions/search/cve/update.go +++ b/pkg/extensions/search/cve/update.go @@ -46,6 +46,10 @@ type DBUpdateTaskGenerator struct { lock *sync.Mutex } +func (gen *DBUpdateTaskGenerator) Name() string { + return "CVEDBUpdateGenerator" +} + func (gen *DBUpdateTaskGenerator) Next() (scheduler.Task, error) { var newTask scheduler.Task diff --git a/pkg/extensions/sync/sync.go b/pkg/extensions/sync/sync.go index 2e99b9ac..986fbb24 100644 --- a/pkg/extensions/sync/sync.go +++ b/pkg/extensions/sync/sync.go @@ -90,6 +90,10 @@ func NewTaskGenerator(service Service, log log.Logger) *TaskGenerator { } } +func (gen *TaskGenerator) Name() string { + return "SyncGenerator" +} + func (gen *TaskGenerator) Next() (scheduler.Task, error) { if err := gen.Service.SetNextAvailableURL(); err != nil { return nil, err diff --git a/pkg/scheduler/scheduler.go b/pkg/scheduler/scheduler.go index c0c15ed6..9b98d6c0 100644 --- a/pkg/scheduler/scheduler.go +++ b/pkg/scheduler/scheduler.go @@ -304,7 +304,8 @@ func (scheduler *Scheduler) pushReadyGenerators() { scheduler.waitingGenerators = append(scheduler.waitingGenerators[:i], scheduler.waitingGenerators[i+1:]...) modified = true - scheduler.log.Debug().Msg("waiting generator is ready, pushing to ready generators") + scheduler.log.Debug().Str("generator", gen.taskGenerator.Name()). + Msg("waiting generator is ready, pushing to ready generators") break } @@ -435,6 +436,7 @@ type TaskGenerator interface { Next() (Task, error) IsDone() bool IsReady() bool + Name() string Reset() } @@ -459,7 +461,8 @@ func (gen *generator) generate(sch *Scheduler) { if gen.remainingTask == nil { nextTask, err := gen.taskGenerator.Next() if err != nil { - sch.log.Error().Err(err).Msg("failed to execute generator") + sch.log.Error().Err(err).Str("generator", gen.taskGenerator.Name()). + Msg("failed to execute generator") return } @@ -471,6 +474,9 @@ func (gen *generator) generate(sch *Scheduler) { gen.taskCount = 0 gen.taskGenerator.Reset() + sch.log.Debug().Str("generator", gen.taskGenerator.Name()). + Msg("generator is done") + return } diff --git a/pkg/scheduler/scheduler_test.go b/pkg/scheduler/scheduler_test.go index b4e5c99e..8a3adaf2 100644 --- a/pkg/scheduler/scheduler_test.go +++ b/pkg/scheduler/scheduler_test.go @@ -63,6 +63,10 @@ type generator struct { taskDelay time.Duration } +func (g *generator) Name() string { + return "TestGenerator" +} + func (g *generator) Next() (scheduler.Task, error) { if g.step > g.limit { g.done = true @@ -107,6 +111,10 @@ type shortGenerator struct { step int } +func (g *shortGenerator) Name() string { + return "ShortTestGenerator" +} + func (g *shortGenerator) Next() (scheduler.Task, error) { g.done = true diff --git a/pkg/storage/common/common.go b/pkg/storage/common/common.go index b102a880..506fbb37 100644 --- a/pkg/storage/common/common.go +++ b/pkg/storage/common/common.go @@ -972,6 +972,10 @@ type DedupeTaskGenerator struct { Log zlog.Logger } +func (gen *DedupeTaskGenerator) Name() string { + return "DedupeTaskGenerator" +} + func (gen *DedupeTaskGenerator) Next() (scheduler.Task, error) { var err error @@ -1085,6 +1089,10 @@ type StorageMetricsInitGenerator struct { MaxDelay int } +func (gen *StorageMetricsInitGenerator) Name() string { + return "StorageMetricsInitGenerator" +} + func (gen *StorageMetricsInitGenerator) Next() (scheduler.Task, error) { if gen.lastRepo == "" && gen.nextRun.IsZero() { gen.rand = rand.New(rand.NewSource(time.Now().UTC().UnixNano())) //nolint: gosec diff --git a/pkg/storage/gc/gc.go b/pkg/storage/gc/gc.go index ce7ce427..a0cfdbb7 100644 --- a/pkg/storage/gc/gc.go +++ b/pkg/storage/gc/gc.go @@ -800,6 +800,10 @@ func (gen *GCTaskGenerator) getRandomDelay() int { return gen.rand.Intn(maxDelay) } +func (gen *GCTaskGenerator) Name() string { + return "GCTaskGenerator" +} + func (gen *GCTaskGenerator) Next() (scheduler.Task, error) { if gen.lastRepo == "" && gen.nextRun.IsZero() { gen.rand = rand.New(rand.NewSource(time.Now().UTC().UnixNano())) //nolint: gosec