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

Don't call Azure queue GetProperties API unnecessarily #2613

Merged
merged 5 commits into from
Feb 14, 2022
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
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))
RamCohen marked this conversation as resolved.
Show resolved Hide resolved

## 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