Skip to content

Commit

Permalink
Allow using simple queue names in aws sqs scaler (kedacore#2483)
Browse files Browse the repository at this point in the history
Signed-off-by: nicolaferraro <[email protected]>
Signed-off-by: Mark Rzasa <[email protected]>
  • Loading branch information
nicolaferraro authored and markrzasa committed Jan 27, 2022
1 parent cc70a32 commit 085c194
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 @@ -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

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 085c194

Please sign in to comment.