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

add ignoreNullValues for AWS CloudWatch Scaler #5635

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
53ea3fd
add errorWhenMetricValueEmpty
robpickerill Mar 28, 2024
4174e93
fix golangci-lint
robpickerill Mar 28, 2024
8e41311
improve error message for empty results
robpickerill Mar 29, 2024
b0d4e84
add error when empty metric values to changelog
robpickerill Mar 29, 2024
7a5f617
rename errorWhenMetricValuesEmpty -> errorWhenNullValues
robpickerill Mar 31, 2024
96a2254
use getParameterFromConfigV2 to read config for errorWhenNullValues
robpickerill Mar 31, 2024
476b4e5
Merge branch 'main' into cloudwatch-error-when-empty-metrics
robpickerill Mar 31, 2024
0b61f97
add e2e for error state for cw, and improve e2e for min values for cw
robpickerill Apr 3, 2024
c6dc524
remove erroneous print statement
robpickerill Apr 4, 2024
0dc9b77
remove unused vars
robpickerill Apr 4, 2024
1f70736
rename errorWhenMetricValuesEmpty -> ignoreNullValues
robpickerill Apr 11, 2024
185db21
move towards shared package for e2e aws
robpickerill Apr 13, 2024
9f5bbf5
minMetricValue optionality based on ignoreNullValues
robpickerill Apr 14, 2024
97f47a0
fail fast
robpickerill Apr 26, 2024
9d0ce60
Update tests/scalers/aws/aws_cloudwatch_ignore_null_values_false/aws_…
robpickerill Apr 26, 2024
a8959f2
Apply suggestions from code review
robpickerill Apr 26, 2024
702817f
fail fast
robpickerill Apr 26, 2024
2862e9c
fix broken new line
robpickerill Apr 26, 2024
f390bc4
Merge branch 'main' into cloudwatch-error-when-empty-metrics
robpickerill Apr 26, 2024
c684676
fix broken new lines
robpickerill Apr 26, 2024
5aceb72
assert no scaling changes in e2e, and set false for required in minMe…
robpickerill May 4, 2024
96b4097
Merge branch 'main' into cloudwatch-error-when-empty-metrics
robpickerill May 20, 2024
9374c26
fix ci checks
robpickerill May 21, 2024
1898924
Update tests/scalers/aws/aws_cloudwatch_min_metric_value/aws_cloudwat…
robpickerill May 21, 2024
a97992b
Merge branch 'main' into cloudwatch-error-when-empty-metrics
robpickerill May 28, 2024
943f929
Merge branch 'kedacore:main' into cloudwatch-error-when-empty-metrics
robpickerill May 31, 2024
ddd9f63
Merge branch 'main' into cloudwatch-error-when-empty-metrics
robpickerill Jun 8, 2024
2e76a9b
fix merge conflicts
robpickerill Jun 8, 2024
43a2c3f
fix e2e package names
robpickerill Jun 10, 2024
a241593
Merge branch 'main' into cloudwatch-error-when-empty-metrics
robpickerill Aug 16, 2024
8e436c3
Merge branch 'main' into cloudwatch-error-when-empty-metrics
robpickerill Aug 20, 2024
d55be16
Merge branch 'main' into cloudwatch-error-when-empty-metrics
robpickerill Aug 20, 2024
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
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ Here is an overview of all new **experimental** features:

### Improvements

- TODO ([#XXX](https://github.com/kedacore/keda/issues/XXX))
- **AWS CloudWatch Scaler**: Add support for ignoreNullValues ([#5352](https://github.com/kedacore/keda/issues/5352))
- **GCP Scalers**: Added custom time horizon in GCP scalers ([#5778](https://github.com/kedacore/keda/issues/5778))
- **GitHub Scaler**: Fixed pagination, fetching repository list ([#5738](https://github.com/kedacore/keda/issues/5738))
- **Kafka**: Fix logic to scale to zero on invalid offset even with earliest offsetResetPolicy ([#5689](https://github.com/kedacore/keda/issues/5689))

### Fixes

Expand Down
14 changes: 11 additions & 3 deletions pkg/scalers/aws_cloudwatch_scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type awsCloudwatchMetadata struct {
TargetMetricValue float64 `keda:"name=targetMetricValue, order=triggerMetadata"`
ActivationTargetMetricValue float64 `keda:"name=activationTargetMetricValue, order=triggerMetadata, optional"`
MinMetricValue float64 `keda:"name=minMetricValue, order=triggerMetadata"`
IgnoreNullValues bool `keda:"name=ignoreNullValues, order=triggerMetadata, optional, default=true"`
JorTurFer marked this conversation as resolved.
Show resolved Hide resolved

MetricCollectionTime int64 `keda:"name=metricCollectionTime, order=triggerMetadata, optional, default=300"`
MetricStat string `keda:"name=metricStat, order=triggerMetadata, optional, default=Average"`
Expand Down Expand Up @@ -191,7 +192,6 @@ func computeQueryWindow(current time.Time, metricPeriodSec, metricEndTimeOffsetS

func (s *awsCloudwatchScaler) GetMetricsAndActivity(ctx context.Context, metricName string) ([]external_metrics.ExternalMetricValue, bool, error) {
metricValue, err := s.GetCloudwatchMetrics(ctx)

if err != nil {
s.logger.Error(err, "Error getting metric value")
return []external_metrics.ExternalMetricValue{}, false, err
Expand Down Expand Up @@ -274,20 +274,28 @@ func (s *awsCloudwatchScaler) GetCloudwatchMetrics(ctx context.Context) (float64
}

output, err := s.cwClient.GetMetricData(ctx, &input)

if err != nil {
s.logger.Error(err, "Failed to get output")
return -1, err
}

s.logger.V(1).Info("Received Metric Data", "data", output)

// If no metric data results or the first result has no values, and ignoreNullValues is false,
// the scaler should return an error to prevent any further scaling actions.
if len(output.MetricDataResults) > 0 && len(output.MetricDataResults[0].Values) == 0 && !s.metadata.IgnoreNullValues {
emptyMetricsErrMsg := "empty metric data received, ignoreNullValues is false, returning error"
s.logger.Error(nil, emptyMetricsErrMsg)
return -1, fmt.Errorf(emptyMetricsErrMsg)
}

var metricValue float64

if len(output.MetricDataResults) > 0 && len(output.MetricDataResults[0].Values) > 0 {
metricValue = output.MetricDataResults[0].Values[0]
} else {
s.logger.Info("empty metric data received, returning minMetricValue")
metricValue = s.metadata.MinMetricValue
}

return metricValue, nil
}
Loading
Loading