From 68b6ca8d70950cb337312b5efdb7056c861af9fb Mon Sep 17 00:00:00 2001 From: Zbynek Roubalik Date: Wed, 6 Nov 2024 16:42:50 +0100 Subject: [PATCH] AWS CloudWatch - properly parse multiple values of `dimensionName` & `dimensionValue` lists (#6313) --- CHANGELOG.md | 1 + pkg/scalers/aws_cloudwatch_scaler.go | 4 +- pkg/scalers/aws_cloudwatch_scaler_test.go | 48 +++++++++++++++++++++++ 3 files changed, 51 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index eef43573d9c..aef9680a3ab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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)) diff --git a/pkg/scalers/aws_cloudwatch_scaler.go b/pkg/scalers/aws_cloudwatch_scaler.go index a07db246f80..72a8a38c638 100644 --- a/pkg/scalers/aws_cloudwatch_scaler.go +++ b/pkg/scalers/aws_cloudwatch_scaler.go @@ -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"` diff --git a/pkg/scalers/aws_cloudwatch_scaler_test.go b/pkg/scalers/aws_cloudwatch_scaler_test.go index da6e85fc2c7..88145246574 100644 --- a/pkg/scalers/aws_cloudwatch_scaler_test.go +++ b/pkg/scalers/aws_cloudwatch_scaler_test.go @@ -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{ @@ -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()