From 578962d934df19cb2cb7ec0536dcb76f53951e68 Mon Sep 17 00:00:00 2001 From: Daniel Smith Date: Sat, 10 Nov 2018 18:46:43 -0800 Subject: [PATCH] fixup! Test workqueue metrics change units to seconds --- pkg/util/workqueue/prometheus/prometheus.go | 9 ++++--- .../client-go/util/workqueue/metrics.go | 26 ++++++++++--------- .../client-go/util/workqueue/metrics_test.go | 4 +-- 3 files changed, 22 insertions(+), 17 deletions(-) diff --git a/pkg/util/workqueue/prometheus/prometheus.go b/pkg/util/workqueue/prometheus/prometheus.go index 460c3d4dff..7c1f270f6f 100644 --- a/pkg/util/workqueue/prometheus/prometheus.go +++ b/pkg/util/workqueue/prometheus/prometheus.go @@ -71,11 +71,14 @@ func (prometheusMetricsProvider) NewWorkDurationMetric(name string) workqueue.Su return workDuration } -func (prometheusMetricsProvider) NewUnfinishedWorkMicrosecondsMetric(name string) workqueue.SettableGaugeMetric { +func (prometheusMetricsProvider) NewUnfinishedWorkSecondsMetric(name string) workqueue.SettableGaugeMetric { unfinished := prometheus.NewGauge(prometheus.GaugeOpts{ Subsystem: name, - Name: "unfinished_work_microseconds", - Help: "How many microseconds of work has " + name + " done that is still in progress and hasn't yet been observed by work_duration.", + Name: "unfinished_work_seconds", + Help: "How many seconds of work " + name + " has done that " + + "is in progress and hasn't been observed by work_duration. Large " + + "values indicate stuck threads. One can deduce the number of stuck " + + "threads by observing the rate at which this increases.", }) prometheus.Register(unfinished) return unfinished diff --git a/staging/src/k8s.io/client-go/util/workqueue/metrics.go b/staging/src/k8s.io/client-go/util/workqueue/metrics.go index 43c0ab5e9e..51b5f2426d 100644 --- a/staging/src/k8s.io/client-go/util/workqueue/metrics.go +++ b/staging/src/k8s.io/client-go/util/workqueue/metrics.go @@ -80,7 +80,7 @@ type defaultQueueMetrics struct { processingStartTimes map[t]time.Time // how long have current threads been working? - unfinishedWorkMicroseconds SettableGaugeMetric + unfinishedWorkSeconds SettableGaugeMetric } func (m *defaultQueueMetrics) add(item t) { @@ -124,7 +124,9 @@ func (m *defaultQueueMetrics) updateUnfinishedWork() { for _, t := range m.processingStartTimes { total += m.sinceInMicroseconds(t) } - m.unfinishedWorkMicroseconds.Set(total) + // Convert to seconds; microseconds is unhelpfully granular for this. + total /= 1000000 + m.unfinishedWorkSeconds.Set(total) } type noMetrics struct{} @@ -161,7 +163,7 @@ type MetricsProvider interface { NewAddsMetric(name string) CounterMetric NewLatencyMetric(name string) SummaryMetric NewWorkDurationMetric(name string) SummaryMetric - NewUnfinishedWorkMicrosecondsMetric(name string) SettableGaugeMetric + NewUnfinishedWorkSecondsMetric(name string) SettableGaugeMetric NewRetriesMetric(name string) CounterMetric } @@ -183,7 +185,7 @@ func (_ noopMetricsProvider) NewWorkDurationMetric(name string) SummaryMetric { return noopMetric{} } -func (_ noopMetricsProvider) NewUnfinishedWorkMicrosecondsMetric(name string) SettableGaugeMetric { +func (_ noopMetricsProvider) NewUnfinishedWorkSecondsMetric(name string) SettableGaugeMetric { return noopMetric{} } @@ -213,14 +215,14 @@ func (f *queueMetricsFactory) newQueueMetrics(name string, clock clock.Clock) qu return noMetrics{} } return &defaultQueueMetrics{ - clock: clock, - depth: mp.NewDepthMetric(name), - adds: mp.NewAddsMetric(name), - latency: mp.NewLatencyMetric(name), - workDuration: mp.NewWorkDurationMetric(name), - unfinishedWorkMicroseconds: mp.NewUnfinishedWorkMicrosecondsMetric(name), - addTimes: map[t]time.Time{}, - processingStartTimes: map[t]time.Time{}, + clock: clock, + depth: mp.NewDepthMetric(name), + adds: mp.NewAddsMetric(name), + latency: mp.NewLatencyMetric(name), + workDuration: mp.NewWorkDurationMetric(name), + unfinishedWorkSeconds: mp.NewUnfinishedWorkSecondsMetric(name), + addTimes: map[t]time.Time{}, + processingStartTimes: map[t]time.Time{}, } } diff --git a/staging/src/k8s.io/client-go/util/workqueue/metrics_test.go b/staging/src/k8s.io/client-go/util/workqueue/metrics_test.go index 065e2c40b1..90b2cf25e7 100644 --- a/staging/src/k8s.io/client-go/util/workqueue/metrics_test.go +++ b/staging/src/k8s.io/client-go/util/workqueue/metrics_test.go @@ -113,7 +113,7 @@ func (m *testMetricsProvider) NewWorkDurationMetric(name string) SummaryMetric { return &m.duration } -func (m *testMetricsProvider) NewUnfinishedWorkMicrosecondsMetric(name string) SettableGaugeMetric { +func (m *testMetricsProvider) NewUnfinishedWorkSecondsMetric(name string) SettableGaugeMetric { return &m.unfinished } @@ -229,7 +229,7 @@ func TestMetrics(t *testing.T) { c.Step(time.Millisecond) <-ch mp.unfinished.notifyCh = nil - if e, a := 1000.0, mp.unfinished.gaugeValue(); e != a { + if e, a := .001, mp.unfinished.gaugeValue(); e != a { t.Errorf("expected %v, got %v", e, a) }