From fd33356ca88713702a55f19302ffb4d6af98a940 Mon Sep 17 00:00:00 2001 From: Nicola Ferraro Date: Mon, 24 Jan 2022 14:51:38 +0100 Subject: [PATCH] Allow using simple queue names in aws sqs scaler (#2483) Signed-off-by: nicolaferraro Signed-off-by: Mark Rzasa --- CHANGELOG.md | 1 + pkg/scalers/aws_sqs_queue_scaler.go | 17 +++++++++-------- pkg/scalers/aws_sqs_queue_test.go | 8 ++++++++ 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b93645feace..251a5beb530 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -43,6 +43,7 @@ - **Kafka Scaler:** allow flag `topic` to be optional, where lag of all topics within the consumer group will be used for scaling ([#2409](https://github.com/kedacore/keda/pull/2409)) - **General:** fail fast on `buildScalers` when not able to resolve a secret that a deployment is relying on ([#2394](https://github.com/kedacore/keda/pull/2394)) - **CPU Scaler:** Adding e2e test for the cpu scaler ([#2441](https://github.com/kedacore/keda/pull/2441)) +- **AWS SQS Scaler**: allow using simple queue name instead of URL ([#2457](https://github.com/kedacore/keda/pull/2457)) ### Breaking Changes diff --git a/pkg/scalers/aws_sqs_queue_scaler.go b/pkg/scalers/aws_sqs_queue_scaler.go index 7a0c7517a6a..df24d604978 100644 --- a/pkg/scalers/aws_sqs_queue_scaler.go +++ b/pkg/scalers/aws_sqs_queue_scaler.go @@ -85,17 +85,18 @@ func parseAwsSqsQueueMetadata(config *ScalerConfig) (*awsSqsQueueMetadata, error queueURL, err := url.ParseRequestURI(meta.queueURL) if err != nil { - return nil, fmt.Errorf("queueURL is not a valid URL") - } + // queueURL is not a valid URL, using it as queueName + meta.queueName = meta.queueURL + } else { + queueURLPath := queueURL.Path + queueURLPathParts := strings.Split(queueURLPath, "/") + if len(queueURLPathParts) != 3 || len(queueURLPathParts[2]) == 0 { + return nil, fmt.Errorf("cannot get queueName from queueURL") + } - queueURLPath := queueURL.Path - queueURLPathParts := strings.Split(queueURLPath, "/") - if len(queueURLPathParts) != 3 || len(queueURLPathParts[2]) == 0 { - return nil, fmt.Errorf("cannot get queueName from queueURL") + meta.queueName = queueURLPathParts[2] } - meta.queueName = queueURLPathParts[2] - if val, ok := config.TriggerMetadata["awsRegion"]; ok && val != "" { meta.awsRegion = val } else { diff --git a/pkg/scalers/aws_sqs_queue_test.go b/pkg/scalers/aws_sqs_queue_test.go index 166726a29cb..550b816187d 100644 --- a/pkg/scalers/aws_sqs_queue_test.go +++ b/pkg/scalers/aws_sqs_queue_test.go @@ -20,6 +20,7 @@ const ( testAWSSQSProperQueueURL = "https://sqs.eu-west-1.amazonaws.com/account_id/DeleteArtifactQ" testAWSSQSImproperQueueURL1 = "https://sqs.eu-west-1.amazonaws.com/account_id" testAWSSQSImproperQueueURL2 = "https://sqs.eu-west-1.amazonaws.com" + testAWSSimpleQueueURL = "my-queue" testAWSSQSErrorQueueURL = "https://sqs.eu-west-1.amazonaws.com/account_id/Error" testAWSSQSBadDataQueueURL = "https://sqs.eu-west-1.amazonaws.com/account_id/BadData" @@ -165,6 +166,13 @@ var testAWSSQSMetadata = []parseAWSSQSMetadataTestData{ }, false, "with AWS Role assigned on KEDA operator itself"}, + {map[string]string{ + "queueURL": testAWSSimpleQueueURL, + "queueLength": "1", + "awsRegion": "eu-west-1"}, + testAWSSQSAuthentication, + false, + "properly formed queue and region"}, } var awsSQSMetricIdentifiers = []awsSQSMetricIdentifier{