From 3bec0ca9047ffb99d81e0e3036a598b54949145b Mon Sep 17 00:00:00 2001 From: nicolaferraro Date: Fri, 14 Jan 2022 15:50:23 +0100 Subject: [PATCH] Allow using simple queue names in aws sqs scaler Signed-off-by: nicolaferraro --- 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 072f1d7b55d..617365aed38 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,7 @@ - Graphite Scaler: use the latest datapoint returned, not the earliest ([#2365](https://github.com/kedacore/keda/pull/2365)) - Kubernetes Workload Scaler: ignore terminated pods ([#2384](https://github.com/kedacore/keda/pull/2384)) +- AWS SQS Scaler: Allow using simple queue name instead of URL ([#2457](https://github.com/kedacore/keda/pull/2457)) - TODO ([#XXX](https://github.com/kedacore/keda/pull/XXX)) 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{