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

AWS CloudWatch - properly parse multiple values of dimensionName & dimensionValue lists #6313

Merged
merged 2 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -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
Loading