Skip to content

Commit

Permalink
Rename queueLength to messageCount for Azure Service Bus scaler (#…
Browse files Browse the repository at this point in the history
…1138)

Signed-off-by: Tom Kerkhove <[email protected]>
  • Loading branch information
tomkerkhove authored Sep 11, 2020
1 parent aa7b3ac commit db1907e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
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))
- Use `host` instead of `apiHost` in `rabbitmq` scaler. Add `protocol` in trigger spec to specify which protocol should be used ([#1115](https://github.com/kedacore/keda/pull/1115))

### Other
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
7 changes: 6 additions & 1 deletion 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 All @@ -58,7 +63,7 @@ var parseServiceBusMetadataDataset = []parseServiceBusMetadataTestData{

var azServiceBusMetricIdentifiers = []azServiceBusMetricIdentifier{
{&parseServiceBusMetadataDataset[1], "azure-servicebus-testqueue"},
{&parseServiceBusMetadataDataset[2], "azure-servicebus-testtopic-testsubscription"},
{&parseServiceBusMetadataDataset[3], "azure-servicebus-testtopic-testsubscription"},
}

var getServiceBusLengthTestScalers = []azureServiceBusScaler{
Expand Down

0 comments on commit db1907e

Please sign in to comment.