Test workqueue metrics

Kubernetes-commit: 5a8444ceec9e28e8a7dbf36bfd7cb55554c5b865
This commit is contained in:
Daniel Smith
2018-11-09 16:12:11 -08:00
committed by Kubernetes Publisher
parent 75d4dad922
commit 26f9385b8e
3 changed files with 241 additions and 31 deletions

View File

@@ -19,6 +19,8 @@ package workqueue
import (
"sync"
"time"
"k8s.io/apimachinery/pkg/util/clock"
)
type Interface interface {
@@ -36,22 +38,24 @@ func New() *Type {
}
func NewNamed(name string) *Type {
rc := clock.RealClock{}
return newQueue(
name,
newQueueMetrics(name),
rc,
globalMetricsFactory.newQueueMetrics(name, rc),
defaultUnfinishedWorkUpdatePeriod,
)
}
func newQueue(name string, metrics queueMetrics, updatePeriod time.Duration) *Type {
func newQueue(c clock.Clock, metrics queueMetrics, updatePeriod time.Duration) *Type {
t := &Type{
clock: c,
dirty: set{},
processing: set{},
cond: sync.NewCond(&sync.Mutex{}),
metrics: metrics,
unfinishedWorkUpdatePeriod: updatePeriod,
}
go t.updateUnfinishedWorkLook()
go t.updateUnfinishedWorkLoop()
return t
}
@@ -80,6 +84,7 @@ type Type struct {
metrics queueMetrics
unfinishedWorkUpdatePeriod time.Duration
clock clock.Clock
}
type empty struct{}
@@ -187,10 +192,10 @@ func (q *Type) ShuttingDown() bool {
return q.shuttingDown
}
func (q *Type) updateUnfinishedWorkLook() {
t := time.NewTicker(q.unfinishedWorkUpdatePeriod)
func (q *Type) updateUnfinishedWorkLoop() {
t := q.clock.NewTicker(q.unfinishedWorkUpdatePeriod)
defer t.Stop()
for range t.C {
for range t.C() {
if !func() bool {
q.cond.L.Lock()
defer q.cond.L.Unlock()