Skip to content

Commit d18575f

Browse files
author
Yue Fei
committed
Use approximate queue length
Signed-off-by: Yue Fei <[email protected]>
1 parent f4bee67 commit d18575f

File tree

1 file changed

+1
-25
lines changed

1 file changed

+1
-25
lines changed

pkg/scalers/azure/azure_queue.go

+1-25
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,7 @@ import (
2525
"github.com/kedacore/keda/v2/pkg/util"
2626
)
2727

28-
const (
29-
maxPeekMessages int32 = 32
30-
)
31-
32-
// GetAzureQueueLength returns the length of a queue in int
28+
// 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
3329
func GetAzureQueueLength(ctx context.Context, httpClient util.HTTPDoer, podIdentity kedav1alpha1.AuthPodIdentity, connectionString, queueName, accountName, endpointSuffix string) (int64, error) {
3430
credential, endpoint, err := ParseAzureStorageQueueConnection(ctx, httpClient, podIdentity, connectionString, accountName, endpointSuffix)
3531
if err != nil {
@@ -40,30 +36,10 @@ func GetAzureQueueLength(ctx context.Context, httpClient util.HTTPDoer, podIdent
4036
serviceURL := azqueue.NewServiceURL(*endpoint, p)
4137
queueURL := serviceURL.NewQueueURL(queueName)
4238

43-
visibleMessageCount, err := getVisibleCount(ctx, &queueURL, maxPeekMessages)
44-
if err != nil {
45-
return -1, err
46-
}
47-
48-
// Queue has less messages than we allowed to peek for, so no need to get the approximation
49-
if visibleMessageCount < int64(maxPeekMessages) {
50-
return visibleMessageCount, nil
51-
}
52-
5339
props, err := queueURL.GetProperties(ctx)
5440
if err != nil {
5541
return -1, err
5642
}
5743

5844
return int64(props.ApproximateMessagesCount()), nil
5945
}
60-
61-
func getVisibleCount(ctx context.Context, queueURL *azqueue.QueueURL, maxCount int32) (int64, error) {
62-
messagesURL := queueURL.NewMessagesURL()
63-
queue, err := messagesURL.Peek(ctx, maxCount)
64-
if err != nil {
65-
return 0, err
66-
}
67-
num := queue.NumMessages()
68-
return int64(num), nil
69-
}

0 commit comments

Comments
 (0)