From 253403e1a55172f42309dd2551b2aae0f9a7edae Mon Sep 17 00:00:00 2001 From: Althaf Mohamed Date: Thu, 25 Nov 2021 06:23:29 +0000 Subject: [PATCH 1/4] By making a contribution to this project, I certify that: (a) The contribution was created in whole or in part by me and I have the right to submit it under the open source license indicated in the file; or (b) The contribution is based upon previous work that, to the best of my knowledge, is covered under an appropriate open source license and I have the right under that license to submit that work with modifications, whether created in whole or in part by me, under the same open source license (unless I am permitted to submit under a different license), as indicated in the file; or (c) The contribution was provided directly to me by some other person who certified (a), (b) or (c) and I have not modified it. (d) I understand and agree that this project and the contribution are public and that a record of the contribution (including all personal information I submit with it, including my sign-off) is maintained indefinitely and may be redistributed consistent with this project or the open source license(s) involved. Signed-off-by: Althaf Mohamed --- pkg/scalers/aws_cloudwatch_scaler.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 From 3bd7e0aaa1e1d1632d264e53df7079ac759e90ff Mon Sep 17 00:00:00 2001 From: Althaf Mohamed Date: Thu, 25 Nov 2021 09:19:51 +0000 Subject: [PATCH 2/4] Adding changelog and modifying test case for no value response Signed-off-by: Althaf Mohamed --- CHANGELOG.md | 1 + pkg/scalers/aws_cloudwatch_test.go | 20 ++++++++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5e50a8f624d..0cd0845297c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,7 @@ - ScaledJob: introduce `RolloutStrategy` ([#2164](https://github.com/kedacore/keda/pull/2164)) - Add ScalersCache to reuse scalers unless they need changing ([#2187](https://github.com/kedacore/keda/pull/2187)) - Cache metric names provided by KEDA Metrics Server ([#2279](https://github.com/kedacore/keda/pull/2279)) +- Return minimum value for the metric and log, when cloudwatch returns empty list of metrics ([#2345](https://github.com/kedacore/keda/pull/2345)) ### Improvements diff --git a/pkg/scalers/aws_cloudwatch_test.go b/pkg/scalers/aws_cloudwatch_test.go index f416fe7c8ef..1733741e250 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()) } From fad430b1851c56771e2d6dc8372f4bcb7bcaf9e1 Mon Sep 17 00:00:00 2001 From: Althaf Mohamed Date: Thu, 25 Nov 2021 09:33:12 +0000 Subject: [PATCH 3/4] fixing lint issues Signed-off-by: Althaf Mohamed --- pkg/scalers/aws_cloudwatch_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/scalers/aws_cloudwatch_test.go b/pkg/scalers/aws_cloudwatch_test.go index 1733741e250..76883026897 100644 --- a/pkg/scalers/aws_cloudwatch_test.go +++ b/pkg/scalers/aws_cloudwatch_test.go @@ -452,7 +452,7 @@ func TestAWSCloudwatchScalerGetMetrics(t *testing.T) { case testAWSCloudwatchErrorMetric: assert.Error(t, err, "expect error because of cloudwatch api error") case testAWSCloudwatchNoValueMetric: - assert.NoError(t,err, "dont expect error when returning empty metric list 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()) } From 70d12563784a6cff029ad52b35a2839c58ec82e0 Mon Sep 17 00:00:00 2001 From: Althaf Mohamed Date: Thu, 25 Nov 2021 09:43:36 +0000 Subject: [PATCH 4/4] Moving change log entry under improvements Signed-off-by: Althaf Mohamed --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0cd0845297c..811a30a3aa6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,12 +29,12 @@ - ScaledJob: introduce `RolloutStrategy` ([#2164](https://github.com/kedacore/keda/pull/2164)) - Add ScalersCache to reuse scalers unless they need changing ([#2187](https://github.com/kedacore/keda/pull/2187)) - Cache metric names provided by KEDA Metrics Server ([#2279](https://github.com/kedacore/keda/pull/2279)) -- Return minimum value for the metric and log, when cloudwatch returns empty list of metrics ([#2345](https://github.com/kedacore/keda/pull/2345)) ### Improvements - 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))