Skip to content

Commit

Permalink
Remove 'Size' function.
Browse files Browse the repository at this point in the history
  • Loading branch information
markusthoemmes committed May 7, 2019
1 parent ddd01b2 commit 3eb7757
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 22 deletions.
8 changes: 0 additions & 8 deletions pkg/autoscaler/aggregation/bucketing.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions pkg/autoscaler/aggregation/bucketing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
})
}
Expand Down
23 changes: 11 additions & 12 deletions pkg/autoscaler/collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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)
}
Expand Down

0 comments on commit 3eb7757

Please sign in to comment.