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

Rename queueLength to messageCount for Azure Service Bus scaler #1138

Merged
merged 8 commits into from
Sep 11, 2020
Merged
Show file tree
Hide file tree
Changes from 6 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
- Removed deprecated brokerList for Kafka scaler ([#882](https://github.com/kedacore/keda/pull/882))
- All scalers metadata that is resolved from the scaleTarget environment have suffix `FromEnv` added. e.g: `connection` -> `connectionFromEnv`
- Kafka: split metadata and config for SASL and TLS ([#1074](https://github.com/kedacore/keda/pull/1074))
- Service Bus: `queueLength` is now called `messageCount` ([#1109](https://github.com/kedacore/keda/issues/1109))

### Other
- Update Operator SDK and k8s deps ([#1007](https://github.com/kedacore/keda/pull/1007),[#870](https://github.com/kedacore/keda/issues/870))
Expand Down
23 changes: 12 additions & 11 deletions pkg/scalers/azure_servicebus_scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ package scalers
import (
"context"
"fmt"
"github.com/kedacore/keda/pkg/scalers/azure"
"strconv"

servicebus "github.com/Azure/azure-service-bus-go"

"github.com/Azure/azure-amqp-common-go/v3/auth"
servicebus "github.com/Azure/azure-service-bus-go"
"github.com/kedacore/keda/pkg/scalers/azure"
v2beta2 "k8s.io/api/autoscaling/v2beta2"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -20,9 +19,11 @@ import (
type entityType int

const (
none entityType = 0
queue entityType = 1
subscription entityType = 2
none entityType = 0
queue entityType = 1
subscription entityType = 2
messageCountMetricName = "messageCount"
defaultTargetMessageCount = 5
)

var azureServiceBusLog = logf.Log.WithName("azure_servicebus_scaler")
Expand Down Expand Up @@ -59,15 +60,15 @@ func NewAzureServiceBusScaler(resolvedEnv, metadata, authParams map[string]strin
func parseAzureServiceBusMetadata(resolvedEnv, metadata, authParams map[string]string, podIdentity string) (*azureServiceBusMetadata, error) {
meta := azureServiceBusMetadata{}
meta.entityType = none
meta.targetLength = defaultTargetQueueLength
meta.targetLength = defaultTargetMessageCount

// get target metric value
if val, ok := metadata[queueLengthMetricName]; ok {
queueLength, err := strconv.Atoi(val)
if val, ok := metadata[messageCountMetricName]; ok {
messageCount, err := strconv.Atoi(val)
if err != nil {
azureServiceBusLog.Error(err, "Error parsing azure queue metadata", "queueLengthMetricName", queueLengthMetricName)
azureServiceBusLog.Error(err, "Error parsing azure queue metadata", "messageCount", messageCountMetricName)
} else {
meta.targetLength = queueLength
meta.targetLength = messageCount
}
}

Expand Down
5 changes: 5 additions & 0 deletions pkg/scalers/azure_servicebus_scaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const (
queueName = "testqueue"
connectionSetting = "none"
namespaceName = "ns"
messageCount = "1000"
)

type parseServiceBusMetadataTestData struct {
Expand All @@ -36,8 +37,12 @@ var parseServiceBusMetadataDataset = []parseServiceBusMetadataTestData{
{map[string]string{}, true, none, map[string]string{}, ""},
// properly formed queue
{map[string]string{"queueName": queueName, "connectionFromEnv": connectionSetting}, false, queue, map[string]string{}, ""},
// properly formed queue with message count
{map[string]string{"queueName": queueName, "connectionFromEnv": connectionSetting, "messageCount": messageCount}, false, queue, map[string]string{}, ""},
// properly formed topic & subscription
{map[string]string{"topicName": topicName, "subscriptionName": subscriptionName, "connectionFromEnv": connectionSetting}, false, subscription, map[string]string{}, ""},
// properly formed topic & subscription with message count
{map[string]string{"topicName": topicName, "subscriptionName": subscriptionName, "connectionFromEnv": connectionSetting, "messageCount": messageCount}, false, subscription, map[string]string{}, ""},
// queue and topic specified
{map[string]string{"queueName": queueName, "topicName": topicName, "connectionFromEnv": connectionSetting}, true, none, map[string]string{}, ""},
// queue and subscription specified
Expand Down