Skip to content

Commit 4e57bd1

Browse files
zeripathlunnywxiaoguang
authored
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 <[email protected]> Co-authored-by: Lunny Xiao <[email protected]> Co-authored-by: wxiaoguang <[email protected]>
1 parent 9444135 commit 4e57bd1

File tree

6 files changed

+27
-0
lines changed

6 files changed

+27
-0
lines changed

modules/queue/manager.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ type ManagedPool interface {
8484
BoostWorkers() int
8585
// SetPoolSettings sets the user updatable settings for the pool
8686
SetPoolSettings(maxNumberOfWorkers, boostWorkers int, timeout time.Duration)
87+
// NumberInQueue returns the total number of items in the pool
88+
NumberInQueue() int64
8789
// Done returns a channel that will be closed when the Pool's baseCtx is closed
8890
Done() <-chan struct{}
8991
}
@@ -427,6 +429,14 @@ func (q *ManagedQueue) SetPoolSettings(maxNumberOfWorkers, boostWorkers int, tim
427429
}
428430
}
429431

432+
// NumberInQueue returns the number of items in the queue
433+
func (q *ManagedQueue) NumberInQueue() int64 {
434+
if pool, ok := q.Managed.(ManagedPool); ok {
435+
return pool.NumberInQueue()
436+
}
437+
return -1
438+
}
439+
430440
func (l ManagedQueueList) Len() int {
431441
return len(l)
432442
}

modules/queue/queue_bytefifo.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,13 @@ func (q *ByteFIFOQueue) IsEmpty() bool {
135135
return q.byteFIFO.Len(q.terminateCtx) == 0
136136
}
137137

138+
// NumberInQueue returns the number in the queue
139+
func (q *ByteFIFOQueue) NumberInQueue() int64 {
140+
q.lock.Lock()
141+
defer q.lock.Unlock()
142+
return q.byteFIFO.Len(q.terminateCtx) + q.WorkerPool.NumberInQueue()
143+
}
144+
138145
// Flush flushes the ByteFIFOQueue
139146
func (q *ByteFIFOQueue) Flush(timeout time.Duration) error {
140147
select {

modules/queue/workerpool.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,11 @@ func (p *WorkerPool) NumberOfWorkers() int {
204204
return p.numberOfWorkers
205205
}
206206

207+
// NumberInQueue returns the number of items in the queue
208+
func (p *WorkerPool) NumberInQueue() int64 {
209+
return atomic.LoadInt64(&p.numInQueue)
210+
}
211+
207212
// MaxNumberOfWorkers returns the maximum number of workers automatically added to the pool
208213
func (p *WorkerPool) MaxNumberOfWorkers() int {
209214
p.lock.Lock()

options/locale/locale_en-US.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2820,6 +2820,7 @@ monitor.queue.type = Type
28202820
monitor.queue.exemplar = Exemplar Type
28212821
monitor.queue.numberworkers = Number of Workers
28222822
monitor.queue.maxnumberworkers = Max Number of Workers
2823+
monitor.queue.numberinqueue = Number in Queue
28232824
monitor.queue.review = Review Config
28242825
monitor.queue.review_add = Review/Add Workers
28252826
monitor.queue.configuration = Initial Configuration

templates/admin/monitor.tmpl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
<th>{{.i18n.Tr "admin.monitor.queue.type"}}</th>
4949
<th>{{.i18n.Tr "admin.monitor.queue.exemplar"}}</th>
5050
<th>{{.i18n.Tr "admin.monitor.queue.numberworkers"}}</th>
51+
<th>{{.i18n.Tr "admin.monitor.queue.numberinqueue"}}</th>
5152
<th></th>
5253
</tr>
5354
</thead>
@@ -58,6 +59,7 @@
5859
<td>{{.Type}}</td>
5960
<td>{{.ExemplarType}}</td>
6061
<td>{{$sum := .NumberOfWorkers}}{{if lt $sum 0}}-{{else}}{{$sum}}{{end}}</td>
62+
<td>{{$sum := .NumberInQueue}}{{if lt $sum 0}}-{{else}}{{$sum}}{{end}}</td>
6163
<td><a href="{{$.Link}}/queue/{{.QID}}" class="button">{{if lt $sum 0}}{{$.i18n.Tr "admin.monitor.queue.review"}}{{else}}{{$.i18n.Tr "admin.monitor.queue.review_add"}}{{end}}</a>
6264
</tr>
6365
{{end}}

templates/admin/queue.tmpl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
<th>{{.i18n.Tr "admin.monitor.queue.exemplar"}}</th>
1616
<th>{{.i18n.Tr "admin.monitor.queue.numberworkers"}}</th>
1717
<th>{{.i18n.Tr "admin.monitor.queue.maxnumberworkers"}}</th>
18+
<th>{{.i18n.Tr "admin.monitor.queue.numberinqueue"}}</th>
1819
</tr>
1920
</thead>
2021
<tbody>
@@ -24,6 +25,7 @@
2425
<td>{{.Queue.ExemplarType}}</td>
2526
<td>{{$sum := .Queue.NumberOfWorkers}}{{if lt $sum 0}}-{{else}}{{$sum}}{{end}}</td>
2627
<td>{{if lt $sum 0}}-{{else}}{{.Queue.MaxNumberOfWorkers}}{{end}}</td>
28+
<td>{{$sum := .Queue.NumberInQueue}}{{if lt $sum 0}}-{{else}}{{$sum}}{{end}}</td>
2729
</tr>
2830
</tbody>
2931
</table>

0 commit comments

Comments
 (0)