diff --git a/pkg/autoscaler/aggregation/bucketing.go b/pkg/autoscaler/aggregation/bucketing.go index 623f801e2e91..9d5f31714d97 100644 --- a/pkg/autoscaler/aggregation/bucketing.go +++ b/pkg/autoscaler/aggregation/bucketing.go @@ -52,14 +52,6 @@ func (t *TimedFloat64Buckets) Record(time time.Time, name string, value float64) bucket.Record(name, value) } -// Size returns the number of buckets stored. -func (t *TimedFloat64Buckets) Size() int { - t.bucketsMutex.RLock() - defer t.bucketsMutex.RUnlock() - - return len(t.buckets) -} - // ForEachBucket calls the given Accumulator function for each bucket. func (t *TimedFloat64Buckets) ForEachBucket(accs ...Accumulator) { t.bucketsMutex.RLock() diff --git a/pkg/autoscaler/aggregation/bucketing_test.go b/pkg/autoscaler/aggregation/bucketing_test.go index c0223d66a479..fbf65b5634e7 100644 --- a/pkg/autoscaler/aggregation/bucketing_test.go +++ b/pkg/autoscaler/aggregation/bucketing_test.go @@ -85,8 +85,8 @@ func TestTimedFloat64Buckets(t *testing.T) { if !cmp.Equal(tt.want, got) { t.Errorf("Unexpected values (-want +got): %v", cmp.Diff(tt.want, got)) } - if got := buckets.Size(); len(tt.want) == 0 && got != 0 { - t.Errorf("Size() = %d, want 0", got) + if got := len(buckets.buckets); len(tt.want) == 0 && got != 0 { + t.Errorf("len(buckets) = %d, want 0", got) } }) } diff --git a/pkg/autoscaler/collector_test.go b/pkg/autoscaler/collector_test.go index 196a79e61894..bf86977b7645 100644 --- a/pkg/autoscaler/collector_test.go +++ b/pkg/autoscaler/collector_test.go @@ -118,11 +118,13 @@ func TestMetricCollectorScraper(t *testing.T) { now := time.Now() metricKey := NewMetricKey(defaultNamespace, defaultName) + want := 10.0 stat := &StatMessage{ Key: metricKey, Stat: Stat{ - Time: &now, - PodName: "testPod", + Time: &now, + PodName: "testPod", + AverageConcurrentRequests: 10.0, }, } scraper := testScraper(func() (*StatMessage, error) { @@ -133,13 +135,14 @@ func TestMetricCollectorScraper(t *testing.T) { coll := NewMetricCollector(factory, logger) coll.Create(ctx, defaultMetric) - var got int + // stable concurrency should eventually be equal to the stat. + var got float64 wait.PollImmediate(10*time.Millisecond, 1*time.Second, func() (bool, error) { - got = coll.collections[metricKey].buckets.Size() - return got > 0, nil + got, _, _ = coll.StableAndPanicConcurrency(metricKey) + return got == want, nil }) - if got < 1 { - t.Errorf("buckets.Size() = %v, want > 0", got) + if got != want { + t.Errorf("StableAndPanicConcurrency() = %v, want %v", got, want) } coll.Delete(ctx, defaultNamespace, defaultName) @@ -162,7 +165,7 @@ func TestMetricCollectorRecord(t *testing.T) { Time: &now, PodName: "testPod", AverageConcurrentRequests: want + 10, - AverageProxiedConcurrentRequests: 10, // this should be subtracted from the above + AverageProxiedConcurrentRequests: 10, // this should be subtracted from the above. } scraper := testScraper(func() (*StatMessage, error) { return nil, nil @@ -173,10 +176,6 @@ func TestMetricCollectorRecord(t *testing.T) { coll.Create(ctx, defaultMetric) coll.Record(metricKey, stat) - if got, want := coll.collections[metricKey].buckets.Size(), 1; got != want { - t.Errorf("buckets.Size() = %d, want %d", got, want) - } - if stable, panic, _ := coll.StableAndPanicConcurrency(metricKey); stable != panic && stable != want { t.Errorf("StableAndPanicConcurrency() = %v, %v; want %v (for both)", stable, panic, want) }