Skip to content

Commit

Permalink
AWS CloudWatch - properly parse multiple values of dimensionName & …
Browse files Browse the repository at this point in the history
…`dimensionValue` lists (#6313)
  • Loading branch information
zroubalik authored Nov 6, 2024
1 parent 4eb7149 commit 68b6ca8
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ Here is an overview of all new **experimental** features:
### Fixes

- **General**: Scalers cache uses a mutex to prevent concurrent actions ([#6273](https://github.com/kedacore/keda/issues/6273))
- **AWS CloudWatch Scaler**: Properly parse multiple values of `dimensionName` & `dimensionValue` lists ([#6236](https://github.com/kedacore/keda/issues/6236))
- **AWS Secret Manager**: Pod identity overrides are honored ([#6195](https://github.com/kedacore/keda/issues/6195))
- **AWS SQS Scaler**: Improve error handling for SQS queue metrics ([#6178](https://github.com/kedacore/keda/issues/6178))
- **Azure Event Hub Scaler**: Checkpointer errors are correctly handled ([#6084](https://github.com/kedacore/keda/issues/6084))
Expand Down
4 changes: 2 additions & 2 deletions pkg/scalers/aws_cloudwatch_scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ type awsCloudwatchMetadata struct {
triggerIndex int
Namespace string `keda:"name=namespace, order=triggerMetadata, optional"`
MetricsName string `keda:"name=metricName, order=triggerMetadata, optional"`
DimensionName []string `keda:"name=dimensionName, order=triggerMetadata, optional"`
DimensionValue []string `keda:"name=dimensionValue, order=triggerMetadata, optional"`
DimensionName []string `keda:"name=dimensionName, order=triggerMetadata, optional, separator=;"`
DimensionValue []string `keda:"name=dimensionValue, order=triggerMetadata, optional, separator=;"`
Expression string `keda:"name=expression, order=triggerMetadata, optional"`

TargetMetricValue float64 `keda:"name=targetMetricValue, order=triggerMetadata"`
Expand Down
48 changes: 48 additions & 0 deletions pkg/scalers/aws_cloudwatch_scaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,22 @@ var testAWSCloudwatchMetadata = []parseAWSCloudwatchMetadataTestData{
testAWSAuthentication, true,
"unsupported value for ignoreNullValues",
},
// test case for multiple dimensions with valid separator
{
map[string]string{
"namespace": "AWS/SQS",
"dimensionName": "QueueName;Region",
"dimensionValue": "queue1;us-west-2",
"metricName": "ApproximateNumberOfMessagesVisible",
"targetMetricValue": "5",
"minMetricValue": "1",
"metricStat": "Average",
"awsRegion": "us-west-2",
},
testAWSAuthentication,
false,
"Multiple dimensions with valid separator",
},
}

var awsCloudwatchMetricIdentifiers = []awsCloudwatchMetricIdentifier{
Expand Down Expand Up @@ -629,6 +645,38 @@ func TestCloudwatchParseMetadata(t *testing.T) {
}
}

func TestAWSCloudwatchScalerMultipleDimensions(t *testing.T) {
meta := map[string]string{
"namespace": "AWS/SQS",
"dimensionName": "QueueName;Region",
"dimensionValue": "queue1;us-west-2",
"metricName": "ApproximateNumberOfMessagesVisible",
"targetMetricValue": "5",
"minMetricValue": "1",
"metricStat": "Average",
"awsRegion": "us-west-2",
}

config := &scalersconfig.ScalerConfig{
TriggerMetadata: meta,
ResolvedEnv: testAWSCloudwatchResolvedEnv,
AuthParams: testAWSAuthentication,
}

awsMeta, err := parseAwsCloudwatchMetadata(config)
if err != nil {
t.Fatalf("Expected no error, got %v", err)
}

if assert.Equal(t, 2, len(awsMeta.DimensionName), "Expected two dimension names") &&
assert.Equal(t, 2, len(awsMeta.DimensionValue), "Expected two dimension values") {
assert.Equal(t, "QueueName", awsMeta.DimensionName[0], "First dimension name should be QueueName")
assert.Equal(t, "Region", awsMeta.DimensionName[1], "Second dimension name should be Region")
assert.Equal(t, "queue1", awsMeta.DimensionValue[0], "First dimension value should be queue1")
assert.Equal(t, "us-west-2", awsMeta.DimensionValue[1], "Second dimension value should be us-west-2")
}
}

func TestAWSCloudwatchGetMetricSpecForScaling(t *testing.T) {
for _, testData := range awsCloudwatchMetricIdentifiers {
ctx := context.Background()
Expand Down

0 comments on commit 68b6ca8

Please sign in to comment.