From 9e83e7e975dd5971e60e9768e06520aa5ebf9bf8 Mon Sep 17 00:00:00 2001 From: austin ce Date: Fri, 2 Dec 2022 14:08:11 -0500 Subject: [PATCH] Integrate new metrics provider option in test case --- .../client-go/util/workqueue/metrics_test.go | 112 ------------------ .../k8s.io/client-go/util/workqueue/queue.go | 1 - 2 files changed, 113 deletions(-) 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 a35be0359c0..6102345155f 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 @@ -171,118 +171,6 @@ func TestMetrics(t *testing.T) { mp := testMetricsProvider{} t0 := time.Unix(0, 0) c := testingclock.NewFakeClock(t0) - mf := queueMetricsFactory{metricsProvider: &mp} - m := mf.newQueueMetrics("test", c) - q := newQueue(c, m, time.Millisecond) - defer q.ShutDown() - for !c.HasWaiters() { - // Wait for the go routine to call NewTicker() - time.Sleep(time.Millisecond) - } - - q.Add("foo") - if e, a := 1.0, mp.adds.gaugeValue(); e != a { - t.Errorf("expected %v, got %v", e, a) - } - - if e, a := 1.0, mp.depth.gaugeValue(); e != a { - t.Errorf("expected %v, got %v", e, a) - } - - c.Step(50 * time.Microsecond) - - // Start processing - i, _ := q.Get() - if i != "foo" { - t.Errorf("Expected %v, got %v", "foo", i) - } - - if e, a := 5e-05, mp.latency.observationValue(); e != a { - t.Errorf("expected %v, got %v", e, a) - } - if e, a := 1, mp.latency.observationCount(); e != a { - t.Errorf("expected %v, got %v", e, a) - } - - // Add it back while processing; multiple adds of the same item are - // de-duped. - q.Add(i) - q.Add(i) - q.Add(i) - q.Add(i) - q.Add(i) - if e, a := 2.0, mp.adds.gaugeValue(); e != a { - t.Errorf("expected %v, got %v", e, a) - } - // One thing remains in the queue - if e, a := 1.0, mp.depth.gaugeValue(); e != a { - t.Errorf("expected %v, got %v", e, a) - } - - c.Step(25 * time.Microsecond) - - // Finish it up - q.Done(i) - - if e, a := 2.5e-05, mp.duration.observationValue(); e != a { - t.Errorf("expected %v, got %v", e, a) - } - if e, a := 1, mp.duration.observationCount(); e != a { - t.Errorf("expected %v, got %v", e, a) - } - - // One thing remains in the queue - if e, a := 1.0, mp.depth.gaugeValue(); e != a { - t.Errorf("expected %v, got %v", e, a) - } - - // It should be back on the queue - i, _ = q.Get() - if i != "foo" { - t.Errorf("Expected %v, got %v", "foo", i) - } - - if e, a := 2.5e-05, mp.latency.observationValue(); e != a { - t.Errorf("expected %v, got %v", e, a) - } - if e, a := 2, mp.latency.observationCount(); e != a { - t.Errorf("expected %v, got %v", e, a) - } - - // use a channel to ensure we don't look at the metric before it's - // been set. - ch := make(chan struct{}, 1) - longestCh := make(chan struct{}, 1) - mp.unfinished.notifyCh = ch - mp.longest.notifyCh = longestCh - c.Step(time.Millisecond) - <-ch - mp.unfinished.notifyCh = nil - if e, a := .001, mp.unfinished.gaugeValue(); e != a { - t.Errorf("expected %v, got %v", e, a) - } - <-longestCh - mp.longest.notifyCh = nil - if e, a := .001, mp.longest.gaugeValue(); e != a { - t.Errorf("expected %v, got %v", e, a) - } - - // Finish that one up - q.Done(i) - if e, a := .001, mp.duration.observationValue(); e != a { - t.Errorf("expected %v, got %v", e, a) - } - if e, a := 2, mp.duration.observationCount(); e != a { - t.Errorf("expected %v, got %v", e, a) - } -} - -func TestPerQueueMetrics(t *testing.T) { - // TODO(austince): refactor TestMetrics to make this test just another case - mp := testMetricsProvider{} - t0 := time.Unix(0, 0) - c := testingclock.NewFakeClock(t0) - q := newNamedQueueWithCustomClock(c, "test", time.Millisecond, WithMetricsProvider(&mp)) defer q.ShutDown() for !c.HasWaiters() { diff --git a/staging/src/k8s.io/client-go/util/workqueue/queue.go b/staging/src/k8s.io/client-go/util/workqueue/queue.go index 5c2890b3657..99853cfa672 100644 --- a/staging/src/k8s.io/client-go/util/workqueue/queue.go +++ b/staging/src/k8s.io/client-go/util/workqueue/queue.go @@ -44,7 +44,6 @@ func NewNamed(name string, opts ...QueueOption) *Type { // newNamedQueueWithCustomClock constructs a new named workqueue // with ability to inject real or fake clock for testing purposes -// TODO(austince): should WithUpdatePeriod be a QueueOption? Could this func then be public? func newNamedQueueWithCustomClock(clock clock.WithTicker, name string, updatePeriod time.Duration, opts ...QueueOption) *Type { config := NewConfig(opts...)