Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use approximate queue length for azure queue scaler #4003

Merged
merged 6 commits into from
Feb 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ Here is an overview of all new **experimental** features:

- **General**: Fix regression in fallback mechanism ([#4249](https://github.com/kedacore/keda/issues/4249))
- **General**: Prevent a panic that might occur while refreshing a scaler cache ([#4092](https://github.com/kedacore/keda/issues/4092))
- **Azure Queue Scaler**: Fix azure queue length ([#4002](https://github.com/kedacore/keda/issues/4002))
- **Azure Service Bus Scaler:** Use correct auth flows with pod identity ([#4026](https://github.com/kedacore/keda/issues/4026)|[#4123](https://github.com/kedacore/keda/issues/4123))
- **Azure Service Bus Scaler:**: Improve way clients are created to reduce amount of ARM requests ([#4262](https://github.com/kedacore/keda/issues/4262))
- **Cassandra Scaler**: Checking whether the port information is entered in the ClusterIPAddres is done correctly. ([#4110](https://github.com/kedacore/keda/issues/4110))
Expand Down
26 changes: 1 addition & 25 deletions pkg/scalers/azure/azure_queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@ import (
"github.com/kedacore/keda/v2/pkg/util"
)

const (
maxPeekMessages int32 = 32
)

// GetAzureQueueLength returns the length of a queue in int
// GetAzureQueueLength returns the length of a queue in int, see https://learn.microsoft.com/en-us/azure/storage/queues/storage-dotnet-how-to-use-queues?tabs=dotnet#get-the-queue-length
func GetAzureQueueLength(ctx context.Context, httpClient util.HTTPDoer, podIdentity kedav1alpha1.AuthPodIdentity, connectionString, queueName, accountName, endpointSuffix string) (int64, error) {
credential, endpoint, err := ParseAzureStorageQueueConnection(ctx, httpClient, podIdentity, connectionString, accountName, endpointSuffix)
if err != nil {
Expand All @@ -40,30 +36,10 @@ func GetAzureQueueLength(ctx context.Context, httpClient util.HTTPDoer, podIdent
serviceURL := azqueue.NewServiceURL(*endpoint, p)
queueURL := serviceURL.NewQueueURL(queueName)

visibleMessageCount, err := getVisibleCount(ctx, &queueURL, maxPeekMessages)
if err != nil {
return -1, err
}

// Queue has less messages than we allowed to peek for, so no need to get the approximation
if visibleMessageCount < int64(maxPeekMessages) {
return visibleMessageCount, nil
}

props, err := queueURL.GetProperties(ctx)
if err != nil {
return -1, err
}

return int64(props.ApproximateMessagesCount()), nil
}

func getVisibleCount(ctx context.Context, queueURL *azqueue.QueueURL, maxCount int32) (int64, error) {
messagesURL := queueURL.NewMessagesURL()
queue, err := messagesURL.Peek(ctx, maxCount)
if err != nil {
return 0, err
}
num := queue.NumMessages()
return int64(num), nil
}