Skip to content

Commit

Permalink
Use constants for queue length strategy.
Browse files Browse the repository at this point in the history
Signed-off-by: Leonardo D'Ippolito <contact@leodip.com>
  • Loading branch information
leodip committed Jul 1, 2024
1 parent cb1190f commit e2421c0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 4 additions & 2 deletions pkg/scalers/azure/azure_queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ import (
)

const (
maxPeekMessages int32 = 32
maxPeekMessages int32 = 32
QueueLengthStrategyAll string = "all"
QueueLengthStrategyVisibleOnly string = "visibleonly"
)

// 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
Expand All @@ -41,7 +43,7 @@ func GetAzureQueueLength(ctx context.Context, podIdentity kedav1alpha1.AuthPodId
queueURL := serviceURL.NewQueueURL(queueName)

strategy := strings.ToLower(queueLengthStrategy)
if strategy == "visibleonly" {
if strategy == QueueLengthStrategyVisibleOnly {
visibleMessageCount, err := getVisibleCount(ctx, &queueURL, maxPeekMessages)
if err != nil {
return -1, err
Expand Down
4 changes: 2 additions & 2 deletions pkg/scalers/azure_queue_scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,13 @@ func parseAzureQueueMetadata(config *scalersconfig.ScalerConfig, logger logr.Log

if val, ok := config.TriggerMetadata["queueLengthStrategy"]; ok && val != "" {
strategy := strings.ToLower(val)
if strategy == "all" || strategy == "visibleonly" {
if strategy == azure.QueueLengthStrategyAll || strategy == azure.QueueLengthStrategyVisibleOnly {
meta.queueLengthStrategy = strategy
} else {
return nil, kedav1alpha1.AuthPodIdentity{}, fmt.Errorf("invalid queueLengthStrategy %s given", val)
}
} else {
meta.queueLengthStrategy = "all"
meta.queueLengthStrategy = azure.QueueLengthStrategyAll
}

// If the Use AAD Pod Identity is not present, or set to "none"
Expand Down

0 comments on commit e2421c0

Please sign in to comment.