Skip to content

Commit

Permalink
Add special case for 'no data available
Browse files Browse the repository at this point in the history
' error
  • Loading branch information
markusthoemmes committed May 9, 2019
1 parent 2268d5b commit 8b9fbb2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
6 changes: 5 additions & 1 deletion pkg/autoscaler/autoscaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,11 @@ func (a *Autoscaler) Scale(ctx context.Context, now time.Time) (int32, bool) {
metricKey := NewMetricKey(a.namespace, a.revision)
observedStableConcurrency, observedPanicConcurrency, err := a.metricClient.StableAndPanicConcurrency(metricKey)
if err != nil {
logger.Errorw("Failed to obtain metrics", zap.Error(err))
if err == ErrNoData {
logger.Debug("No data to scale on yet")
} else {
logger.Errorw("Failed to obtain metrics", zap.Error(err))
}
return 0, false
}

Expand Down
7 changes: 6 additions & 1 deletion pkg/autoscaler/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ const (
bucketSize = 2 * time.Second
)

var (
// ErrNoData denotes that the collector could not calculate data.
ErrNoData = errors.New("no data available")
)

// Metric represents a resource to configure the metric collector with.
// +k8s:deepcopy-gen=true
type Metric struct {
Expand Down Expand Up @@ -280,7 +285,7 @@ func (c *collection) stableAndPanicConcurrency(now time.Time) (float64, float64,
c.buckets.RemoveOlderThan(now.Add(-spec.StableWindow))

if c.buckets.IsEmpty() {
return 0, 0, errors.New("no data available")
return 0, 0, ErrNoData
}

panicAverage := aggregation.Average{}
Expand Down

0 comments on commit 8b9fbb2

Please sign in to comment.