mirror of
https://github.com/project-zot/zot.git
synced 2024-12-16 21:56:37 -05:00
fix(scheduler): the session cleanup generator is reset too often (#2220)
This causes the "fair" scheduler to run it too often in the detriment of other generators. The intention was to run it every 2 hours but the measurement unit for 7200 was not specified. Add more logs, including showing a generator name, in order to troubleshoot this kind of issues easier in the future. Signed-off-by: Andrei Aaron <aaaron@luxoft.com>
This commit is contained in:
parent
ce4924f841
commit
6a83dd47c0
10 changed files with 57 additions and 3 deletions
|
@ -30,7 +30,11 @@ type CookieStore struct {
|
||||||
|
|
||||||
func (c *CookieStore) RunSessionCleaner(sch *scheduler.Scheduler) {
|
func (c *CookieStore) RunSessionCleaner(sch *scheduler.Scheduler) {
|
||||||
if c.needsCleanup {
|
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
|
done bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (gen *SessionCleanup) Name() string {
|
||||||
|
return "SessionCleanupGenerator"
|
||||||
|
}
|
||||||
|
|
||||||
func (gen *SessionCleanup) Next() (scheduler.Task, error) {
|
func (gen *SessionCleanup) Next() (scheduler.Task, error) {
|
||||||
sessions, err := getExpiredSessions(gen.rootDir)
|
sessions, err := getExpiredSessions(gen.rootDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -55,6 +55,10 @@ type taskGenerator struct {
|
||||||
done bool
|
done bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (gen *taskGenerator) Name() string {
|
||||||
|
return "ScrubGenerator"
|
||||||
|
}
|
||||||
|
|
||||||
func (gen *taskGenerator) Next() (scheduler.Task, error) {
|
func (gen *taskGenerator) Next() (scheduler.Task, error) {
|
||||||
repo, err := gen.imgStore.GetNextRepository(gen.lastRepo)
|
repo, err := gen.imgStore.GetNextRepository(gen.lastRepo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -200,6 +200,10 @@ type sigValidityTaskGenerator struct {
|
||||||
log log.Logger
|
log log.Logger
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (gen *sigValidityTaskGenerator) Name() string {
|
||||||
|
return "SignatureValidationGenerator"
|
||||||
|
}
|
||||||
|
|
||||||
func (gen *sigValidityTaskGenerator) Next() (scheduler.Task, error) {
|
func (gen *sigValidityTaskGenerator) Next() (scheduler.Task, error) {
|
||||||
if len(gen.repos) == 0 {
|
if len(gen.repos) == 0 {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
|
@ -115,6 +115,10 @@ func (gen *scanTaskGenerator) isScheduled(digest string) bool {
|
||||||
return ok
|
return ok
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (gen *scanTaskGenerator) Name() string {
|
||||||
|
return "CVEScanGenerator"
|
||||||
|
}
|
||||||
|
|
||||||
func (gen *scanTaskGenerator) Next() (scheduler.Task, error) {
|
func (gen *scanTaskGenerator) Next() (scheduler.Task, error) {
|
||||||
// metaRB requires us to use a context for authorization
|
// metaRB requires us to use a context for authorization
|
||||||
userAc := reqCtx.NewUserAccessControl()
|
userAc := reqCtx.NewUserAccessControl()
|
||||||
|
|
|
@ -46,6 +46,10 @@ type DBUpdateTaskGenerator struct {
|
||||||
lock *sync.Mutex
|
lock *sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (gen *DBUpdateTaskGenerator) Name() string {
|
||||||
|
return "CVEDBUpdateGenerator"
|
||||||
|
}
|
||||||
|
|
||||||
func (gen *DBUpdateTaskGenerator) Next() (scheduler.Task, error) {
|
func (gen *DBUpdateTaskGenerator) Next() (scheduler.Task, error) {
|
||||||
var newTask scheduler.Task
|
var newTask scheduler.Task
|
||||||
|
|
||||||
|
|
|
@ -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) {
|
func (gen *TaskGenerator) Next() (scheduler.Task, error) {
|
||||||
if err := gen.Service.SetNextAvailableURL(); err != nil {
|
if err := gen.Service.SetNextAvailableURL(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
@ -304,7 +304,8 @@ func (scheduler *Scheduler) pushReadyGenerators() {
|
||||||
scheduler.waitingGenerators = append(scheduler.waitingGenerators[:i], scheduler.waitingGenerators[i+1:]...)
|
scheduler.waitingGenerators = append(scheduler.waitingGenerators[:i], scheduler.waitingGenerators[i+1:]...)
|
||||||
modified = true
|
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
|
break
|
||||||
}
|
}
|
||||||
|
@ -435,6 +436,7 @@ type TaskGenerator interface {
|
||||||
Next() (Task, error)
|
Next() (Task, error)
|
||||||
IsDone() bool
|
IsDone() bool
|
||||||
IsReady() bool
|
IsReady() bool
|
||||||
|
Name() string
|
||||||
Reset()
|
Reset()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -459,7 +461,8 @@ func (gen *generator) generate(sch *Scheduler) {
|
||||||
if gen.remainingTask == nil {
|
if gen.remainingTask == nil {
|
||||||
nextTask, err := gen.taskGenerator.Next()
|
nextTask, err := gen.taskGenerator.Next()
|
||||||
if err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
|
@ -471,6 +474,9 @@ func (gen *generator) generate(sch *Scheduler) {
|
||||||
gen.taskCount = 0
|
gen.taskCount = 0
|
||||||
gen.taskGenerator.Reset()
|
gen.taskGenerator.Reset()
|
||||||
|
|
||||||
|
sch.log.Debug().Str("generator", gen.taskGenerator.Name()).
|
||||||
|
Msg("generator is done")
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -63,6 +63,10 @@ type generator struct {
|
||||||
taskDelay time.Duration
|
taskDelay time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (g *generator) Name() string {
|
||||||
|
return "TestGenerator"
|
||||||
|
}
|
||||||
|
|
||||||
func (g *generator) Next() (scheduler.Task, error) {
|
func (g *generator) Next() (scheduler.Task, error) {
|
||||||
if g.step > g.limit {
|
if g.step > g.limit {
|
||||||
g.done = true
|
g.done = true
|
||||||
|
@ -107,6 +111,10 @@ type shortGenerator struct {
|
||||||
step int
|
step int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (g *shortGenerator) Name() string {
|
||||||
|
return "ShortTestGenerator"
|
||||||
|
}
|
||||||
|
|
||||||
func (g *shortGenerator) Next() (scheduler.Task, error) {
|
func (g *shortGenerator) Next() (scheduler.Task, error) {
|
||||||
g.done = true
|
g.done = true
|
||||||
|
|
||||||
|
|
|
@ -972,6 +972,10 @@ type DedupeTaskGenerator struct {
|
||||||
Log zlog.Logger
|
Log zlog.Logger
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (gen *DedupeTaskGenerator) Name() string {
|
||||||
|
return "DedupeTaskGenerator"
|
||||||
|
}
|
||||||
|
|
||||||
func (gen *DedupeTaskGenerator) Next() (scheduler.Task, error) {
|
func (gen *DedupeTaskGenerator) Next() (scheduler.Task, error) {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
|
@ -1085,6 +1089,10 @@ type StorageMetricsInitGenerator struct {
|
||||||
MaxDelay int
|
MaxDelay int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (gen *StorageMetricsInitGenerator) Name() string {
|
||||||
|
return "StorageMetricsInitGenerator"
|
||||||
|
}
|
||||||
|
|
||||||
func (gen *StorageMetricsInitGenerator) Next() (scheduler.Task, error) {
|
func (gen *StorageMetricsInitGenerator) Next() (scheduler.Task, error) {
|
||||||
if gen.lastRepo == "" && gen.nextRun.IsZero() {
|
if gen.lastRepo == "" && gen.nextRun.IsZero() {
|
||||||
gen.rand = rand.New(rand.NewSource(time.Now().UTC().UnixNano())) //nolint: gosec
|
gen.rand = rand.New(rand.NewSource(time.Now().UTC().UnixNano())) //nolint: gosec
|
||||||
|
|
|
@ -800,6 +800,10 @@ func (gen *GCTaskGenerator) getRandomDelay() int {
|
||||||
return gen.rand.Intn(maxDelay)
|
return gen.rand.Intn(maxDelay)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (gen *GCTaskGenerator) Name() string {
|
||||||
|
return "GCTaskGenerator"
|
||||||
|
}
|
||||||
|
|
||||||
func (gen *GCTaskGenerator) Next() (scheduler.Task, error) {
|
func (gen *GCTaskGenerator) Next() (scheduler.Task, error) {
|
||||||
if gen.lastRepo == "" && gen.nextRun.IsZero() {
|
if gen.lastRepo == "" && gen.nextRun.IsZero() {
|
||||||
gen.rand = rand.New(rand.NewSource(time.Now().UTC().UnixNano())) //nolint: gosec
|
gen.rand = rand.New(rand.NewSource(time.Now().UTC().UnixNano())) //nolint: gosec
|
||||||
|
|
Loading…
Reference in a new issue