From db1907e1b78bc51c28cd9127fc8b53dc59fc5522 Mon Sep 17 00:00:00 2001 From: Tom Kerkhove Date: Fri, 11 Sep 2020 14:11:45 +0200 Subject: [PATCH] Rename `queueLength` to `messageCount` for Azure Service Bus scaler (#1138) Signed-off-by: Tom Kerkhove --- CHANGELOG.md | 1 + pkg/scalers/azure_servicebus_scaler.go | 23 +++++++++++---------- pkg/scalers/azure_servicebus_scaler_test.go | 7 ++++++- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index adc96766cf2..10a32c757fe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/pkg/scalers/azure_servicebus_scaler.go b/pkg/scalers/azure_servicebus_scaler.go index 143baf33d6a..0fe39a3f7e0 100755 --- a/pkg/scalers/azure_servicebus_scaler.go +++ b/pkg/scalers/azure_servicebus_scaler.go @@ -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" @@ -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") @@ -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 } } diff --git a/pkg/scalers/azure_servicebus_scaler_test.go b/pkg/scalers/azure_servicebus_scaler_test.go index 7f07a83683e..26061d85048 100755 --- a/pkg/scalers/azure_servicebus_scaler_test.go +++ b/pkg/scalers/azure_servicebus_scaler_test.go @@ -12,6 +12,7 @@ const ( queueName = "testqueue" connectionSetting = "none" namespaceName = "ns" + messageCount = "1000" ) type parseServiceBusMetadataTestData struct { @@ -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 @@ -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{