diff --git a/CHANGELOG.md b/CHANGELOG.md index 5e50a8f624d..811a30a3aa6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,6 +34,7 @@ - Artemis Scaler: parse out broker config parameters in case `restAPITemplate` is given ([#2104](https://github.com/kedacore/keda/pull/2104)) - AWS Cloudwatch Scaler: improve metric exporting logic ([#2243](https://github.com/kedacore/keda/pull/2243)) +- AWS Cloudwatch Scaler: return minimum value for the metric when cloudwatch returns empty list ([#2345](https://github.com/kedacore/keda/pull/2345)) - Azure Log Analytics Scaler: add support to provide the metric name([#2106](https://github.com/kedacore/keda/pull/2106)) - Azure Pipelines Scaler: improve logs ([#2297](https://github.com/kedacore/keda/pull/2297)) - Cron Scaler: improve validation in case start & end input is same ([#2032](https://github.com/kedacore/keda/pull/2032)) diff --git a/pkg/scalers/aws_cloudwatch_scaler.go b/pkg/scalers/aws_cloudwatch_scaler.go index 14be0d6bfd6..fb68e43cc86 100644 --- a/pkg/scalers/aws_cloudwatch_scaler.go +++ b/pkg/scalers/aws_cloudwatch_scaler.go @@ -367,7 +367,8 @@ func (c *awsCloudwatchScaler) GetCloudwatchMetrics() (float64, error) { if len(output.MetricDataResults) > 0 && len(output.MetricDataResults[0].Values) > 0 { metricValue = *output.MetricDataResults[0].Values[0] } else { - return -1, fmt.Errorf("metric data not received") + cloudwatchLog.Info("empty metric data received, returning minMetricValue") + metricValue = c.metadata.minMetricValue } return metricValue, nil diff --git a/pkg/scalers/aws_cloudwatch_test.go b/pkg/scalers/aws_cloudwatch_test.go index f416fe7c8ef..76883026897 100644 --- a/pkg/scalers/aws_cloudwatch_test.go +++ b/pkg/scalers/aws_cloudwatch_test.go @@ -360,7 +360,23 @@ var awsCloudwatchGetMetricTestData = []awsCloudwatchMetadata{ }, { namespace: "Custom", - metricsName: "Error", + metricsName: testAWSCloudwatchErrorMetric, + dimensionName: []string{"DIM"}, + dimensionValue: []string{"DIM_VALUE"}, + targetMetricValue: 100, + minMetricValue: 0, + metricCollectionTime: 60, + metricStat: "Average", + metricUnit: "", + metricStatPeriod: 60, + metricEndTimeOffset: 60, + awsRegion: "us-west-2", + awsAuthorization: awsAuthorizationMetadata{podIdentityOwner: false}, + scalerIndex: 0, + }, + { + namespace: "Custom", + metricsName: testAWSCloudwatchNoValueMetric, dimensionName: []string{"DIM"}, dimensionValue: []string{"DIM_VALUE"}, targetMetricValue: 100, @@ -436,7 +452,7 @@ func TestAWSCloudwatchScalerGetMetrics(t *testing.T) { case testAWSCloudwatchErrorMetric: assert.Error(t, err, "expect error because of cloudwatch api error") case testAWSCloudwatchNoValueMetric: - assert.Error(t, err, "expect error because of no data return from cloudwatch") + assert.NoError(t, err, "dont expect error when returning empty metric list from cloudwatch") default: assert.EqualValues(t, int64(10.0), value[0].Value.Value()) }