Skip to content

Commit

Permalink
Don't call Azure queue GetProperties API unnecessarily (#2613)
Browse files Browse the repository at this point in the history
  • Loading branch information
RamCohen committed Feb 14, 2022
1 parent 130bc93 commit 85dd397
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@

### Improvements

- Improve e2e tests reliability ([#2580](https://github.com/kedacore/keda/issues/2580))
- **Azure Queue:** Don't call Azure queue GetProperties API unnecessarily ([#2613](https://github.com/kedacore/keda/pull/2613))

### Breaking Changes

- TODO ([#XXX](https://github.com/kedacore/keda/issue/XXX))

### Other

- TODO ([#XXX](https://github.com/kedacore/keda/issue/XXX))
- **General:** Improve e2e tests reliability ([#2580](https://github.com/kedacore/keda/issues/2580))

## v.2.6.1

Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<Scaler Name>: ` as a prefix and sort them alphabetically
Expand Down
21 changes: 13 additions & 8 deletions pkg/scalers/azure/azure_queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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) {
Expand Down

0 comments on commit 85dd397

Please sign in to comment.