From 4e57bd1d307d20341e9ae5cdb6aeb7913bd1f59d Mon Sep 17 00:00:00 2001 From: zeripath Date: Sat, 12 Feb 2022 05:31:26 +0000 Subject: [PATCH] Add number in queue status to monitor page (#18712) Add number in queue status to the monitor page so that administrators can assess how much work is left to be done in the queues. Signed-off-by: Andrew Thornton Co-authored-by: Lunny Xiao Co-authored-by: wxiaoguang --- modules/queue/manager.go | 10 ++++++++++ modules/queue/queue_bytefifo.go | 7 +++++++ modules/queue/workerpool.go | 5 +++++ options/locale/locale_en-US.ini | 1 + templates/admin/monitor.tmpl | 2 ++ templates/admin/queue.tmpl | 2 ++ 6 files changed, 27 insertions(+) diff --git a/modules/queue/manager.go b/modules/queue/manager.go index 73c57540be85..bba2c54ad21f 100644 --- a/modules/queue/manager.go +++ b/modules/queue/manager.go @@ -84,6 +84,8 @@ type ManagedPool interface { BoostWorkers() int // SetPoolSettings sets the user updatable settings for the pool SetPoolSettings(maxNumberOfWorkers, boostWorkers int, timeout time.Duration) + // NumberInQueue returns the total number of items in the pool + NumberInQueue() int64 // Done returns a channel that will be closed when the Pool's baseCtx is closed Done() <-chan struct{} } @@ -427,6 +429,14 @@ func (q *ManagedQueue) SetPoolSettings(maxNumberOfWorkers, boostWorkers int, tim } } +// NumberInQueue returns the number of items in the queue +func (q *ManagedQueue) NumberInQueue() int64 { + if pool, ok := q.Managed.(ManagedPool); ok { + return pool.NumberInQueue() + } + return -1 +} + func (l ManagedQueueList) Len() int { return len(l) } diff --git a/modules/queue/queue_bytefifo.go b/modules/queue/queue_bytefifo.go index bf153d70bb75..ead3828f332b 100644 --- a/modules/queue/queue_bytefifo.go +++ b/modules/queue/queue_bytefifo.go @@ -135,6 +135,13 @@ func (q *ByteFIFOQueue) IsEmpty() bool { return q.byteFIFO.Len(q.terminateCtx) == 0 } +// NumberInQueue returns the number in the queue +func (q *ByteFIFOQueue) NumberInQueue() int64 { + q.lock.Lock() + defer q.lock.Unlock() + return q.byteFIFO.Len(q.terminateCtx) + q.WorkerPool.NumberInQueue() +} + // Flush flushes the ByteFIFOQueue func (q *ByteFIFOQueue) Flush(timeout time.Duration) error { select { diff --git a/modules/queue/workerpool.go b/modules/queue/workerpool.go index 100197c5e1f1..5f6ec1871019 100644 --- a/modules/queue/workerpool.go +++ b/modules/queue/workerpool.go @@ -204,6 +204,11 @@ func (p *WorkerPool) NumberOfWorkers() int { return p.numberOfWorkers } +// NumberInQueue returns the number of items in the queue +func (p *WorkerPool) NumberInQueue() int64 { + return atomic.LoadInt64(&p.numInQueue) +} + // MaxNumberOfWorkers returns the maximum number of workers automatically added to the pool func (p *WorkerPool) MaxNumberOfWorkers() int { p.lock.Lock() diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 722cade0eba6..f52fef3c0590 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -2820,6 +2820,7 @@ monitor.queue.type = Type monitor.queue.exemplar = Exemplar Type monitor.queue.numberworkers = Number of Workers monitor.queue.maxnumberworkers = Max Number of Workers +monitor.queue.numberinqueue = Number in Queue monitor.queue.review = Review Config monitor.queue.review_add = Review/Add Workers monitor.queue.configuration = Initial Configuration diff --git a/templates/admin/monitor.tmpl b/templates/admin/monitor.tmpl index 8a90f9b6474c..a35b587bd509 100644 --- a/templates/admin/monitor.tmpl +++ b/templates/admin/monitor.tmpl @@ -48,6 +48,7 @@ {{.i18n.Tr "admin.monitor.queue.type"}} {{.i18n.Tr "admin.monitor.queue.exemplar"}} {{.i18n.Tr "admin.monitor.queue.numberworkers"}} + {{.i18n.Tr "admin.monitor.queue.numberinqueue"}} @@ -58,6 +59,7 @@ {{.Type}} {{.ExemplarType}} {{$sum := .NumberOfWorkers}}{{if lt $sum 0}}-{{else}}{{$sum}}{{end}} + {{$sum := .NumberInQueue}}{{if lt $sum 0}}-{{else}}{{$sum}}{{end}} {{if lt $sum 0}}{{$.i18n.Tr "admin.monitor.queue.review"}}{{else}}{{$.i18n.Tr "admin.monitor.queue.review_add"}}{{end}} {{end}} diff --git a/templates/admin/queue.tmpl b/templates/admin/queue.tmpl index d2d2c83baf48..a08b44277cac 100644 --- a/templates/admin/queue.tmpl +++ b/templates/admin/queue.tmpl @@ -15,6 +15,7 @@ {{.i18n.Tr "admin.monitor.queue.exemplar"}} {{.i18n.Tr "admin.monitor.queue.numberworkers"}} {{.i18n.Tr "admin.monitor.queue.maxnumberworkers"}} + {{.i18n.Tr "admin.monitor.queue.numberinqueue"}} @@ -24,6 +25,7 @@ {{.Queue.ExemplarType}} {{$sum := .Queue.NumberOfWorkers}}{{if lt $sum 0}}-{{else}}{{$sum}}{{end}} {{if lt $sum 0}}-{{else}}{{.Queue.MaxNumberOfWorkers}}{{end}} + {{$sum := .Queue.NumberInQueue}}{{if lt $sum 0}}-{{else}}{{$sum}}{{end}}