From 8b9fbb22a87df8bb13402731c47811625d0315cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Th=C3=B6mmes?= Date: Wed, 8 May 2019 08:09:53 +0200 Subject: [PATCH] Add special case for 'no data available ' error --- pkg/autoscaler/autoscaler.go | 6 +++++- pkg/autoscaler/collector.go | 7 ++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/pkg/autoscaler/autoscaler.go b/pkg/autoscaler/autoscaler.go index 3682288c44cd..9780bb0722a8 100644 --- a/pkg/autoscaler/autoscaler.go +++ b/pkg/autoscaler/autoscaler.go @@ -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 } diff --git a/pkg/autoscaler/collector.go b/pkg/autoscaler/collector.go index e3aac3037953..d31eb6287b32 100644 --- a/pkg/autoscaler/collector.go +++ b/pkg/autoscaler/collector.go @@ -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 { @@ -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{}