Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle no metrics found for AWS Cloudwatch #2345

Merged
merged 4 commits into from
Nov 25, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
zroubalik marked this conversation as resolved.
Show resolved Hide resolved

### Improvements

Expand Down
3 changes: 2 additions & 1 deletion pkg/scalers/aws_cloudwatch_scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 18 additions & 2 deletions pkg/scalers/aws_cloudwatch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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")
JorTurFer marked this conversation as resolved.
Show resolved Hide resolved
default:
assert.EqualValues(t, int64(10.0), value[0].Value.Value())
}
Expand Down