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 14, 2022
1 parent 4a1e358 commit 3bec0ca
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 @@ -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))

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 3bec0ca

Please sign in to comment.