Skip to content

Commit

Permalink
Allow using simple queue names in aws sqs scaler
Browse files Browse the repository at this point in the history
Signed-off-by: nicolaferraro <ni.ferraro@gmail.com>
  • Loading branch information
nicolaferraro committed Jan 17, 2022
1 parent 633923a commit 181a079
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
- **External Scaler:** fix wrong calculation of retry backoff duration ([#2416](https://github.com/kedacore/keda/pull/2416))
- **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))
- **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

Expand Down
17 changes: 9 additions & 8 deletions pkg/scalers/aws_sqs_queue_scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 8 additions & 0 deletions pkg/scalers/aws_sqs_queue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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{
Expand Down

0 comments on commit 181a079

Please sign in to comment.