Skip to content

Commit

Permalink
fix merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
robpickerill committed Jun 8, 2024
1 parent ddd9f63 commit 731d45c
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 12 deletions.
11 changes: 2 additions & 9 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"`

MetricCollectionTime int64 `keda:"name=metricCollectionTime, order=triggerMetadata, optional, default=300"`
MetricStat string `keda:"name=metricStat, order=triggerMetadata, optional, default=Average"`
Expand Down Expand Up @@ -183,14 +184,6 @@ func checkMetricStatPeriod(period int64) error {
return nil
}

func checkMetricCollectionTime(metricCollectionTime, metricStatPeriod int64) error {
if metricCollectionTime < 0 || metricCollectionTime%metricStatPeriod != 0 {
return fmt.Errorf("metricCollectionTime must be greater than 0 and a multiple of metricStatPeriod(%d), %d is given", metricStatPeriod, metricCollectionTime)
}

return nil
}

func computeQueryWindow(current time.Time, metricPeriodSec, metricEndTimeOffsetSec, metricCollectionTimeSec int64) (startTime, endTime time.Time) {
endTime = current.Add(time.Second * -1 * time.Duration(metricEndTimeOffsetSec)).Truncate(time.Duration(metricPeriodSec) * time.Second)
startTime = endTime.Add(time.Second * -1 * time.Duration(metricCollectionTimeSec))
Expand Down Expand Up @@ -290,7 +283,7 @@ func (s *awsCloudwatchScaler) GetCloudwatchMetrics(ctx context.Context) (float64

// 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 {
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)
Expand Down
2 changes: 1 addition & 1 deletion pkg/scalers/aws_cloudwatch_scaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ func TestAWSCloudwatchScalerGetMetrics(t *testing.T) {
case testAWSCloudwatchNoValueMetric:
assert.NoError(t, err, "dont expect error when returning empty metric list from cloudwatch")
case testAWSCloudwatchEmptyValues:
if meta.ignoreNullValues {
if meta.IgnoreNullValues {
assert.NoError(t, err, "dont expect error when returning empty metric list from cloudwatch")
} else {
assert.Error(t, err, "expect error when returning empty metric list from cloudwatch, because ignoreNullValues is false")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func TestCloudWatchScalerWithIgnoreNullValuesFalse(t *testing.T) {

// check that the deployment did not scale, as the metric query is returning
// null values and the scaledobject is receiving errors, the deployment
// should not scale.
// should not scale, even though the minMetricValue is set to 1.
AssertReplicaCountNotChangeDuringTimePeriod(t, kc, deploymentName, testNamespace, minReplicaCount, 60)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"fmt"
"os"
"testing"
"time"

"github.com/joho/godotenv"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -162,7 +163,17 @@ func TestCloudWatchScalerWithMinMetricValue(t *testing.T) {
assert.True(t, WaitForDeploymentReplicaReadyCount(t, kc, deploymentName, testNamespace, minReplicaCount, 60, 1),
"replica count should be %d after 1 minute", minMetricValueReplicaCount)

// check that the deployment scaled up to the minMetricValueReplicaCount
// Allow a small amount of grace for stabilization, otherwise we will see the
// minMetricValue of 1 scale up the deployment from 0 to 1, as the deployment
// starts at a minReplicaCount of 0. The reason for this is to ensure that the
// scaler is still functioning when the metric value is null, as opposed to
// returning an error, and not scaling the workload at all.
time.Sleep(5 * time.Second)

// Then check that the deployment did not scale further, as the metric query
// is returning null values, the scaler should evaluate the metric value as
// the minMetricValue of 1, and not scale the deployment further beyond this
// point.
AssertReplicaCountNotChangeDuringTimePeriod(t, kc, deploymentName, testNamespace, minMetricValueReplicaCount, 60)
}

Expand Down
3 changes: 3 additions & 0 deletions tests/scalers/aws/helpers/cloudwatch/cloudwatch.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//go:build e2e
// +build e2e

package cloudwatch

import (
Expand Down

0 comments on commit 731d45c

Please sign in to comment.