From 7e2c6a07398d888d5f650d6e78771a6ac91bd8ab Mon Sep 17 00:00:00 2001 From: Ram Cohen Date: Wed, 9 Feb 2022 15:33:01 +0200 Subject: [PATCH 1/4] Don't call Azure queue GetProperties API unnecessarily This PR reorders the logic of getting an Azure queue size in a way that skips the call to get the queue properties (for getting the ApproximateMessagesCount) if the queue has less than 32 messages. Signed-off-by: Ram Cohen --- pkg/scalers/azure/azure_queue.go | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/pkg/scalers/azure/azure_queue.go b/pkg/scalers/azure/azure_queue.go index df549648165..62b5ca32224 100644 --- a/pkg/scalers/azure/azure_queue.go +++ b/pkg/scalers/azure/azure_queue.go @@ -25,6 +25,10 @@ import ( "github.com/kedacore/keda/v2/pkg/util" ) +const ( + maxPeekMessages int32 = 32 +) + // GetAzureQueueLength returns the length of a queue in int func GetAzureQueueLength(ctx context.Context, httpClient util.HTTPDoer, podIdentity kedav1alpha1.PodIdentityProvider, connectionString, queueName, accountName, endpointSuffix string) (int32, error) { credential, endpoint, err := ParseAzureStorageQueueConnection(ctx, httpClient, podIdentity, connectionString, accountName, endpointSuffix) @@ -35,22 +39,23 @@ func GetAzureQueueLength(ctx context.Context, httpClient util.HTTPDoer, podIdent p := azqueue.NewPipeline(credential, azqueue.PipelineOptions{}) serviceURL := azqueue.NewServiceURL(*endpoint, p) queueURL := serviceURL.NewQueueURL(queueName) - props, err := queueURL.GetProperties(ctx) + + visibleMessageCount, err := getVisibleCount(ctx, &queueURL, maxPeekMessages) if err != nil { return -1, err } - visibleMessageCount, err := getVisibleCount(ctx, &queueURL, 32) - 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 < maxPeekMessages { + return visibleMessageCount, nil } - approximateMessageCount := props.ApproximateMessagesCount() - if visibleMessageCount == 32 { - return approximateMessageCount, nil + props, err := queueURL.GetProperties(ctx) + if err != nil { + return -1, err } - return visibleMessageCount, nil + return props.ApproximateMessagesCount(), nil } func getVisibleCount(ctx context.Context, queueURL *azqueue.QueueURL, maxCount int32) (int32, error) { From 23e8abb41af56bc00dd25c4997aeeb2054068158 Mon Sep 17 00:00:00 2001 From: Ram Cohen Date: Thu, 10 Feb 2022 23:10:01 +0200 Subject: [PATCH 2/4] Update changelog Signed-off-by: Ram Cohen --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d64116aca1e..18a7d5e25aa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,6 +34,7 @@ ### Improvements - **General:** Fix generation of metric names if any of ScaledObject's triggers is unavailable ([#2592](https://github.com/kedacore/keda/issues/2592)) +- **Azure Queue:** Don't call Azure queue GetProperties API unnecessarily ([#2613](https://github.com/kedacore/keda/pull/2613)) ### Breaking Changes From 06139e1262e1deba2d274f8956c5aafb373cab8f Mon Sep 17 00:00:00 2001 From: Ram Cohen Date: Thu, 10 Feb 2022 23:12:08 +0200 Subject: [PATCH 3/4] Fix typo in doc Signed-off-by: Ram Cohen --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index fefe607e984..5eb028c46ca 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -48,7 +48,7 @@ check the [test documentation](./tests/README.md). Those tests are run nightly o ## Changelog -Every change should bve added to our changelog under `Unreleased` which is located in `CHANGELOG.md`. This helps us keep track of all changes in a given release. +Every change should be added to our changelog under `Unreleased` which is located in `CHANGELOG.md`. This helps us keep track of all changes in a given release. Here are some guidelines to follow: - Always use `General: ` or `: ` as a prefix and sort them alphabetically From afe765666687be2fc1f6f9a5e7aa1bcb5597e721 Mon Sep 17 00:00:00 2001 From: Ram Cohen Date: Mon, 14 Feb 2022 09:11:10 +0200 Subject: [PATCH 4/4] Remove duplicate changelog line Signed-off-by: Ram Cohen --- CHANGELOG.md | 1 - 1 file changed, 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 472333f1a1c..11a0f2964c2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,7 +34,6 @@ ### Improvements -- **General:** Fix generation of metric names if any of ScaledObject's triggers is unavailable ([#2592](https://github.com/kedacore/keda/issues/2592)) - **Azure Queue:** Don't call Azure queue GetProperties API unnecessarily ([#2613](https://github.com/kedacore/keda/pull/2613)) ### Breaking Changes