From 3e8ab5216774ed11125ba176b490b7f4f4143de0 Mon Sep 17 00:00:00 2001 From: Dennis Brinley Date: Fri, 9 Jul 2021 15:45:49 -0400 Subject: [PATCH 1/7] Commit changes for solace-queue scaler Signed-off-by: Dennis Brinley Includes solace_scaler Unit tests, end-to-end tests, and mod to handler By making a contribution to this project, I certify that: (a) The contribution was created in whole or in part by me and I have the right to submit it under the open source license indicated in the file; or (b) The contribution is based upon previous work that, to the best of my knowledge, is covered under an appropriate open source license and I have the right under that license to submit that work with modifications, whether created in whole or in part by me, under the same open source license (unless I am permitted to submit under a different license), as indicated in the file; or (c) The contribution was provided directly to me by some other person who certified (a), (b) or (c) and I have not modified it. (d) I understand and agree that this project and the contribution are public and that a record of the contribution (including all personal information I submit with it, including my sign-off) is maintained indefinitely and may be redistributed consistent with this project or the open source license(s) involved. --- pkg/scalers/solace_scaler.go | 406 +++++++++++++++ pkg/scalers/solace_scaler_test.go | 812 ++++++++++++++++++++++++++++++ pkg/scaling/scale_handler.go | 2 + tests/scalers/solace-helpers.ts | 240 +++++++++ tests/scalers/solace.tests.ts | 96 ++++ 5 files changed, 1556 insertions(+) create mode 100644 pkg/scalers/solace_scaler.go create mode 100644 pkg/scalers/solace_scaler_test.go create mode 100644 tests/scalers/solace-helpers.ts create mode 100644 tests/scalers/solace.tests.ts diff --git a/pkg/scalers/solace_scaler.go b/pkg/scalers/solace_scaler.go new file mode 100644 index 00000000000..3663befff23 --- /dev/null +++ b/pkg/scalers/solace_scaler.go @@ -0,0 +1,406 @@ +package scalers + +import ( + "context" + "encoding/json" + "fmt" + "net/http" + "strconv" + "strings" + + v2beta2 "k8s.io/api/autoscaling/v2beta2" + "k8s.io/apimachinery/pkg/api/resource" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/labels" + "k8s.io/metrics/pkg/apis/external_metrics" + logf "sigs.k8s.io/controller-runtime/pkg/log" + + kedautil "github.com/kedacore/keda/v2/pkg/util" +) + +const ( + solace_EXT_METRIC_TYPE = "External" + solace_SCALER_ID = "solace" + + // REST ENDPOINT String Patterns + solace_BROKER_BASE_URL_TEMPLATE = "%s://%s:%s" + solace_SEMP_ENDPOINT_URL_TEMPLATE = "%s/%s/%s/monitor/msgVpns/%s/%ss/%s" + // SEMP REST API Context + solace_API_NAME = "SEMP" + solace_API_VERSION = "v2" + solace_API_DFLT_OBJ_TYPE = "queue" + + // Log Message Templates + solace_FOUND_META_TRUE = "Field %s Found in Solace Metadata; Value=%v" + solace_FOUND_META_FALSE = "Required Field %s NOT FOUND in Solace Metadata" + + // YAML Configuration Metadata Field Names + // Broker Identifiers + solace_META_brokerBaseUrl = "brokerBaseUrl" + solace_META_brokerProtocol = "brokerProtocol" + solace_META_brokerHostname = "brokerHostname" + solace_META_brokerPort = "brokerPort" + // Credential Identifiers + solace_META_username = "username" + solace_META_password = "password" + solace_META_usernameEnv = "usernameEnv" + solace_META_passwordEnv = "passwordEnv" + // Target Object Identifiers + solace_META_msgVpn = "msgVpn" + solace_META_queueName = "queueName" + // Metric Targets + solace_META_msgCountTarget = "msgCountTarget" + solace_META_msgSpoolUsageTarget = "msgSpoolUsageTarget" + + // Trigger type identifiers + solace_TRIG_msgcount = "msgcount" + solace_TRIG_msgspoolusage = "msgspoolusage" +) + +// Struct for Observed Metric Values +type SolaceMetricValues struct { + // Observed Message Count + msgCount int + // Observed Message Spool Usage + msgSpoolUsage int +} + +type SolaceScaler struct { + metadata *SolaceMetadata + httpClient *http.Client +} + +type SolaceMetadata struct { + // Full SEMP URL to target queue (CONSTRUCTED IN CODE) + endpointUrl string + // Protocol-Host-Port: http://host-name:12345 + brokerBaseUrl string + brokerProtocol string // Used if brokerBaseUrl not present + brokerHostname string // Used if brokerBaseUrl not present + brokerPort string // Used if brokerBaseUrl not present + // Solace Message VPN + messageVpn string + queueName string + // Basic Auth Username + username string + // Basic Auth Password + password string + // Target Message Count + msgCountTarget int + msgSpoolUsageTarget int // Spool Use Target in Megabytes +} + +// SEMP API Response Root Struct +type solaceSEMPResponse struct { + Collections solaceSEMPCollections `json:"collections"` + Data solaceSEMPData `json:"data"` + Meta solaceSEMPMetadata `json:"meta"` +} + +// SEMP API Response Collections Struct +type solaceSEMPCollections struct { + Msgs solaceSEMPMessages `json:"msgs"` +} + +// SEMP API Response Queue Data Struct +type solaceSEMPData struct { + MsgSpoolUsage int `json:"msgSpoolUsage"` +} + +// SEMP API Messages Struct +type solaceSEMPMessages struct { + Count int `json:"count"` +} + +// SEMP API Metadata Struct +type solaceSEMPMetadata struct { + ResponseCode int `json:"responseCode"` +} + +// Solace Logger +var solaceLog = logf.Log.WithName(solace_SCALER_ID + "_scaler") + +// Constructor for SolaceScaler +func NewSolaceScaler(config *ScalerConfig) (Scaler, error) { + + // Create HTTP Client + httpClient := kedautil.CreateHTTPClient(config.GlobalHTTPTimeout) + + // Parse Solace Metadata + solaceMetadata, err := parseSolaceMetadata(config) + if err != nil { + solaceLog.Error(err, "Error parsing Solace Trigger Metadata or missing values") + return nil, err //fmt.Errorf("Error parsing Solace Trigger metadata: %s", err) + } + + return &SolaceScaler{ + metadata: solaceMetadata, + httpClient: httpClient, + }, nil +} + +// Called by constructor +func parseSolaceMetadata(config *ScalerConfig) (*SolaceMetadata, error) { + meta := SolaceMetadata{} + + // GET THE SEMP API ENDPOINT + // First look for brokerBaseUrl in config; Use components if not found + if val, ok := config.TriggerMetadata[solace_META_brokerBaseUrl]; ok && val != "" { + meta.brokerBaseUrl = val + } else { + // IF brokerBaseUrl is not present, then get components + // GET Protocol + if val, ok := config.TriggerMetadata[solace_META_brokerProtocol]; ok && (val == "https" || val == "http") { + meta.brokerProtocol = val + } else { + return nil, fmt.Errorf(solace_FOUND_META_FALSE, solace_META_brokerProtocol) + } + // GET Hostname + if val, ok := config.TriggerMetadata[solace_META_brokerHostname]; ok && val != "" { + meta.brokerHostname = val + } else { + return nil, fmt.Errorf(solace_FOUND_META_FALSE, solace_META_brokerHostname) + } + // GET Port + if val, ok := config.TriggerMetadata[solace_META_brokerPort]; ok && val != "" { + if _, err := strconv.Atoi(val); err == nil { + meta.brokerPort = val + } else { + return nil, fmt.Errorf("Can't parse brokerPort, not a valid integer: %s", err) + } + } else { + return nil, fmt.Errorf(solace_FOUND_META_FALSE, solace_META_brokerPort) + } + // Format Solace Broker Base URL from components + meta.brokerBaseUrl = fmt.Sprintf(solace_BROKER_BASE_URL_TEMPLATE, meta.brokerProtocol, meta.brokerHostname, meta.brokerPort) + } + + // GET Message VPN + if val, ok := config.TriggerMetadata[solace_META_msgVpn]; ok && val != "" { + meta.messageVpn = val + } else { + return nil, fmt.Errorf(solace_FOUND_META_FALSE, solace_META_msgVpn) + } + + // GET Queue Name + if val, ok := config.TriggerMetadata[solace_META_queueName]; ok && val != "" { + meta.queueName = val + } else { + return nil, fmt.Errorf(solace_FOUND_META_FALSE, solace_META_queueName) + } + + // GET METRIC TARGET VALUES + // GET msgCountTarget + if val, ok := config.TriggerMetadata[solace_META_msgCountTarget]; ok && val != "" { + if msgCount, err := strconv.Atoi(val); err == nil { + meta.msgCountTarget = msgCount + } else { + return nil, fmt.Errorf("Can't parse [%s], not a valid integer: %s", solace_META_msgCountTarget, err) + } + } + // GET msgSpoolUsageTarget + if val, ok := config.TriggerMetadata[solace_META_msgSpoolUsageTarget]; ok && val != "" { + if msgSpoolUsage, err := strconv.Atoi(val); err == nil { + meta.msgSpoolUsageTarget = msgSpoolUsage + } else { + return nil, fmt.Errorf("Can't parse [%s], not a valid integer: %s", solace_META_msgSpoolUsageTarget, err) + } + } + + // Check that we have at least one positive target value for the scaler + if meta.msgCountTarget < 1 && meta.msgSpoolUsageTarget < 1 { + return nil, fmt.Errorf("No Target Value found in the Scaler Configuration") + } + + // Format Solace SEMP Queue Endpoint (REST URL) + meta.endpointUrl = fmt.Sprintf( + solace_SEMP_ENDPOINT_URL_TEMPLATE, + meta.brokerBaseUrl, + solace_API_NAME, + solace_API_VERSION, + meta.messageVpn, + solace_API_DFLT_OBJ_TYPE, + meta.queueName) + + /* GET CREDENTIALS + The username must be a valid broker ADMIN user identifier with read access to SEMP for the broker, VPN, and relevant objects + The scaler will attempt to acquire username and then password independently. For each: + - Search K8S Secret (Encoded) + - Search environment variable specified by config at 'usernameEnv' / 'passwordEnv' + - Search 'username' / 'password' fields (Clear Text) + */ + // Get username + if usernameSecret, ok := config.AuthParams[solace_META_username]; ok && usernameSecret != "" { + meta.username = usernameSecret + } else if usernameEnv, ok := config.TriggerMetadata[solace_META_usernameEnv]; ok && usernameEnv != "" { + if resolvedUser, ok := config.ResolvedEnv[config.TriggerMetadata[solace_META_usernameEnv]]; ok && resolvedUser != "" { + meta.username = resolvedUser + } else { + return nil, fmt.Errorf("username could not be resolved from the environment variable: %s", usernameEnv) + } + } else if usernameClear, ok := config.TriggerMetadata[solace_META_username]; ok && usernameClear != "" { + meta.username = usernameClear + } else { + return nil, fmt.Errorf("username is required and not found in K8Secret, environment, or clear text") + } + // Get Password + if passwordSecret, ok := config.AuthParams[solace_META_password]; ok && passwordSecret != "" { + meta.password = passwordSecret + } else if passwordEnv, ok := config.TriggerMetadata[solace_META_passwordEnv]; ok && passwordEnv != "" { + if resolvedPassword, ok := config.ResolvedEnv[config.TriggerMetadata[solace_META_passwordEnv]]; ok && resolvedPassword != "" { + meta.password = resolvedPassword + } else { + return nil, fmt.Errorf("password could not be resolved from the environment variable: %s", passwordEnv) + } + } else if passwordClear, ok := config.TriggerMetadata[solace_META_password]; ok && passwordClear != "" { + meta.password = passwordClear + } else { + return nil, fmt.Errorf("password is required and not found in K8Secret, environment, or clear text") + } + + return &meta, nil +} + +// INTERFACE METHOD +// DEFINE METRIC FOR SCALING +// CURRENT SUPPORTED METRICS ARE: +// - QUEUE MESSAGE COUNT (msgCount) +// - QUEUE SPOOL USAGE (msgSpoolUsage in MBytes) +// METRIC IDENTIFIER HAS THE SIGNATURE: +// - solace-[VPN_Name]-[Queue_Name]-[metric_type] +// e.g. solace-myvpn-QUEUE1-msgCount +func (s *SolaceScaler) GetMetricSpecForScaling() []v2beta2.MetricSpec { + + var metricSpecList []v2beta2.MetricSpec + + // Message Count Target Spec + if s.metadata.msgCountTarget > 0 { + targetMetricValue := resource.NewQuantity(int64(s.metadata.msgCountTarget), resource.DecimalSI) + externalMetric := &v2beta2.ExternalMetricSource{ + Metric: v2beta2.MetricIdentifier{ + Name: kedautil.NormalizeString(fmt.Sprintf("%s-%s-%s-%s", solace_SCALER_ID, s.metadata.messageVpn, s.metadata.queueName, solace_TRIG_msgcount)), + }, + Target: v2beta2.MetricTarget{ + Type: v2beta2.AverageValueMetricType, + AverageValue: targetMetricValue, + }, + } + metricSpec := v2beta2.MetricSpec{External: externalMetric, Type: solace_EXT_METRIC_TYPE} + metricSpecList = append(metricSpecList, metricSpec) + } + // Message Spool Usage Target Spec + if s.metadata.msgSpoolUsageTarget > 0 { + targetMetricValue := resource.NewQuantity(int64(s.metadata.msgSpoolUsageTarget), resource.DecimalSI) + externalMetric := &v2beta2.ExternalMetricSource{ + Metric: v2beta2.MetricIdentifier{ + Name: kedautil.NormalizeString(fmt.Sprintf("%s-%s-%s-%s", solace_SCALER_ID, s.metadata.messageVpn, s.metadata.queueName, solace_TRIG_msgspoolusage)), + }, + Target: v2beta2.MetricTarget{ + Type: v2beta2.AverageValueMetricType, + AverageValue: targetMetricValue, + }, + } + metricSpec := v2beta2.MetricSpec{External: externalMetric, Type: solace_EXT_METRIC_TYPE} + metricSpecList = append(metricSpecList, metricSpec) + } + return metricSpecList +} + +// returns SolaceMetricValues struct populated from broker SEMP endpoint +func (s *SolaceScaler) getSolaceQueueMetricsFromSEMP() (SolaceMetricValues, error) { + + var scaledMetricEndpointUrl string = s.metadata.endpointUrl + var httpClient *http.Client = s.httpClient + var sempResponse solaceSEMPResponse + var metricValues SolaceMetricValues + + // RETRIEVE METRICS FROM SOLACE SEMP API + // Define HTTP Request + request, err := http.NewRequest("GET", scaledMetricEndpointUrl, nil) + if err != nil { + return SolaceMetricValues{}, fmt.Errorf("Failed attempting request to Solace SEMP API: %s", err) + } + // Add HTTP Auth and Headers + request.SetBasicAuth(s.metadata.username, s.metadata.password) + request.Header.Set("Content-Type", "application/json") + // Call Solace SEMP API + response, err := httpClient.Do(request) + if err != nil { + return SolaceMetricValues{}, fmt.Errorf("Call to Solace SEMP API failed: %s", err) + } + defer response.Body.Close() + + // Check HTTP Status Code + if response.StatusCode < 200 || response.StatusCode > 299 { + sempError := fmt.Errorf("SEMP Request HTTP Status Code: %s - %s", strconv.Itoa(response.StatusCode), response.Status) + return SolaceMetricValues{}, sempError + } + + // Decode SEMP Response and Test + if err := json.NewDecoder(response.Body).Decode(&sempResponse); err != nil { + return SolaceMetricValues{}, fmt.Errorf("Failed to read SEMP response body: %s", err) + } + if sempResponse.Meta.ResponseCode < 200 && sempResponse.Meta.ResponseCode > 299 { + return SolaceMetricValues{}, fmt.Errorf("Solace SEMP API returned error status: %d", sempResponse.Meta.ResponseCode) + } + + // Set Return Values + metricValues.msgCount = sempResponse.Collections.Msgs.Count + metricValues.msgSpoolUsage = sempResponse.Data.MsgSpoolUsage + return metricValues, nil +} + +// INTERFACE METHOD +// Call SEMP API to retrieve metrics +// returns value for named metric +func (s *SolaceScaler) GetMetrics(ctx context.Context, metricName string, metricSelector labels.Selector) ([]external_metrics.ExternalMetricValue, error) { + + var metricValues SolaceMetricValues + if val, err := s.getSolaceQueueMetricsFromSEMP(); err != nil { + solaceLog.Error(err, fmt.Sprintf("Call to SEMP Endpoint Failed")) + return []external_metrics.ExternalMetricValue{}, err + } else { + metricValues = val + } + + var metric external_metrics.ExternalMetricValue + switch { + case strings.HasSuffix(metricName, solace_TRIG_msgcount): + metric = external_metrics.ExternalMetricValue{ + MetricName: metricName, + Value: *resource.NewQuantity(int64(metricValues.msgCount), resource.DecimalSI), + Timestamp: metav1.Now(), + } + case strings.HasSuffix(metricName, solace_TRIG_msgspoolusage): + metric = external_metrics.ExternalMetricValue{ + MetricName: metricName, + Value: *resource.NewQuantity(int64(metricValues.msgSpoolUsage), resource.DecimalSI), + Timestamp: metav1.Now(), + } + default: + // Should never end up here + err := fmt.Errorf("Unidentified Metric: %s", metricName) + solaceLog.Error(err, "Returning Error to calling app") + return []external_metrics.ExternalMetricValue{}, err + } + + return append([]external_metrics.ExternalMetricValue{}, metric), nil +} + +// INTERFACE METHOD +// Call SEMP API to retrieve metrics +// IsActive returns true if queue messageCount > 0 || msgSpoolUsage > 0 +func (s *SolaceScaler) IsActive(ctx context.Context) (bool, error) { + + metricValues, err := s.getSolaceQueueMetricsFromSEMP() + if err != nil { + solaceLog.Error(err, "Call to SEMP Endpoint Failed") + return false, err + } + return (metricValues.msgCount > 0 || metricValues.msgSpoolUsage > 0), nil +} + +// Do Nothing - Satisfies Interface +func (s *SolaceScaler) Close() error { + return nil +} diff --git a/pkg/scalers/solace_scaler_test.go b/pkg/scalers/solace_scaler_test.go new file mode 100644 index 00000000000..5a8a68d4c5e --- /dev/null +++ b/pkg/scalers/solace_scaler_test.go @@ -0,0 +1,812 @@ +package scalers + +import ( + "fmt" + "net/http" + "testing" + + "k8s.io/api/autoscaling/v2beta2" +) + +type testSolaceMetadata struct { + testId string + metadata map[string]string + isError bool +} + +type testSolaceMetricIdentifier struct { + metadataTestData *testSolaceMetadata + name string +} + +var ( + soltest_VALID_BASEURL = "http://localhost:8080" + soltest_VALID_PROTOCOL = "http" + soltest_VALID_HOSTNAME = "localhost" + soltest_VALID_PORT = "8080" + // ##### TODO -- RESET THIS + // soltest_VALID_USERNAME = "solace_user" + // soltest_VALID_PASSWORD = "solace_pass" + // soltest_VALID_VPN = "solace_keda_vpn" + // soltest_VALID_QUEUE_NAME = "KEDA_Q1" + soltest_VALID_USERNAME = "admin" + soltest_VALID_PASSWORD = "admin" + soltest_VALID_VPN = "dennis_vpn" + soltest_VALID_QUEUE_NAME = "queue3" + soltest_VALID_MSG_COUNT_TARGET = "10" + soltest_VALID_MSG_SPOOL_TARGET = "20" + + soltest_ENVVAR_USERNAME = "SOLTEST_USERNAME" + soltest_ENVVAR_PASSWORD = "SOLTEST_PASSWORD" +) + +// AUTH RECORD FOR TEST +var testDataSolaceAuthParamsVALID = map[string]string{ + solace_META_username: soltest_VALID_USERNAME, + solace_META_password: soltest_VALID_PASSWORD, +} + +// ENV VARS FOR TEST -- VALID USER / PWD +var testDataSolaceResolvedEnvVALID = map[string]string{ + soltest_ENVVAR_USERNAME: soltest_VALID_USERNAME, // Sets the environment variables to the correct values + soltest_ENVVAR_PASSWORD: soltest_VALID_PASSWORD, +} + +// ENV VARS FOR TEST -- INVALID USER / PWD +var testDataSolaceResolvedEnvINVALID = map[string]string{ + soltest_ENVVAR_USERNAME: "NOT_CORRECT_USERID", // Sets the environment variables to incorrect values + soltest_ENVVAR_PASSWORD: "NOT_A_PASSWORD", +} + +// TEST CASES FOR SolaceParseMetadata() +var testParseSolaceMetadata = []testSolaceMetadata{ + /* + IF brokerBaseUrl is present, use it without interpretation as the base URL: http://my.host.domain:1234 + IF brokerBaseUrl in not present, Use protocol, host, and port + */ + + // Empty + { + "#001 - EMPTY", map[string]string{}, + true, + }, + + // +Case - brokerBaseUrl + { + "#002 - brokerBaseUrl", + map[string]string{ + "": "", + solace_META_brokerBaseUrl: soltest_VALID_BASEURL, + solace_META_brokerProtocol: "", + solace_META_brokerHostname: "", + solace_META_brokerPort: "", + solace_META_msgVpn: soltest_VALID_VPN, + solace_META_usernameEnv: "", + solace_META_passwordEnv: "", + solace_META_username: soltest_VALID_USERNAME, + solace_META_password: soltest_VALID_PASSWORD, + solace_META_queueName: soltest_VALID_QUEUE_NAME, + solace_META_msgCountTarget: soltest_VALID_MSG_COUNT_TARGET, + }, + false, + }, + // +Case - protocol + host + port + { + "#003 - protocol + host + port", + map[string]string{ + solace_META_brokerBaseUrl: "", + solace_META_brokerProtocol: soltest_VALID_PROTOCOL, + solace_META_brokerHostname: soltest_VALID_HOSTNAME, + solace_META_brokerPort: soltest_VALID_PORT, + solace_META_msgVpn: soltest_VALID_VPN, + solace_META_usernameEnv: "", + solace_META_passwordEnv: "", + solace_META_username: soltest_VALID_USERNAME, + solace_META_password: soltest_VALID_PASSWORD, + solace_META_queueName: soltest_VALID_QUEUE_NAME, + solace_META_msgCountTarget: soltest_VALID_MSG_COUNT_TARGET, + }, + false, + }, + + // -Case - missing protocol + { + "#004 - missing protocol", + map[string]string{ + solace_META_brokerBaseUrl: "", + solace_META_brokerProtocol: "", + solace_META_brokerHostname: soltest_VALID_HOSTNAME, + solace_META_brokerPort: soltest_VALID_PORT, + solace_META_msgVpn: soltest_VALID_VPN, + solace_META_usernameEnv: "", + solace_META_passwordEnv: "", + solace_META_username: soltest_VALID_USERNAME, + solace_META_password: soltest_VALID_PASSWORD, + solace_META_queueName: soltest_VALID_QUEUE_NAME, + solace_META_msgCountTarget: soltest_VALID_MSG_COUNT_TARGET, + }, + true, + }, + // -Case - missing hostname + { + "#005 - missing hostname", + map[string]string{ + solace_META_brokerBaseUrl: "", + solace_META_brokerProtocol: soltest_VALID_PROTOCOL, + solace_META_brokerHostname: "", + solace_META_brokerPort: soltest_VALID_PORT, + solace_META_msgVpn: soltest_VALID_VPN, + solace_META_usernameEnv: "", + solace_META_passwordEnv: "", + solace_META_username: soltest_VALID_USERNAME, + solace_META_password: soltest_VALID_PASSWORD, + solace_META_queueName: soltest_VALID_QUEUE_NAME, + solace_META_msgCountTarget: soltest_VALID_MSG_COUNT_TARGET, + }, + true, + }, + // -Case - missing port + { + "#006 - missing port", + map[string]string{ + solace_META_brokerBaseUrl: "", + solace_META_brokerProtocol: soltest_VALID_PROTOCOL, + solace_META_brokerHostname: soltest_VALID_HOSTNAME, + solace_META_brokerPort: "", + solace_META_msgVpn: soltest_VALID_VPN, + solace_META_usernameEnv: "", + solace_META_passwordEnv: "", + solace_META_username: soltest_VALID_USERNAME, + solace_META_password: soltest_VALID_PASSWORD, + solace_META_queueName: soltest_VALID_QUEUE_NAME, + solace_META_msgCountTarget: soltest_VALID_MSG_COUNT_TARGET, + }, + true, + }, + // -Case - missing username (clear) + { + "#007 - missing username (clear)", + map[string]string{ + solace_META_brokerBaseUrl: "", + solace_META_brokerProtocol: soltest_VALID_PROTOCOL, + solace_META_brokerHostname: soltest_VALID_HOSTNAME, + solace_META_brokerPort: soltest_VALID_PORT, + solace_META_msgVpn: soltest_VALID_VPN, + solace_META_usernameEnv: "", + solace_META_passwordEnv: "", + solace_META_username: "", + solace_META_password: soltest_VALID_PASSWORD, + solace_META_queueName: soltest_VALID_QUEUE_NAME, + solace_META_msgCountTarget: soltest_VALID_MSG_COUNT_TARGET, + }, + true, + }, + // -Case - missing password (clear) + { + "#008 - missing password (clear)", + map[string]string{ + solace_META_brokerBaseUrl: "", + solace_META_brokerProtocol: soltest_VALID_PROTOCOL, + solace_META_brokerHostname: soltest_VALID_HOSTNAME, + solace_META_brokerPort: soltest_VALID_PORT, + solace_META_msgVpn: soltest_VALID_VPN, + solace_META_usernameEnv: "", + solace_META_passwordEnv: "", + solace_META_username: soltest_VALID_USERNAME, + solace_META_password: "", + solace_META_queueName: soltest_VALID_QUEUE_NAME, + solace_META_msgCountTarget: soltest_VALID_MSG_COUNT_TARGET, + }, + true, + }, + // -Case - missing queue + { + "#009 - missing queueName", + map[string]string{ + solace_META_brokerBaseUrl: "", + solace_META_brokerProtocol: soltest_VALID_PROTOCOL, + solace_META_brokerHostname: soltest_VALID_HOSTNAME, + solace_META_brokerPort: soltest_VALID_PORT, + solace_META_msgVpn: soltest_VALID_VPN, + solace_META_usernameEnv: "", + solace_META_passwordEnv: "", + solace_META_username: soltest_VALID_USERNAME, + solace_META_password: soltest_VALID_PASSWORD, + solace_META_queueName: "", + solace_META_msgCountTarget: soltest_VALID_MSG_COUNT_TARGET, + }, + true, + }, + // -Case - missing msgCountTarget + { + "#010 - missing msgCountTarget", + map[string]string{ + solace_META_brokerBaseUrl: "", + solace_META_brokerProtocol: soltest_VALID_PROTOCOL, + solace_META_brokerHostname: soltest_VALID_HOSTNAME, + solace_META_brokerPort: soltest_VALID_PORT, + solace_META_msgVpn: soltest_VALID_VPN, + solace_META_usernameEnv: "", + solace_META_passwordEnv: "", + solace_META_username: soltest_VALID_USERNAME, + solace_META_password: soltest_VALID_PASSWORD, + solace_META_queueName: soltest_VALID_QUEUE_NAME, + solace_META_msgCountTarget: "", + solace_META_msgSpoolUsageTarget: "", + }, + true, + }, + // -Case - msgSpoolUsageTarget non-numeric + { + "#011 - msgSpoolUsageTarget non-numeric", + map[string]string{ + solace_META_brokerBaseUrl: "", + solace_META_brokerProtocol: soltest_VALID_PROTOCOL, + solace_META_brokerHostname: soltest_VALID_HOSTNAME, + solace_META_brokerPort: soltest_VALID_PORT, + solace_META_msgVpn: soltest_VALID_VPN, + solace_META_usernameEnv: "", + solace_META_passwordEnv: "", + solace_META_username: soltest_VALID_USERNAME, + solace_META_password: soltest_VALID_PASSWORD, + solace_META_queueName: soltest_VALID_QUEUE_NAME, + solace_META_msgCountTarget: "NOT_AN_INTEGER", + }, + true, + }, + // -Case - msgSpoolUsage non-numeric + { + "#012 - msgSpoolUsage non-numeric", + map[string]string{ + solace_META_brokerBaseUrl: "", + solace_META_brokerProtocol: soltest_VALID_PROTOCOL, + solace_META_brokerHostname: soltest_VALID_HOSTNAME, + solace_META_brokerPort: soltest_VALID_PORT, + solace_META_msgVpn: soltest_VALID_VPN, + solace_META_usernameEnv: "", + solace_META_passwordEnv: "", + solace_META_username: soltest_VALID_USERNAME, + solace_META_password: soltest_VALID_PASSWORD, + solace_META_queueName: soltest_VALID_QUEUE_NAME, + solace_META_msgSpoolUsageTarget: "NOT_AN_INTEGER", + }, + true, + }, + // +Case - Pass with msgSpoolUsageTarget and not msgCountTarget + { + "#013 - brokerBaseUrl", + map[string]string{ + "": "", + solace_META_brokerBaseUrl: soltest_VALID_BASEURL, + solace_META_brokerProtocol: "", + solace_META_brokerHostname: "", + solace_META_brokerPort: "", + solace_META_msgVpn: soltest_VALID_VPN, + solace_META_usernameEnv: "", + solace_META_passwordEnv: "", + solace_META_username: soltest_VALID_USERNAME, + solace_META_password: soltest_VALID_PASSWORD, + solace_META_queueName: soltest_VALID_QUEUE_NAME, + solace_META_msgSpoolUsageTarget: soltest_VALID_MSG_SPOOL_TARGET, + }, + false, + }, +} + +var testSolaceEnvCreds = []testSolaceMetadata{ + // +Case - Should find ENV vars + // Environment user/pass should be set: + // - SOLTEST_USERNAME + // - SOLTEST_PASSWORD + { + "#101 - Connect with Credentials in env", + map[string]string{ + // "": "", + solace_META_brokerBaseUrl: soltest_VALID_BASEURL, + solace_META_brokerProtocol: "", + solace_META_brokerHostname: "", + solace_META_brokerPort: "", + solace_META_msgVpn: soltest_VALID_VPN, + solace_META_usernameEnv: soltest_ENVVAR_USERNAME, + solace_META_passwordEnv: soltest_ENVVAR_PASSWORD, + // solace_META_username: "", + // solace_META_password: "", + solace_META_queueName: soltest_VALID_QUEUE_NAME, + solace_META_msgCountTarget: soltest_VALID_MSG_COUNT_TARGET, + }, + false, + }, + // -Case - Should fail with ENV var not found + { + "#102 - Environment vars referenced but not found", + map[string]string{ + // "": "", + solace_META_brokerBaseUrl: soltest_VALID_BASEURL, + solace_META_brokerProtocol: "", + solace_META_brokerHostname: "", + solace_META_brokerPort: "", + solace_META_msgVpn: soltest_VALID_VPN, + solace_META_usernameEnv: "SOLTEST_DNE", + solace_META_passwordEnv: "SOLTEST_DNE", + // solace_META_username: "", + // solace_META_password: "", + solace_META_queueName: soltest_VALID_QUEUE_NAME, + solace_META_msgCountTarget: soltest_VALID_MSG_COUNT_TARGET, + }, + true, + }, +} + +var testSolaceK8sSecretCreds = []testSolaceMetadata{ + // Records require Auth Record to be passed + + // +Case - Should find + { + "#201 - Connect with credentials from Auth Record (ENV VAR Present)", + map[string]string{ + // "": "", + solace_META_brokerBaseUrl: soltest_VALID_BASEURL, + solace_META_brokerProtocol: "", + solace_META_brokerHostname: "", + solace_META_brokerPort: "", + solace_META_msgVpn: soltest_VALID_VPN, + solace_META_usernameEnv: soltest_ENVVAR_USERNAME, + solace_META_passwordEnv: soltest_ENVVAR_PASSWORD, + // solace_META_username: "", + // solace_META_password: "", + solace_META_queueName: soltest_VALID_QUEUE_NAME, + solace_META_msgCountTarget: soltest_VALID_MSG_COUNT_TARGET, + }, + false, + }, + // +Case - should find creds + { + "#202 - Connect with credentials from Auth Record (ENV VAR and Clear Auth not present)", + map[string]string{ + // "": "", + // solace_META_brokerBaseUrl: soltest_VALID_BASEURL, + solace_META_brokerProtocol: soltest_VALID_PROTOCOL, + solace_META_brokerHostname: soltest_VALID_HOSTNAME, + solace_META_brokerPort: soltest_VALID_PORT, + solace_META_msgVpn: soltest_VALID_VPN, + // solace_META_usernameEnv: soltest_ENVVAR_USERNAME, + // solace_META_passwordEnv: soltest_ENVVAR_PASSWORD, + // solace_META_username: "", + // solace_META_password: "", + solace_META_queueName: soltest_VALID_QUEUE_NAME, + solace_META_msgCountTarget: soltest_VALID_MSG_COUNT_TARGET, + }, + false, + }, + // +Case - Should find with creds + { + "#203 - Connect with credentials from Auth Record (ENV VAR Present, Clear Auth not present)", + map[string]string{ + // "": "", + solace_META_brokerBaseUrl: soltest_VALID_BASEURL, + solace_META_brokerProtocol: "", + solace_META_brokerHostname: "", + solace_META_brokerPort: "", + solace_META_msgVpn: soltest_VALID_VPN, + solace_META_usernameEnv: "SOLTEST_DNE", + solace_META_passwordEnv: "SOLTEST_DNE", + // solace_META_username: "", + // solace_META_password: "", + solace_META_queueName: soltest_VALID_QUEUE_NAME, + solace_META_msgCountTarget: soltest_VALID_MSG_COUNT_TARGET, + }, + false, + }, +} + +var testSolaceGetMetricSpecData = []testSolaceMetadata{ + { + "#401 - Get Metric Spec - msgCountTarget", + map[string]string{ + "": "", + solace_META_brokerBaseUrl: soltest_VALID_BASEURL, + solace_META_brokerProtocol: "", + solace_META_brokerHostname: "", + solace_META_brokerPort: "", + solace_META_msgVpn: soltest_VALID_VPN, + solace_META_usernameEnv: "", + solace_META_passwordEnv: "", + solace_META_username: soltest_VALID_USERNAME, + solace_META_password: soltest_VALID_PASSWORD, + solace_META_queueName: soltest_VALID_QUEUE_NAME, + solace_META_msgCountTarget: soltest_VALID_MSG_COUNT_TARGET, + // solace_META_msgSpoolUsageTarget: soltest_VALID_MSG_SPOOL_TARGET, + }, + false, + }, + { + "#402 - Get Metric Spec - msgSpoolUsageTarget", + map[string]string{ + "": "", + solace_META_brokerBaseUrl: soltest_VALID_BASEURL, + solace_META_brokerProtocol: "", + solace_META_brokerHostname: "", + solace_META_brokerPort: "", + solace_META_msgVpn: soltest_VALID_VPN, + solace_META_usernameEnv: "", + solace_META_passwordEnv: "", + solace_META_username: soltest_VALID_USERNAME, + solace_META_password: soltest_VALID_PASSWORD, + solace_META_queueName: soltest_VALID_QUEUE_NAME, + // solace_META_msgCountTarget: soltest_VALID_MSG_COUNT_TARGET, + solace_META_msgSpoolUsageTarget: soltest_VALID_MSG_SPOOL_TARGET, + }, + false, + }, + { + "#403 - Get Metric Spec - BOTH msgSpoolUsage and msgCountTarget", + map[string]string{ + "": "", + solace_META_brokerBaseUrl: soltest_VALID_BASEURL, + solace_META_brokerProtocol: "", + solace_META_brokerHostname: "", + solace_META_brokerPort: "", + solace_META_msgVpn: soltest_VALID_VPN, + solace_META_usernameEnv: "", + solace_META_passwordEnv: "", + solace_META_username: soltest_VALID_USERNAME, + solace_META_password: soltest_VALID_PASSWORD, + solace_META_queueName: soltest_VALID_QUEUE_NAME, + solace_META_msgCountTarget: soltest_VALID_MSG_COUNT_TARGET, + solace_META_msgSpoolUsageTarget: soltest_VALID_MSG_SPOOL_TARGET, + }, + false, + }, + { + "#404 - Get Metric Spec - BOTH MISSING", + map[string]string{ + "": "", + solace_META_brokerBaseUrl: soltest_VALID_BASEURL, + solace_META_brokerProtocol: "", + solace_META_brokerHostname: "", + solace_META_brokerPort: "", + solace_META_msgVpn: soltest_VALID_VPN, + solace_META_usernameEnv: "", + solace_META_passwordEnv: "", + solace_META_username: soltest_VALID_USERNAME, + solace_META_password: soltest_VALID_PASSWORD, + solace_META_queueName: soltest_VALID_QUEUE_NAME, + // solace_META_msgCountTarget: soltest_VALID_MSG_COUNT_TARGET, + // solace_META_msgSpoolUsageTarget: soltest_VALID_MSG_SPOOL_TARGET, + }, + true, + }, + { + "#405 - Get Metric Spec - BOTH ZERO", + map[string]string{ + "": "", + solace_META_brokerBaseUrl: soltest_VALID_BASEURL, + solace_META_brokerProtocol: "", + solace_META_brokerHostname: "", + solace_META_brokerPort: "", + solace_META_msgVpn: soltest_VALID_VPN, + solace_META_usernameEnv: "", + solace_META_passwordEnv: "", + solace_META_username: soltest_VALID_USERNAME, + solace_META_password: soltest_VALID_PASSWORD, + solace_META_queueName: soltest_VALID_QUEUE_NAME, + solace_META_msgCountTarget: "0", + solace_META_msgSpoolUsageTarget: "0", + }, + true, + }, + { + "#406 - Get Metric Spec - ONE ZERO; OTHER VALID", + map[string]string{ + "": "", + solace_META_brokerBaseUrl: soltest_VALID_BASEURL, + solace_META_brokerProtocol: "", + solace_META_brokerHostname: "", + solace_META_brokerPort: "", + solace_META_msgVpn: soltest_VALID_VPN, + solace_META_usernameEnv: "", + solace_META_passwordEnv: "", + solace_META_username: soltest_VALID_USERNAME, + solace_META_password: soltest_VALID_PASSWORD, + solace_META_queueName: soltest_VALID_QUEUE_NAME, + solace_META_msgCountTarget: "0", + solace_META_msgSpoolUsageTarget: soltest_VALID_MSG_SPOOL_TARGET, + }, + false, + }, +} + +var testSolaceExpectedMetricNames = map[string]string{ + solace_SCALER_ID + "-" + soltest_VALID_VPN + "-" + soltest_VALID_QUEUE_NAME + "-" + "msgCount": "", + solace_SCALER_ID + "-" + soltest_VALID_VPN + "-" + soltest_VALID_QUEUE_NAME + "-" + "msgSpoolUsage": "", +} + +var testSolaceSEMPConnectionMetadata = []testSolaceMetadata{ + /* + IF brokerBaseUrl is present, use it without interpretation as the base URL: http://my.host.domain:1234 + IF brokerBaseUrl in not present, Use protocol, host, and port + */ + + // +Case - Should Connect (Base URL Provided) + { + "#301 - Connect w/ baseUrl + Clear Auth", + map[string]string{ + "": "", + solace_META_brokerBaseUrl: soltest_VALID_BASEURL, + solace_META_brokerProtocol: "", + solace_META_brokerHostname: "", + solace_META_brokerPort: "", + solace_META_msgVpn: soltest_VALID_VPN, + solace_META_usernameEnv: "", + solace_META_passwordEnv: "", + solace_META_username: soltest_VALID_USERNAME, + solace_META_password: soltest_VALID_PASSWORD, + solace_META_queueName: soltest_VALID_QUEUE_NAME, + solace_META_msgCountTarget: soltest_VALID_MSG_COUNT_TARGET, + }, + false, + }, + { + "#302 - Connect with invalid username", + map[string]string{ + solace_META_brokerBaseUrl: "", + solace_META_brokerProtocol: soltest_VALID_PROTOCOL, + solace_META_brokerHostname: soltest_VALID_HOSTNAME, + solace_META_brokerPort: soltest_VALID_PORT, + solace_META_username: "NOT_A_REAL_USER", + solace_META_password: soltest_VALID_PASSWORD, + solace_META_msgVpn: soltest_VALID_VPN, + solace_META_queueName: soltest_VALID_QUEUE_NAME, + solace_META_msgSpoolUsageTarget: soltest_VALID_MSG_SPOOL_TARGET, + }, + true, + }, + { + "#303 - Connect with invalid password", + map[string]string{ + solace_META_brokerBaseUrl: "", + solace_META_brokerProtocol: soltest_VALID_PROTOCOL, + solace_META_brokerHostname: soltest_VALID_HOSTNAME, + solace_META_brokerPort: soltest_VALID_PORT, + solace_META_username: soltest_VALID_USERNAME, + solace_META_password: "THIS_IS_NOT_MY_PASSWORD", + solace_META_msgVpn: soltest_VALID_VPN, + solace_META_queueName: soltest_VALID_QUEUE_NAME, + solace_META_msgCountTarget: soltest_VALID_MSG_COUNT_TARGET, + solace_META_msgSpoolUsageTarget: soltest_VALID_MSG_SPOOL_TARGET, + }, + true, + }, + // +Case - Should Connect (Derived Base URL) + { + "#304 - Connect with component URL + Env Var Auth", + map[string]string{ + solace_META_brokerBaseUrl: "", + solace_META_brokerProtocol: soltest_VALID_PROTOCOL, + solace_META_brokerHostname: soltest_VALID_HOSTNAME, + solace_META_brokerPort: soltest_VALID_PORT, + solace_META_msgVpn: soltest_VALID_VPN, + solace_META_usernameEnv: "", + solace_META_passwordEnv: "", + solace_META_username: soltest_VALID_USERNAME, + solace_META_password: soltest_VALID_PASSWORD, + solace_META_queueName: soltest_VALID_QUEUE_NAME, + solace_META_msgCountTarget: soltest_VALID_MSG_COUNT_TARGET, + }, + false, + }, + { + "#305 - Connect with component URL + K8S Auth Record", + map[string]string{ + solace_META_brokerBaseUrl: "", + solace_META_brokerProtocol: soltest_VALID_PROTOCOL, + solace_META_brokerHostname: soltest_VALID_HOSTNAME, + solace_META_brokerPort: soltest_VALID_PORT, + solace_META_msgVpn: soltest_VALID_VPN, + solace_META_usernameEnv: "", + solace_META_passwordEnv: "", + // solace_META_username: soltest_VALID_USERNAME, + // solace_META_password: soltest_VALID_PASSWORD, + solace_META_queueName: soltest_VALID_QUEUE_NAME, + solace_META_msgCountTarget: soltest_VALID_MSG_COUNT_TARGET, + }, + false, + }, + // -Case - Solace VPN DNE + { + "#306 - Solace VPN DNE", + map[string]string{ + solace_META_brokerBaseUrl: "", + solace_META_brokerProtocol: soltest_VALID_PROTOCOL, + solace_META_brokerHostname: soltest_VALID_HOSTNAME, + solace_META_brokerPort: soltest_VALID_PORT, + solace_META_msgVpn: "THIS_VPN_DOES_NOT_EXIST", + solace_META_usernameEnv: "", + solace_META_passwordEnv: "", + solace_META_username: soltest_VALID_USERNAME, + solace_META_password: soltest_VALID_PASSWORD, + solace_META_queueName: soltest_VALID_QUEUE_NAME, + solace_META_msgCountTarget: soltest_VALID_MSG_COUNT_TARGET, + }, + true, + }, + // -Case - Queue DNE + { + "#307 - Solace Queue DNE", + map[string]string{ + solace_META_brokerBaseUrl: "", + solace_META_brokerProtocol: soltest_VALID_PROTOCOL, + solace_META_brokerHostname: soltest_VALID_HOSTNAME, + solace_META_brokerPort: soltest_VALID_PORT, + solace_META_msgVpn: soltest_VALID_VPN, + solace_META_usernameEnv: "", + solace_META_passwordEnv: "", + solace_META_username: soltest_VALID_USERNAME, + solace_META_password: soltest_VALID_PASSWORD, + solace_META_queueName: "THIS_QUEUE_DOES_NOT_EXIST", + solace_META_msgCountTarget: soltest_VALID_MSG_COUNT_TARGET, + }, + true, + }, + // -Case - Bad baseUrl + { + "#308 - Bad Base URL", + map[string]string{ + solace_META_brokerBaseUrl: "http://not-a-real-server.nothing:999", + solace_META_brokerProtocol: "", + solace_META_brokerHostname: "", + solace_META_brokerPort: "", + solace_META_msgVpn: soltest_VALID_VPN, + solace_META_usernameEnv: "", + solace_META_passwordEnv: "", + solace_META_username: soltest_VALID_USERNAME, + solace_META_password: soltest_VALID_PASSWORD, + solace_META_queueName: soltest_VALID_QUEUE_NAME, + solace_META_msgCountTarget: soltest_VALID_MSG_COUNT_TARGET, + }, + true, + }, +} + +func TestSolaceParseSolaceMetadata(t *testing.T) { + for _, testData := range testParseSolaceMetadata { + fmt.Print(testData.testId) + _, err := parseSolaceMetadata(&ScalerConfig{ResolvedEnv: nil, TriggerMetadata: testData.metadata, AuthParams: nil}) + if err != nil && !testData.isError { + t.Error("Expected success but got error: ", err) + fmt.Println(" --> FAIL") + } else if testData.isError && err == nil { + t.Error("Expected error but got success") + fmt.Println(" --> FAIL") + } else { + fmt.Println(" --> PASS") + } + } + for _, testData := range testSolaceEnvCreds { + fmt.Print(testData.testId) + _, err := parseSolaceMetadata(&ScalerConfig{ResolvedEnv: testDataSolaceResolvedEnvVALID, TriggerMetadata: testData.metadata, AuthParams: nil}) + if err != nil && !testData.isError { + t.Error("Expected success but got error: ", err) + fmt.Println(" --> FAIL") + } else if testData.isError && err == nil { + t.Error("Expected error but got success") + fmt.Println(" --> FAIL") + } else { + fmt.Println(" --> PASS") + } + } + for _, testData := range testSolaceK8sSecretCreds { + fmt.Print(testData.testId) + _, err := parseSolaceMetadata(&ScalerConfig{ResolvedEnv: nil, TriggerMetadata: testData.metadata, AuthParams: testDataSolaceAuthParamsVALID}) + if err != nil && !testData.isError { + t.Error("Expected success but result is error: ", err) + fmt.Println(" --> FAIL") + } else if testData.isError && err == nil { + t.Error("Expected error but result is success") + fmt.Println(" --> FAIL") + } else { + fmt.Println(" --> PASS") + } + } +} + +func TestSolaceGetMetricSpec(t *testing.T) { + for idx := 0; idx < len(testSolaceGetMetricSpecData); idx++ { + + testData := testSolaceGetMetricSpecData[idx] + fmt.Print(testData.testId) + var err error + var solaceMeta *SolaceMetadata + if idx == 0 { + // The first instance will have nil ResolvedEnv and AuthParams -- for Clear Auth + solaceMeta, err = parseSolaceMetadata(&ScalerConfig{ResolvedEnv: nil, TriggerMetadata: testData.metadata, AuthParams: nil}) + } else { + // The first instance will have nil ResolvedEnv and AuthParams -- for Clear Auth + solaceMeta, err = parseSolaceMetadata(&ScalerConfig{ResolvedEnv: testDataSolaceResolvedEnvVALID, TriggerMetadata: testData.metadata, AuthParams: testDataSolaceAuthParamsVALID}) + } + if err != nil { + fmt.Printf("\n Failed to parse metadata: %v", err) + // t.Error("Failed to parse metadata: ", err) + } else { + + // fmt.Println("Here") + // fmt.Println(solaceMeta.brokerBaseUrl) + // fmt.Printf("%v\n", solaceMeta.msgCountTarget) + + // var startTime metav1.Time = metav1.Now() + // startTime.Time.Add(time.Duration(-2) * time.Second) + + // DECLARE SCALER AND RUN METHOD TO GET METRICS + testSolaceScaler := SolaceScaler{ + metadata: solaceMeta, + httpClient: http.DefaultClient, + } + + var metric []v2beta2.MetricSpec + if metric = testSolaceScaler.GetMetricSpecForScaling(); metric == nil || len(metric) == 0 { + t.Error("Metric value not found") + } + metricName := metric[0].External.Metric.Name + metricValue := metric[0].External.Target.AverageValue + if _, ok := testSolaceExpectedMetricNames[metricName]; ok == false { + t.Error("Expected Metric value not found") + } + + fmt.Printf("\n Found Metric: %s=%v", metricName, metricValue) + } + + if testData.isError && err == nil { + fmt.Println(" --> FAIL") + t.Error("Expected to fail but passed", err) + } else if !testData.isError && err != nil { + t.Error("Expected success but failed", err) + } else { + fmt.Println(" --> PASS") + } + + } +} + +func TestSolaceSEMPConnection(t *testing.T) { + for idx := 0; idx < len(testSolaceSEMPConnectionMetadata); idx++ { + + testData := testSolaceSEMPConnectionMetadata[idx] + fmt.Print(testData.testId) + var err error + var solaceMeta *SolaceMetadata + if idx < 3 { + // The first instance will have nil ResolvedEnv and AuthParams -- for Clear Auth + solaceMeta, err = parseSolaceMetadata(&ScalerConfig{ResolvedEnv: nil, TriggerMetadata: testData.metadata, AuthParams: nil}) + } else { + // The first instance will have nil ResolvedEnv and AuthParams -- for Clear Auth + solaceMeta, err = parseSolaceMetadata(&ScalerConfig{ResolvedEnv: testDataSolaceResolvedEnvVALID, TriggerMetadata: testData.metadata, AuthParams: testDataSolaceAuthParamsVALID}) + } + if err != nil { + t.Fatal("FAILED to parse metadata: ", err) + } + + testSolaceScaler := SolaceScaler{ + metadata: solaceMeta, + httpClient: http.DefaultClient, + } + + val, err := testSolaceScaler.getSolaceQueueMetricsFromSEMP() + + if testData.isError && err == nil { + fmt.Println(" --> FAIL") + t.Error("Expected to fail but passed", err) + } else if !testData.isError && err != nil { + fmt.Println(" --> FAIL: Connection to SEMP Failed") + t.Error("Expected successful connection to SEMP Failed", err) + } else { + fmt.Printf(" --> PASS") + if val.msgCount > 0 { + fmt.Printf("; msgCount=%d", val.msgCount) + } + if val.msgSpoolUsage > 0 { + fmt.Printf("; msgSpoolUsage=%d", val.msgSpoolUsage) + } + fmt.Println() + } + } +} diff --git a/pkg/scaling/scale_handler.go b/pkg/scaling/scale_handler.go index 1c1e7fe027d..26e30415a51 100644 --- a/pkg/scaling/scale_handler.go +++ b/pkg/scaling/scale_handler.go @@ -446,6 +446,8 @@ func buildScaler(triggerType string, config *scalers.ScalerConfig) (scalers.Scal return scalers.NewRedisStreamsScaler(true, config) case "redis-streams": return scalers.NewRedisStreamsScaler(false, config) + case "solace-queue": + return scalers.NewSolaceScaler(config) case "stan": return scalers.NewStanScaler(config) default: diff --git a/tests/scalers/solace-helpers.ts b/tests/scalers/solace-helpers.ts new file mode 100644 index 00000000000..8745e3436b3 --- /dev/null +++ b/tests/scalers/solace-helpers.ts @@ -0,0 +1,240 @@ +import * as sh from 'shelljs' +import * as tmp from 'tmp' +import * as fs from 'fs' + +export class SolaceHelper { + + static getUpdateSolaceHelmChart(t) { + t.is( + 0, + sh.exec(`helm repo add solacecharts https://solaceproducts.github.io/pubsubplus-kubernetes-quickstart/helm-charts`).code, + 'Should retrieve Solace Helm Chart from Repo' + ) + t.is( + 0, + sh.exec(`helm repo update`).code, + 'Should update Helm Charts' + ) + } + + static installSolaceBroker(t, testNamespace: string) { + t.is( + 0, + sh.exec(`kubectl create namespace ${testNamespace}`).code, 'Should create solace namespace' + ) + t.is( + 0, + sh.exec(`helm install kedalab solacecharts/pubsubplus-dev --namespace ${testNamespace} --set solace.usernameAdminPassword=KedaLabAdminPwd1 --set storage.persistent=false`).code, 'Solace Broker should install' + ) + sh.exec('sleep 2s') + t.is( + 0, + sh.exec(`kubectl -n ${testNamespace} wait --for=condition=Ready --timeout=120s pod/kedalab-pubsubplus-dev-0`).code, 'Solace should be available.' + ) + sh.exec('sleep 2s') + } + + static installSolaceTestHelper(t, testNamespace: string) { + const tmpFile = tmp.fileSync() + fs.writeFileSync(tmpFile.name, solaceTestHelperYaml) + t.is( + 0, + sh.exec(`kubectl apply -f ${tmpFile.name}`).code, 'creating test helper pod should work' + ) + t.is( + 0, + sh.exec(`kubectl -n ${testNamespace} wait --for=condition=Ready --timeout=120s pod/kedalab-helper`).code, 'kedalab-helper should be available' + ) + sh.exec('sleep 5s') + } + + static configSolacePubSubBroker(t, testNamespace: string) { + t.is( + 0, + sh.exec(`kubectl exec -n ${testNamespace} kedalab-helper -- ./config/config_solace.sh`).code, 'should be able to configure Solace PubSub Broker' + ) + } + + static installSolaceConsumer(t) { + const tmpFile = tmp.fileSync() + fs.writeFileSync(tmpFile.name, solaceConsumerYaml) + t.is( + 0, + sh.exec(`kubectl apply -f ${tmpFile.name}`).code, 'create solace-consumer deployment should work.' + ) + sh.exec('sleep 10s') + } + + static installSolaceKedaSecret(t) { + const tmpFile = tmp.fileSync() + fs.writeFileSync(tmpFile.name, solaceKedaSecretYaml) + sh.exec(`kubectl apply -f ${tmpFile.name}`).code, 'creating secret should work.' + } + + static installSolaceKedaTriggerAuth(t) { + const tmpFile = tmp.fileSync() + fs.writeFileSync(tmpFile.name, solaceKedaTriggerAuthYaml) + sh.exec(`kubectl apply -f ${tmpFile.name}`).code, 'creating scaled object should work.' + } + + static installSolaceKedaScaledObject(t) { + const tmpFile = tmp.fileSync() + fs.writeFileSync(tmpFile.name, solaceKedaScaledObjectYaml) + sh.exec(`kubectl apply -f ${tmpFile.name}`).code, 'creating scaled object should work.' + } + + static publishMessages(t, testNamespace: string, messageRate: string, messageNumber: string) { + t.is( + 0, + sh.exec(`kubectl exec -n ${testNamespace} kedalab-helper -- ./sdkperf/sdkperf_java.sh -cip=kedalab-pubsubplus-dev:55555 -cu consumer_user@keda_vpn -cp=consumer_pwd -mr ${messageRate} -mn ${messageNumber} -mt=persistent -pql=SCALED_CONSUMER_QUEUE1`).code, 'creating solace producer deployment should work.' + ) + } + + static uninstallSolaceKedaObjects(t){ + const tmpFile = tmp.fileSync() + fs.writeFileSync(tmpFile.name, solaceKedaScaledObjectYaml) + sh.exec(`kubectl delete -f ${tmpFile.name}`) + fs.writeFileSync(tmpFile.name, solaceKedaTriggerAuthYaml) + sh.exec(`kubectl delete -f ${tmpFile.name}`) + fs.writeFileSync(tmpFile.name, solaceKedaSecretYaml) + sh.exec(`kubectl delete -f ${tmpFile.name}`) + } + + static uninstallSolaceTestPods(t) { + const tmpFile = tmp.fileSync() + fs.writeFileSync(tmpFile.name, solaceConsumerYaml) + sh.exec(`kubectl delete -f ${tmpFile.name}`) + fs.writeFileSync(tmpFile.name, solaceTestHelperYaml) + sh.exec(`kubectl delete -f ${tmpFile.name}`) + } + + static uninstallSolace(t, solaceNamespace: string){ + sh.exec(`helm uninstall kedalab --namespace=${solaceNamespace}`) + sh.exec(`sleep 6s`) + sh.exec(`kubectl delete namespace ${solaceNamespace}`) + } +} + +const solaceKedaScaledObjectYaml = ` +apiVersion: keda.sh/v1alpha1 +kind: ScaledObject +metadata: + name: kedalab-scaled-object + namespace: solace +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: solace-consumer + pollingInterval: 5 + cooldownPeriod: 20 + minReplicaCount: 0 + maxReplicaCount: 10 + advanced: + horizontalPodAutoscalerConfig: + behavior: + scaleDown: + stabilizationWindowSeconds: 0 + policies: + - type: Percent + value: 100 + periodSeconds: 10 + scaleUp: + stabilizationWindowSeconds: 0 + policies: + - type: Pods + value: 10 + periodSeconds: 10 + selectPolicy: Max + triggers: + - type: solace-queue + metadata: + brokerBaseUrl: http://kedalab-pubsubplus-dev.solace.svc.cluster.local:8080 + msgVpn: keda_vpn + queueName: SCALED_CONSUMER_QUEUE1 + msgCountTarget: '20' + msgSpoolUsageTarget: '100000' + authenticationRef: + name: kedalab-trigger-auth +` + +const solaceKedaTriggerAuthYaml = ` +apiVersion: keda.sh/v1alpha1 +kind: TriggerAuthentication +metadata: + name: kedalab-trigger-auth + namespace: solace +spec: + secretTargetRef: + - parameter: username + name: kedalab-solace-secret + key: SEMP_USER + - parameter: password + name: kedalab-solace-secret + key: SEMP_PASSWORD +` + +const solaceKedaSecretYaml = ` +apiVersion: v1 +kind: Secret +metadata: + name: kedalab-solace-secret + namespace: solace + labels: + app: solace-consumer +type: Opaque +data: + SEMP_USER: YWRtaW4= + SEMP_PASSWORD: S2VkYUxhYkFkbWluUHdkMQ== +` + +const solaceConsumerYaml = ` +apiVersion: apps/v1 +kind: Deployment +metadata: + name: solace-consumer + namespace: solace +spec: + selector: + matchLabels: + app: web + template: + metadata: + labels: + app: web + name: docker-test-pod + spec: + containers: + - name: solace-jms-consumer + image: ghcr.io/solacelabs/kedalab-consumer:latest + env: + - name: SOLACE_CLIENT_HOST + value: tcp://kedalab-pubsubplus-dev:55555 + - name: SOLACE_CLIENT_MSGVPN + value: keda_vpn + - name: SOLACE_CLIENT_USERNAME + value: consumer_user + - name: SOLACE_CLIENT_PASSWORD + value: consumer_pwd + - name: SOLACE_CLIENT_QUEUENAME + value: SCALED_CONSUMER_QUEUE1 + - name: SOLACE_CLIENT_CONSUMER_DELAY + value: '1000' + imagePullPolicy: Always + restartPolicy: Always +` + +const solaceTestHelperYaml = ` +apiVersion: v1 +kind: Pod +metadata: + name: kedalab-helper + namespace: solace +spec: + containers: + - name: sdk-perf + image: ghcr.io/solacelabs/kedalab-helper:latest + # Just spin & wait forever + command: [ "/bin/bash", "-c", "--" ] + args: [ "while true; do sleep 10; done;" ] +` diff --git a/tests/scalers/solace.tests.ts b/tests/scalers/solace.tests.ts new file mode 100644 index 00000000000..01b4b9a9e9e --- /dev/null +++ b/tests/scalers/solace.tests.ts @@ -0,0 +1,96 @@ +import * as async from 'async' +import * as fs from 'fs' +import * as sh from 'shelljs' +import * as tmp from 'tmp' +import test from 'ava' +import { SolaceHelper } from './solace-helpers' + +const testNamespace = 'solace' +const queueName = 'test' +const username = "artemis" +const password = "artemis" + +test.before(t => { + sh.config.silent = true + SolaceHelper.getUpdateSolaceHelmChart(t) + SolaceHelper.installSolaceBroker(t, testNamespace) + SolaceHelper.installSolaceTestHelper(t, testNamespace) + SolaceHelper.configSolacePubSubBroker(t, testNamespace) + SolaceHelper.installSolaceConsumer(t) +}); + +test.serial('#1 Consumer Deployment should have 1 replicas on start', t => { + let replicas = sh.exec(`kubectl get deployment.apps/solace-consumer --namespace ${testNamespace} -o jsonpath="{.spec.replicas}"`).stdout + + t.log('replica count: ' + replicas); + t.is(replicas, '1', 'replica count should start out as 1') +}) + +test.serial('#2 Create Scaled Object; Consumer Deployment replicas scale to zero', t => { + // deploy scaler and auth objects + SolaceHelper.installSolaceKedaSecret(t) + SolaceHelper.installSolaceKedaTriggerAuth(t) + SolaceHelper.installSolaceKedaScaledObject(t) + + let replicas = '1' + for (let i = 0; i <= 20 && replicas !== '10'; i++) { + replicas = sh.exec(`kubectl get deployment.apps/solace-consumer --namespace ${testNamespace} -o jsonpath="{.spec.replicas}"`).stdout + t.log('pod replicas (of 0 expected): ' + replicas) + if (replicas !== '0') { + sh.exec('sleep 3s') + } else { + t.log('scale to zero goal met') +// t.log('scale to zero goal met; delay to allow pod time to terminate') +// sh.exec('sleep 10s') + break + } + } + + t.is('0', replicas, 'Replica count should be 0 after 60 seconds') + }) + +test.serial('#3 Publish 400 messages to Consumer Queue; Scale Replicas to 10', t => { + // publish messages to queue -- 500 msgs at 50 msgs/sec + SolaceHelper.publishMessages(t, testNamespace, '50', '400') + + // with messages published, the consumer deployment should start receiving the messages + let replicas = '0' + for (let i = 0; i < 15 && replicas !== '10'; i++) { + replicas = sh.exec(`kubectl get deployment.apps/solace-consumer --namespace ${testNamespace} -o jsonpath="{.spec.replicas}"`).stdout + t.log('pod replicas (of 10 expected): ' + replicas) + if (replicas !== '10') { + sh.exec('sleep 4s') + } else { + t.log('max pod replica count goal met') + break + } + } + + t.is('10', replicas, 'Replica count should be 10 after 60 seconds') +}) + +test.serial('#4 Consumer Deployment scales to zero replicas after all messages read', t => { + + let replicas = '10' + + // Replicas should decrease as messages are consumed + for (let i = 0; i < 60 && replicas !== '0'; i++) { + replicas = sh.exec(`kubectl get deployment.apps/solace-consumer --namespace ${testNamespace} -o jsonpath="{.spec.replicas}"`).stdout + t.log('pod replicas (of 0 expected): ' + replicas) + if (replicas !== '0') { + sh.exec('sleep 5s') + } else { + t.log('min pod replica count goal met (scale to zero)') + break + } + } + + t.is('0', replicas, 'Replica count should be 0 after 5 minutes') +}) + +test.after.always.cb('clean up the cluster', t => { + SolaceHelper.uninstallSolaceKedaObjects(t) + SolaceHelper.uninstallSolaceTestPods(t) + SolaceHelper.uninstallSolace(t, testNamespace) + t.end() +}) From 62cd11b81f798f1dac504f43b559267916590a20 Mon Sep 17 00:00:00 2001 From: Dennis Brinley Date: Fri, 9 Jul 2021 16:33:58 -0400 Subject: [PATCH 2/7] Missed some cleanup in previous commit -- deleted unnecessary lines and comments Applies to solace_scaler tests Signed-off-by: Dennis Brinley By making a contribution to this project, I certify that: (a) The contribution was created in whole or in part by me and I have the right to submit it under the open source license indicated in the file; or (b) The contribution is based upon previous work that, to the best of my knowledge, is covered under an appropriate open source license and I have the right under that license to submit that work with modifications, whether created in whole or in part by me, under the same open source license (unless I am permitted to submit under a different license), as indicated in the file; or (c) The contribution was provided directly to me by some other person who certified (a), (b) or (c) and I have not modified it. (d) I understand and agree that this project and the contribution are public and that a record of the contribution (including all personal information I submit with it, including my sign-off) is maintained indefinitely and may be redistributed consistent with this project or the open source license(s) involved. --- pkg/scalers/solace_scaler_test.go | 22 ++++------------------ tests/scalers/solace.tests.ts | 8 +++----- 2 files changed, 7 insertions(+), 23 deletions(-) diff --git a/pkg/scalers/solace_scaler_test.go b/pkg/scalers/solace_scaler_test.go index 5a8a68d4c5e..8e78f132a23 100644 --- a/pkg/scalers/solace_scaler_test.go +++ b/pkg/scalers/solace_scaler_test.go @@ -20,15 +20,10 @@ type testSolaceMetricIdentifier struct { } var ( - soltest_VALID_BASEURL = "http://localhost:8080" - soltest_VALID_PROTOCOL = "http" - soltest_VALID_HOSTNAME = "localhost" - soltest_VALID_PORT = "8080" - // ##### TODO -- RESET THIS - // soltest_VALID_USERNAME = "solace_user" - // soltest_VALID_PASSWORD = "solace_pass" - // soltest_VALID_VPN = "solace_keda_vpn" - // soltest_VALID_QUEUE_NAME = "KEDA_Q1" + soltest_VALID_BASEURL = "http://localhost:8080" + soltest_VALID_PROTOCOL = "http" + soltest_VALID_HOSTNAME = "localhost" + soltest_VALID_PORT = "8080" soltest_VALID_USERNAME = "admin" soltest_VALID_PASSWORD = "admin" soltest_VALID_VPN = "dennis_vpn" @@ -726,16 +721,7 @@ func TestSolaceGetMetricSpec(t *testing.T) { } if err != nil { fmt.Printf("\n Failed to parse metadata: %v", err) - // t.Error("Failed to parse metadata: ", err) } else { - - // fmt.Println("Here") - // fmt.Println(solaceMeta.brokerBaseUrl) - // fmt.Printf("%v\n", solaceMeta.msgCountTarget) - - // var startTime metav1.Time = metav1.Now() - // startTime.Time.Add(time.Duration(-2) * time.Second) - // DECLARE SCALER AND RUN METHOD TO GET METRICS testSolaceScaler := SolaceScaler{ metadata: solaceMeta, diff --git a/tests/scalers/solace.tests.ts b/tests/scalers/solace.tests.ts index 01b4b9a9e9e..f6b2ece8a61 100644 --- a/tests/scalers/solace.tests.ts +++ b/tests/scalers/solace.tests.ts @@ -1,14 +1,12 @@ -import * as async from 'async' -import * as fs from 'fs' +//import * as async from 'async' +//import * as fs from 'fs' import * as sh from 'shelljs' -import * as tmp from 'tmp' +//import * as tmp from 'tmp' import test from 'ava' import { SolaceHelper } from './solace-helpers' const testNamespace = 'solace' const queueName = 'test' -const username = "artemis" -const password = "artemis" test.before(t => { sh.config.silent = true From 5ca995a460027546aca0229aaa9f8853ae717562 Mon Sep 17 00:00:00 2001 From: Dennis Brinley Date: Mon, 12 Jul 2021 11:23:29 -0400 Subject: [PATCH 3/7] Corrected linting errors and cleanup Signed-off-by: Dennis Brinley By making a contribution to this project, I certify that: (a) The contribution was created in whole or in part by me and I have the right to submit it under the open source license indicated in the file; or (b) The contribution is based upon previous work that, to the best of my knowledge, is covered under an appropriate open source license and I have the right under that license to submit that work with modifications, whether created in whole or in part by me, under the same open source license (unless I am permitted to submit under a different license), as indicated in the file; or (c) The contribution was provided directly to me by some other person who certified (a), (b) or (c) and I have not modified it. (d) I understand and agree that this project and the contribution are public and that a record of the contribution (including all personal information I submit with it, including my sign-off) is maintained indefinitely and may be redistributed consistent with this project or the open source license(s) involved. --- pkg/scalers/solace_scaler.go | 132 +++-- pkg/scalers/solace_scaler_test.go | 833 +++++++++++------------------- tests/scalers/solace.tests.ts | 3 - 3 files changed, 380 insertions(+), 588 deletions(-) diff --git a/pkg/scalers/solace_scaler.go b/pkg/scalers/solace_scaler.go index 3663befff23..fd4fb5f85d3 100644 --- a/pkg/scalers/solace_scaler.go +++ b/pkg/scalers/solace_scaler.go @@ -19,42 +19,41 @@ import ( ) const ( - solace_EXT_METRIC_TYPE = "External" - solace_SCALER_ID = "solace" + solaceExtMetricType = "External" + solaceScalerId = "solace" // REST ENDPOINT String Patterns - solace_BROKER_BASE_URL_TEMPLATE = "%s://%s:%s" - solace_SEMP_ENDPOINT_URL_TEMPLATE = "%s/%s/%s/monitor/msgVpns/%s/%ss/%s" + solaceBrokerBaseUrlTemplate = "%s://%s:%s" + solaceSempEndpointUrlTemplate = "%s/%s/%s/monitor/msgVpns/%s/%ss/%s" // SEMP REST API Context - solace_API_NAME = "SEMP" - solace_API_VERSION = "v2" - solace_API_DFLT_OBJ_TYPE = "queue" + solaceApiName = "SEMP" + solaceApiVersion = "v2" + solaceApiObjectTypeQueue = "queue" // Log Message Templates - solace_FOUND_META_TRUE = "Field %s Found in Solace Metadata; Value=%v" - solace_FOUND_META_FALSE = "Required Field %s NOT FOUND in Solace Metadata" + solaceFoundMetaFalse = "Required Field %s NOT FOUND in Solace Metadata" // YAML Configuration Metadata Field Names // Broker Identifiers - solace_META_brokerBaseUrl = "brokerBaseUrl" - solace_META_brokerProtocol = "brokerProtocol" - solace_META_brokerHostname = "brokerHostname" - solace_META_brokerPort = "brokerPort" + solaceMetaBrokerBaseUrl = "brokerBaseUrl" + solaceMetaBrokerProtocol = "brokerProtocol" + solaceMetaBrokerHostname = "brokerHostname" + solaceMetaBrokerPort = "brokerPort" // Credential Identifiers - solace_META_username = "username" - solace_META_password = "password" - solace_META_usernameEnv = "usernameEnv" - solace_META_passwordEnv = "passwordEnv" + solaceMetaUsername = "username" + solaceMetaPassword = "password" + solaceMetaUsernameEnv = "usernameEnv" + solaceMetaPasswordEnv = "passwordEnv" // Target Object Identifiers - solace_META_msgVpn = "msgVpn" - solace_META_queueName = "queueName" + solaceMetamsgVpn = "msgVpn" + solaceMetaqueueName = "queueName" // Metric Targets - solace_META_msgCountTarget = "msgCountTarget" - solace_META_msgSpoolUsageTarget = "msgSpoolUsageTarget" + solaceMetamsgCountTarget = "msgCountTarget" + solaceMetamsgSpoolUsageTarget = "msgSpoolUsageTarget" // Trigger type identifiers - solace_TRIG_msgcount = "msgcount" - solace_TRIG_msgspoolusage = "msgspoolusage" + solaceTriggermsgcount = "msgcount" + solaceTriggermsgspoolusage = "msgspoolusage" ) // Struct for Observed Metric Values @@ -118,7 +117,7 @@ type solaceSEMPMetadata struct { } // Solace Logger -var solaceLog = logf.Log.WithName(solace_SCALER_ID + "_scaler") +var solaceLog = logf.Log.WithName(solaceScalerId + "_scaler") // Constructor for SolaceScaler func NewSolaceScaler(config *ScalerConfig) (Scaler, error) { @@ -130,7 +129,7 @@ func NewSolaceScaler(config *ScalerConfig) (Scaler, error) { solaceMetadata, err := parseSolaceMetadata(config) if err != nil { solaceLog.Error(err, "Error parsing Solace Trigger Metadata or missing values") - return nil, err //fmt.Errorf("Error parsing Solace Trigger metadata: %s", err) + return nil, err } return &SolaceScaler{ @@ -145,65 +144,65 @@ func parseSolaceMetadata(config *ScalerConfig) (*SolaceMetadata, error) { // GET THE SEMP API ENDPOINT // First look for brokerBaseUrl in config; Use components if not found - if val, ok := config.TriggerMetadata[solace_META_brokerBaseUrl]; ok && val != "" { + if val, ok := config.TriggerMetadata[solaceMetaBrokerBaseUrl]; ok && val != "" { meta.brokerBaseUrl = val } else { // IF brokerBaseUrl is not present, then get components // GET Protocol - if val, ok := config.TriggerMetadata[solace_META_brokerProtocol]; ok && (val == "https" || val == "http") { + if val, ok := config.TriggerMetadata[solaceMetaBrokerProtocol]; ok && (val == "https" || val == "http") { meta.brokerProtocol = val } else { - return nil, fmt.Errorf(solace_FOUND_META_FALSE, solace_META_brokerProtocol) + return nil, fmt.Errorf(solaceFoundMetaFalse, solaceMetaBrokerProtocol) } // GET Hostname - if val, ok := config.TriggerMetadata[solace_META_brokerHostname]; ok && val != "" { + if val, ok := config.TriggerMetadata[solaceMetaBrokerHostname]; ok && val != "" { meta.brokerHostname = val } else { - return nil, fmt.Errorf(solace_FOUND_META_FALSE, solace_META_brokerHostname) + return nil, fmt.Errorf(solaceFoundMetaFalse, solaceMetaBrokerHostname) } // GET Port - if val, ok := config.TriggerMetadata[solace_META_brokerPort]; ok && val != "" { + if val, ok := config.TriggerMetadata[solaceMetaBrokerPort]; ok && val != "" { if _, err := strconv.Atoi(val); err == nil { meta.brokerPort = val } else { return nil, fmt.Errorf("Can't parse brokerPort, not a valid integer: %s", err) } } else { - return nil, fmt.Errorf(solace_FOUND_META_FALSE, solace_META_brokerPort) + return nil, fmt.Errorf(solaceFoundMetaFalse, solaceMetaBrokerPort) } // Format Solace Broker Base URL from components - meta.brokerBaseUrl = fmt.Sprintf(solace_BROKER_BASE_URL_TEMPLATE, meta.brokerProtocol, meta.brokerHostname, meta.brokerPort) + meta.brokerBaseUrl = fmt.Sprintf(solaceBrokerBaseUrlTemplate, meta.brokerProtocol, meta.brokerHostname, meta.brokerPort) } // GET Message VPN - if val, ok := config.TriggerMetadata[solace_META_msgVpn]; ok && val != "" { + if val, ok := config.TriggerMetadata[solaceMetamsgVpn]; ok && val != "" { meta.messageVpn = val } else { - return nil, fmt.Errorf(solace_FOUND_META_FALSE, solace_META_msgVpn) + return nil, fmt.Errorf(solaceFoundMetaFalse, solaceMetamsgVpn) } // GET Queue Name - if val, ok := config.TriggerMetadata[solace_META_queueName]; ok && val != "" { + if val, ok := config.TriggerMetadata[solaceMetaqueueName]; ok && val != "" { meta.queueName = val } else { - return nil, fmt.Errorf(solace_FOUND_META_FALSE, solace_META_queueName) + return nil, fmt.Errorf(solaceFoundMetaFalse, solaceMetaqueueName) } // GET METRIC TARGET VALUES // GET msgCountTarget - if val, ok := config.TriggerMetadata[solace_META_msgCountTarget]; ok && val != "" { + if val, ok := config.TriggerMetadata[solaceMetamsgCountTarget]; ok && val != "" { if msgCount, err := strconv.Atoi(val); err == nil { meta.msgCountTarget = msgCount } else { - return nil, fmt.Errorf("Can't parse [%s], not a valid integer: %s", solace_META_msgCountTarget, err) + return nil, fmt.Errorf("Can't parse [%s], not a valid integer: %s", solaceMetamsgCountTarget, err) } } // GET msgSpoolUsageTarget - if val, ok := config.TriggerMetadata[solace_META_msgSpoolUsageTarget]; ok && val != "" { + if val, ok := config.TriggerMetadata[solaceMetamsgSpoolUsageTarget]; ok && val != "" { if msgSpoolUsage, err := strconv.Atoi(val); err == nil { meta.msgSpoolUsageTarget = msgSpoolUsage } else { - return nil, fmt.Errorf("Can't parse [%s], not a valid integer: %s", solace_META_msgSpoolUsageTarget, err) + return nil, fmt.Errorf("Can't parse [%s], not a valid integer: %s", solaceMetamsgSpoolUsageTarget, err) } } @@ -214,45 +213,44 @@ func parseSolaceMetadata(config *ScalerConfig) (*SolaceMetadata, error) { // Format Solace SEMP Queue Endpoint (REST URL) meta.endpointUrl = fmt.Sprintf( - solace_SEMP_ENDPOINT_URL_TEMPLATE, + solaceSempEndpointUrlTemplate, meta.brokerBaseUrl, - solace_API_NAME, - solace_API_VERSION, + solaceApiName, + solaceApiVersion, meta.messageVpn, - solace_API_DFLT_OBJ_TYPE, + solaceApiObjectTypeQueue, meta.queueName) - /* GET CREDENTIALS - The username must be a valid broker ADMIN user identifier with read access to SEMP for the broker, VPN, and relevant objects - The scaler will attempt to acquire username and then password independently. For each: - - Search K8S Secret (Encoded) - - Search environment variable specified by config at 'usernameEnv' / 'passwordEnv' - - Search 'username' / 'password' fields (Clear Text) - */ + // GET CREDENTIALS + // The username must be a valid broker ADMIN user identifier with read access to SEMP for the broker, VPN, and relevant objects + // The scaler will attempt to acquire username and then password independently. For each: + // - Search K8S Secret (Encoded) + // - Search environment variable specified by config at 'usernameEnv' / 'passwordEnv' + // - Search 'username' / 'password' fields (Clear Text) // Get username - if usernameSecret, ok := config.AuthParams[solace_META_username]; ok && usernameSecret != "" { + if usernameSecret, ok := config.AuthParams[solaceMetaUsername]; ok && usernameSecret != "" { meta.username = usernameSecret - } else if usernameEnv, ok := config.TriggerMetadata[solace_META_usernameEnv]; ok && usernameEnv != "" { - if resolvedUser, ok := config.ResolvedEnv[config.TriggerMetadata[solace_META_usernameEnv]]; ok && resolvedUser != "" { + } else if usernameEnv, ok := config.TriggerMetadata[solaceMetaUsernameEnv]; ok && usernameEnv != "" { + if resolvedUser, ok := config.ResolvedEnv[config.TriggerMetadata[solaceMetaUsernameEnv]]; ok && resolvedUser != "" { meta.username = resolvedUser } else { return nil, fmt.Errorf("username could not be resolved from the environment variable: %s", usernameEnv) } - } else if usernameClear, ok := config.TriggerMetadata[solace_META_username]; ok && usernameClear != "" { + } else if usernameClear, ok := config.TriggerMetadata[solaceMetaUsername]; ok && usernameClear != "" { meta.username = usernameClear } else { return nil, fmt.Errorf("username is required and not found in K8Secret, environment, or clear text") } // Get Password - if passwordSecret, ok := config.AuthParams[solace_META_password]; ok && passwordSecret != "" { + if passwordSecret, ok := config.AuthParams[solaceMetaPassword]; ok && passwordSecret != "" { meta.password = passwordSecret - } else if passwordEnv, ok := config.TriggerMetadata[solace_META_passwordEnv]; ok && passwordEnv != "" { - if resolvedPassword, ok := config.ResolvedEnv[config.TriggerMetadata[solace_META_passwordEnv]]; ok && resolvedPassword != "" { + } else if passwordEnv, ok := config.TriggerMetadata[solaceMetaPasswordEnv]; ok && passwordEnv != "" { + if resolvedPassword, ok := config.ResolvedEnv[config.TriggerMetadata[solaceMetaPasswordEnv]]; ok && resolvedPassword != "" { meta.password = resolvedPassword } else { return nil, fmt.Errorf("password could not be resolved from the environment variable: %s", passwordEnv) } - } else if passwordClear, ok := config.TriggerMetadata[solace_META_password]; ok && passwordClear != "" { + } else if passwordClear, ok := config.TriggerMetadata[solaceMetaPassword]; ok && passwordClear != "" { meta.password = passwordClear } else { return nil, fmt.Errorf("password is required and not found in K8Secret, environment, or clear text") @@ -278,14 +276,14 @@ func (s *SolaceScaler) GetMetricSpecForScaling() []v2beta2.MetricSpec { targetMetricValue := resource.NewQuantity(int64(s.metadata.msgCountTarget), resource.DecimalSI) externalMetric := &v2beta2.ExternalMetricSource{ Metric: v2beta2.MetricIdentifier{ - Name: kedautil.NormalizeString(fmt.Sprintf("%s-%s-%s-%s", solace_SCALER_ID, s.metadata.messageVpn, s.metadata.queueName, solace_TRIG_msgcount)), + Name: kedautil.NormalizeString(fmt.Sprintf("%s-%s-%s-%s", solaceScalerId, s.metadata.messageVpn, s.metadata.queueName, solaceTriggermsgcount)), }, Target: v2beta2.MetricTarget{ Type: v2beta2.AverageValueMetricType, AverageValue: targetMetricValue, }, } - metricSpec := v2beta2.MetricSpec{External: externalMetric, Type: solace_EXT_METRIC_TYPE} + metricSpec := v2beta2.MetricSpec{External: externalMetric, Type: solaceExtMetricType} metricSpecList = append(metricSpecList, metricSpec) } // Message Spool Usage Target Spec @@ -293,14 +291,14 @@ func (s *SolaceScaler) GetMetricSpecForScaling() []v2beta2.MetricSpec { targetMetricValue := resource.NewQuantity(int64(s.metadata.msgSpoolUsageTarget), resource.DecimalSI) externalMetric := &v2beta2.ExternalMetricSource{ Metric: v2beta2.MetricIdentifier{ - Name: kedautil.NormalizeString(fmt.Sprintf("%s-%s-%s-%s", solace_SCALER_ID, s.metadata.messageVpn, s.metadata.queueName, solace_TRIG_msgspoolusage)), + Name: kedautil.NormalizeString(fmt.Sprintf("%s-%s-%s-%s", solaceScalerId, s.metadata.messageVpn, s.metadata.queueName, solaceTriggermsgspoolusage)), }, Target: v2beta2.MetricTarget{ Type: v2beta2.AverageValueMetricType, AverageValue: targetMetricValue, }, } - metricSpec := v2beta2.MetricSpec{External: externalMetric, Type: solace_EXT_METRIC_TYPE} + metricSpec := v2beta2.MetricSpec{External: externalMetric, Type: solaceExtMetricType} metricSpecList = append(metricSpecList, metricSpec) } return metricSpecList @@ -340,7 +338,7 @@ func (s *SolaceScaler) getSolaceQueueMetricsFromSEMP() (SolaceMetricValues, erro if err := json.NewDecoder(response.Body).Decode(&sempResponse); err != nil { return SolaceMetricValues{}, fmt.Errorf("Failed to read SEMP response body: %s", err) } - if sempResponse.Meta.ResponseCode < 200 && sempResponse.Meta.ResponseCode > 299 { + if sempResponse.Meta.ResponseCode < 200 || sempResponse.Meta.ResponseCode > 299 { return SolaceMetricValues{}, fmt.Errorf("Solace SEMP API returned error status: %d", sempResponse.Meta.ResponseCode) } @@ -365,13 +363,13 @@ func (s *SolaceScaler) GetMetrics(ctx context.Context, metricName string, metric var metric external_metrics.ExternalMetricValue switch { - case strings.HasSuffix(metricName, solace_TRIG_msgcount): + case strings.HasSuffix(metricName, solaceTriggermsgcount): metric = external_metrics.ExternalMetricValue{ MetricName: metricName, Value: *resource.NewQuantity(int64(metricValues.msgCount), resource.DecimalSI), Timestamp: metav1.Now(), } - case strings.HasSuffix(metricName, solace_TRIG_msgspoolusage): + case strings.HasSuffix(metricName, solaceTriggermsgspoolusage): metric = external_metrics.ExternalMetricValue{ MetricName: metricName, Value: *resource.NewQuantity(int64(metricValues.msgSpoolUsage), resource.DecimalSI), diff --git a/pkg/scalers/solace_scaler_test.go b/pkg/scalers/solace_scaler_test.go index 8e78f132a23..b7c0c4bd782 100644 --- a/pkg/scalers/solace_scaler_test.go +++ b/pkg/scalers/solace_scaler_test.go @@ -14,43 +14,38 @@ type testSolaceMetadata struct { isError bool } +/* type testSolaceMetricIdentifier struct { metadataTestData *testSolaceMetadata name string } - +*/ var ( - soltest_VALID_BASEURL = "http://localhost:8080" - soltest_VALID_PROTOCOL = "http" - soltest_VALID_HOSTNAME = "localhost" - soltest_VALID_PORT = "8080" - soltest_VALID_USERNAME = "admin" - soltest_VALID_PASSWORD = "admin" - soltest_VALID_VPN = "dennis_vpn" - soltest_VALID_QUEUE_NAME = "queue3" - soltest_VALID_MSG_COUNT_TARGET = "10" - soltest_VALID_MSG_SPOOL_TARGET = "20" - - soltest_ENVVAR_USERNAME = "SOLTEST_USERNAME" - soltest_ENVVAR_PASSWORD = "SOLTEST_PASSWORD" + soltestValidBaseUrl = "http://localhost:8080" + soltestValidProtocol = "http" + soltestValidHostname = "localhost" + soltestValidPort = "8080" + soltestValidUsername = "admin" + soltestValidPassword = "admin" + soltestValidVpn = "dennis_vpn" + soltestValidQueueName = "queue3" + soltestValidMsgCountTarget = "10" + soltestValidMsgSpoolTarget = "20" + + soltestEnvUsername = "SOLTEST_USERNAME" + soltestEnvPassword = "SOLTEST_PASSWORD" ) // AUTH RECORD FOR TEST var testDataSolaceAuthParamsVALID = map[string]string{ - solace_META_username: soltest_VALID_USERNAME, - solace_META_password: soltest_VALID_PASSWORD, + solaceMetaUsername: soltestValidUsername, + solaceMetaPassword: soltestValidPassword, } // ENV VARS FOR TEST -- VALID USER / PWD var testDataSolaceResolvedEnvVALID = map[string]string{ - soltest_ENVVAR_USERNAME: soltest_VALID_USERNAME, // Sets the environment variables to the correct values - soltest_ENVVAR_PASSWORD: soltest_VALID_PASSWORD, -} - -// ENV VARS FOR TEST -- INVALID USER / PWD -var testDataSolaceResolvedEnvINVALID = map[string]string{ - soltest_ENVVAR_USERNAME: "NOT_CORRECT_USERID", // Sets the environment variables to incorrect values - soltest_ENVVAR_PASSWORD: "NOT_A_PASSWORD", + soltestEnvUsername: soltestValidUsername, // Sets the environment variables to the correct values + soltestEnvPassword: soltestValidPassword, } // TEST CASES FOR SolaceParseMetadata() @@ -70,18 +65,18 @@ var testParseSolaceMetadata = []testSolaceMetadata{ { "#002 - brokerBaseUrl", map[string]string{ - "": "", - solace_META_brokerBaseUrl: soltest_VALID_BASEURL, - solace_META_brokerProtocol: "", - solace_META_brokerHostname: "", - solace_META_brokerPort: "", - solace_META_msgVpn: soltest_VALID_VPN, - solace_META_usernameEnv: "", - solace_META_passwordEnv: "", - solace_META_username: soltest_VALID_USERNAME, - solace_META_password: soltest_VALID_PASSWORD, - solace_META_queueName: soltest_VALID_QUEUE_NAME, - solace_META_msgCountTarget: soltest_VALID_MSG_COUNT_TARGET, + "": "", + solaceMetaBrokerBaseUrl: soltestValidBaseUrl, + solaceMetaBrokerProtocol: "", + solaceMetaBrokerHostname: "", + solaceMetaBrokerPort: "", + solaceMetamsgVpn: soltestValidVpn, + solaceMetaUsernameEnv: "", + solaceMetaPasswordEnv: "", + solaceMetaUsername: soltestValidUsername, + solaceMetaPassword: soltestValidPassword, + solaceMetaqueueName: soltestValidQueueName, + solaceMetamsgCountTarget: soltestValidMsgCountTarget, }, false, }, @@ -89,17 +84,17 @@ var testParseSolaceMetadata = []testSolaceMetadata{ { "#003 - protocol + host + port", map[string]string{ - solace_META_brokerBaseUrl: "", - solace_META_brokerProtocol: soltest_VALID_PROTOCOL, - solace_META_brokerHostname: soltest_VALID_HOSTNAME, - solace_META_brokerPort: soltest_VALID_PORT, - solace_META_msgVpn: soltest_VALID_VPN, - solace_META_usernameEnv: "", - solace_META_passwordEnv: "", - solace_META_username: soltest_VALID_USERNAME, - solace_META_password: soltest_VALID_PASSWORD, - solace_META_queueName: soltest_VALID_QUEUE_NAME, - solace_META_msgCountTarget: soltest_VALID_MSG_COUNT_TARGET, + solaceMetaBrokerBaseUrl: "", + solaceMetaBrokerProtocol: soltestValidProtocol, + solaceMetaBrokerHostname: soltestValidHostname, + solaceMetaBrokerPort: soltestValidPort, + solaceMetamsgVpn: soltestValidVpn, + solaceMetaUsernameEnv: "", + solaceMetaPasswordEnv: "", + solaceMetaUsername: soltestValidUsername, + solaceMetaPassword: soltestValidPassword, + solaceMetaqueueName: soltestValidQueueName, + solaceMetamsgCountTarget: soltestValidMsgCountTarget, }, false, }, @@ -108,17 +103,17 @@ var testParseSolaceMetadata = []testSolaceMetadata{ { "#004 - missing protocol", map[string]string{ - solace_META_brokerBaseUrl: "", - solace_META_brokerProtocol: "", - solace_META_brokerHostname: soltest_VALID_HOSTNAME, - solace_META_brokerPort: soltest_VALID_PORT, - solace_META_msgVpn: soltest_VALID_VPN, - solace_META_usernameEnv: "", - solace_META_passwordEnv: "", - solace_META_username: soltest_VALID_USERNAME, - solace_META_password: soltest_VALID_PASSWORD, - solace_META_queueName: soltest_VALID_QUEUE_NAME, - solace_META_msgCountTarget: soltest_VALID_MSG_COUNT_TARGET, + solaceMetaBrokerBaseUrl: "", + solaceMetaBrokerProtocol: "", + solaceMetaBrokerHostname: soltestValidHostname, + solaceMetaBrokerPort: soltestValidPort, + solaceMetamsgVpn: soltestValidVpn, + solaceMetaUsernameEnv: "", + solaceMetaPasswordEnv: "", + solaceMetaUsername: soltestValidUsername, + solaceMetaPassword: soltestValidPassword, + solaceMetaqueueName: soltestValidQueueName, + solaceMetamsgCountTarget: soltestValidMsgCountTarget, }, true, }, @@ -126,17 +121,17 @@ var testParseSolaceMetadata = []testSolaceMetadata{ { "#005 - missing hostname", map[string]string{ - solace_META_brokerBaseUrl: "", - solace_META_brokerProtocol: soltest_VALID_PROTOCOL, - solace_META_brokerHostname: "", - solace_META_brokerPort: soltest_VALID_PORT, - solace_META_msgVpn: soltest_VALID_VPN, - solace_META_usernameEnv: "", - solace_META_passwordEnv: "", - solace_META_username: soltest_VALID_USERNAME, - solace_META_password: soltest_VALID_PASSWORD, - solace_META_queueName: soltest_VALID_QUEUE_NAME, - solace_META_msgCountTarget: soltest_VALID_MSG_COUNT_TARGET, + solaceMetaBrokerBaseUrl: "", + solaceMetaBrokerProtocol: soltestValidProtocol, + solaceMetaBrokerHostname: "", + solaceMetaBrokerPort: soltestValidPort, + solaceMetamsgVpn: soltestValidVpn, + solaceMetaUsernameEnv: "", + solaceMetaPasswordEnv: "", + solaceMetaUsername: soltestValidUsername, + solaceMetaPassword: soltestValidPassword, + solaceMetaqueueName: soltestValidQueueName, + solaceMetamsgCountTarget: soltestValidMsgCountTarget, }, true, }, @@ -144,17 +139,17 @@ var testParseSolaceMetadata = []testSolaceMetadata{ { "#006 - missing port", map[string]string{ - solace_META_brokerBaseUrl: "", - solace_META_brokerProtocol: soltest_VALID_PROTOCOL, - solace_META_brokerHostname: soltest_VALID_HOSTNAME, - solace_META_brokerPort: "", - solace_META_msgVpn: soltest_VALID_VPN, - solace_META_usernameEnv: "", - solace_META_passwordEnv: "", - solace_META_username: soltest_VALID_USERNAME, - solace_META_password: soltest_VALID_PASSWORD, - solace_META_queueName: soltest_VALID_QUEUE_NAME, - solace_META_msgCountTarget: soltest_VALID_MSG_COUNT_TARGET, + solaceMetaBrokerBaseUrl: "", + solaceMetaBrokerProtocol: soltestValidProtocol, + solaceMetaBrokerHostname: soltestValidHostname, + solaceMetaBrokerPort: "", + solaceMetamsgVpn: soltestValidVpn, + solaceMetaUsernameEnv: "", + solaceMetaPasswordEnv: "", + solaceMetaUsername: soltestValidUsername, + solaceMetaPassword: soltestValidPassword, + solaceMetaqueueName: soltestValidQueueName, + solaceMetamsgCountTarget: soltestValidMsgCountTarget, }, true, }, @@ -162,17 +157,17 @@ var testParseSolaceMetadata = []testSolaceMetadata{ { "#007 - missing username (clear)", map[string]string{ - solace_META_brokerBaseUrl: "", - solace_META_brokerProtocol: soltest_VALID_PROTOCOL, - solace_META_brokerHostname: soltest_VALID_HOSTNAME, - solace_META_brokerPort: soltest_VALID_PORT, - solace_META_msgVpn: soltest_VALID_VPN, - solace_META_usernameEnv: "", - solace_META_passwordEnv: "", - solace_META_username: "", - solace_META_password: soltest_VALID_PASSWORD, - solace_META_queueName: soltest_VALID_QUEUE_NAME, - solace_META_msgCountTarget: soltest_VALID_MSG_COUNT_TARGET, + solaceMetaBrokerBaseUrl: "", + solaceMetaBrokerProtocol: soltestValidProtocol, + solaceMetaBrokerHostname: soltestValidHostname, + solaceMetaBrokerPort: soltestValidPort, + solaceMetamsgVpn: soltestValidVpn, + solaceMetaUsernameEnv: "", + solaceMetaPasswordEnv: "", + solaceMetaUsername: "", + solaceMetaPassword: soltestValidPassword, + solaceMetaqueueName: soltestValidQueueName, + solaceMetamsgCountTarget: soltestValidMsgCountTarget, }, true, }, @@ -180,17 +175,17 @@ var testParseSolaceMetadata = []testSolaceMetadata{ { "#008 - missing password (clear)", map[string]string{ - solace_META_brokerBaseUrl: "", - solace_META_brokerProtocol: soltest_VALID_PROTOCOL, - solace_META_brokerHostname: soltest_VALID_HOSTNAME, - solace_META_brokerPort: soltest_VALID_PORT, - solace_META_msgVpn: soltest_VALID_VPN, - solace_META_usernameEnv: "", - solace_META_passwordEnv: "", - solace_META_username: soltest_VALID_USERNAME, - solace_META_password: "", - solace_META_queueName: soltest_VALID_QUEUE_NAME, - solace_META_msgCountTarget: soltest_VALID_MSG_COUNT_TARGET, + solaceMetaBrokerBaseUrl: "", + solaceMetaBrokerProtocol: soltestValidProtocol, + solaceMetaBrokerHostname: soltestValidHostname, + solaceMetaBrokerPort: soltestValidPort, + solaceMetamsgVpn: soltestValidVpn, + solaceMetaUsernameEnv: "", + solaceMetaPasswordEnv: "", + solaceMetaUsername: soltestValidUsername, + solaceMetaPassword: "", + solaceMetaqueueName: soltestValidQueueName, + solaceMetamsgCountTarget: soltestValidMsgCountTarget, }, true, }, @@ -198,17 +193,17 @@ var testParseSolaceMetadata = []testSolaceMetadata{ { "#009 - missing queueName", map[string]string{ - solace_META_brokerBaseUrl: "", - solace_META_brokerProtocol: soltest_VALID_PROTOCOL, - solace_META_brokerHostname: soltest_VALID_HOSTNAME, - solace_META_brokerPort: soltest_VALID_PORT, - solace_META_msgVpn: soltest_VALID_VPN, - solace_META_usernameEnv: "", - solace_META_passwordEnv: "", - solace_META_username: soltest_VALID_USERNAME, - solace_META_password: soltest_VALID_PASSWORD, - solace_META_queueName: "", - solace_META_msgCountTarget: soltest_VALID_MSG_COUNT_TARGET, + solaceMetaBrokerBaseUrl: "", + solaceMetaBrokerProtocol: soltestValidProtocol, + solaceMetaBrokerHostname: soltestValidHostname, + solaceMetaBrokerPort: soltestValidPort, + solaceMetamsgVpn: soltestValidVpn, + solaceMetaUsernameEnv: "", + solaceMetaPasswordEnv: "", + solaceMetaUsername: soltestValidUsername, + solaceMetaPassword: soltestValidPassword, + solaceMetaqueueName: "", + solaceMetamsgCountTarget: soltestValidMsgCountTarget, }, true, }, @@ -216,18 +211,18 @@ var testParseSolaceMetadata = []testSolaceMetadata{ { "#010 - missing msgCountTarget", map[string]string{ - solace_META_brokerBaseUrl: "", - solace_META_brokerProtocol: soltest_VALID_PROTOCOL, - solace_META_brokerHostname: soltest_VALID_HOSTNAME, - solace_META_brokerPort: soltest_VALID_PORT, - solace_META_msgVpn: soltest_VALID_VPN, - solace_META_usernameEnv: "", - solace_META_passwordEnv: "", - solace_META_username: soltest_VALID_USERNAME, - solace_META_password: soltest_VALID_PASSWORD, - solace_META_queueName: soltest_VALID_QUEUE_NAME, - solace_META_msgCountTarget: "", - solace_META_msgSpoolUsageTarget: "", + solaceMetaBrokerBaseUrl: "", + solaceMetaBrokerProtocol: soltestValidProtocol, + solaceMetaBrokerHostname: soltestValidHostname, + solaceMetaBrokerPort: soltestValidPort, + solaceMetamsgVpn: soltestValidVpn, + solaceMetaUsernameEnv: "", + solaceMetaPasswordEnv: "", + solaceMetaUsername: soltestValidUsername, + solaceMetaPassword: soltestValidPassword, + solaceMetaqueueName: soltestValidQueueName, + solaceMetamsgCountTarget: "", + solaceMetamsgSpoolUsageTarget: "", }, true, }, @@ -235,17 +230,17 @@ var testParseSolaceMetadata = []testSolaceMetadata{ { "#011 - msgSpoolUsageTarget non-numeric", map[string]string{ - solace_META_brokerBaseUrl: "", - solace_META_brokerProtocol: soltest_VALID_PROTOCOL, - solace_META_brokerHostname: soltest_VALID_HOSTNAME, - solace_META_brokerPort: soltest_VALID_PORT, - solace_META_msgVpn: soltest_VALID_VPN, - solace_META_usernameEnv: "", - solace_META_passwordEnv: "", - solace_META_username: soltest_VALID_USERNAME, - solace_META_password: soltest_VALID_PASSWORD, - solace_META_queueName: soltest_VALID_QUEUE_NAME, - solace_META_msgCountTarget: "NOT_AN_INTEGER", + solaceMetaBrokerBaseUrl: "", + solaceMetaBrokerProtocol: soltestValidProtocol, + solaceMetaBrokerHostname: soltestValidHostname, + solaceMetaBrokerPort: soltestValidPort, + solaceMetamsgVpn: soltestValidVpn, + solaceMetaUsernameEnv: "", + solaceMetaPasswordEnv: "", + solaceMetaUsername: soltestValidUsername, + solaceMetaPassword: soltestValidPassword, + solaceMetaqueueName: soltestValidQueueName, + solaceMetamsgCountTarget: "NOT_AN_INTEGER", }, true, }, @@ -253,17 +248,17 @@ var testParseSolaceMetadata = []testSolaceMetadata{ { "#012 - msgSpoolUsage non-numeric", map[string]string{ - solace_META_brokerBaseUrl: "", - solace_META_brokerProtocol: soltest_VALID_PROTOCOL, - solace_META_brokerHostname: soltest_VALID_HOSTNAME, - solace_META_brokerPort: soltest_VALID_PORT, - solace_META_msgVpn: soltest_VALID_VPN, - solace_META_usernameEnv: "", - solace_META_passwordEnv: "", - solace_META_username: soltest_VALID_USERNAME, - solace_META_password: soltest_VALID_PASSWORD, - solace_META_queueName: soltest_VALID_QUEUE_NAME, - solace_META_msgSpoolUsageTarget: "NOT_AN_INTEGER", + solaceMetaBrokerBaseUrl: "", + solaceMetaBrokerProtocol: soltestValidProtocol, + solaceMetaBrokerHostname: soltestValidHostname, + solaceMetaBrokerPort: soltestValidPort, + solaceMetamsgVpn: soltestValidVpn, + solaceMetaUsernameEnv: "", + solaceMetaPasswordEnv: "", + solaceMetaUsername: soltestValidUsername, + solaceMetaPassword: soltestValidPassword, + solaceMetaqueueName: soltestValidQueueName, + solaceMetamsgSpoolUsageTarget: "NOT_AN_INTEGER", }, true, }, @@ -271,18 +266,18 @@ var testParseSolaceMetadata = []testSolaceMetadata{ { "#013 - brokerBaseUrl", map[string]string{ - "": "", - solace_META_brokerBaseUrl: soltest_VALID_BASEURL, - solace_META_brokerProtocol: "", - solace_META_brokerHostname: "", - solace_META_brokerPort: "", - solace_META_msgVpn: soltest_VALID_VPN, - solace_META_usernameEnv: "", - solace_META_passwordEnv: "", - solace_META_username: soltest_VALID_USERNAME, - solace_META_password: soltest_VALID_PASSWORD, - solace_META_queueName: soltest_VALID_QUEUE_NAME, - solace_META_msgSpoolUsageTarget: soltest_VALID_MSG_SPOOL_TARGET, + "": "", + solaceMetaBrokerBaseUrl: soltestValidBaseUrl, + solaceMetaBrokerProtocol: "", + solaceMetaBrokerHostname: "", + solaceMetaBrokerPort: "", + solaceMetamsgVpn: soltestValidVpn, + solaceMetaUsernameEnv: "", + solaceMetaPasswordEnv: "", + solaceMetaUsername: soltestValidUsername, + solaceMetaPassword: soltestValidPassword, + solaceMetaqueueName: soltestValidQueueName, + solaceMetamsgSpoolUsageTarget: soltestValidMsgSpoolTarget, }, false, }, @@ -290,24 +285,21 @@ var testParseSolaceMetadata = []testSolaceMetadata{ var testSolaceEnvCreds = []testSolaceMetadata{ // +Case - Should find ENV vars - // Environment user/pass should be set: - // - SOLTEST_USERNAME - // - SOLTEST_PASSWORD { "#101 - Connect with Credentials in env", map[string]string{ // "": "", - solace_META_brokerBaseUrl: soltest_VALID_BASEURL, - solace_META_brokerProtocol: "", - solace_META_brokerHostname: "", - solace_META_brokerPort: "", - solace_META_msgVpn: soltest_VALID_VPN, - solace_META_usernameEnv: soltest_ENVVAR_USERNAME, - solace_META_passwordEnv: soltest_ENVVAR_PASSWORD, - // solace_META_username: "", - // solace_META_password: "", - solace_META_queueName: soltest_VALID_QUEUE_NAME, - solace_META_msgCountTarget: soltest_VALID_MSG_COUNT_TARGET, + solaceMetaBrokerBaseUrl: soltestValidBaseUrl, + solaceMetaBrokerProtocol: "", + solaceMetaBrokerHostname: "", + solaceMetaBrokerPort: "", + solaceMetamsgVpn: soltestValidVpn, + solaceMetaUsernameEnv: soltestEnvUsername, + solaceMetaPasswordEnv: soltestEnvPassword, + // solaceMetaUsername: "", + // solaceMetaPassword: "", + solaceMetaqueueName: soltestValidQueueName, + solaceMetamsgCountTarget: soltestValidMsgCountTarget, }, false, }, @@ -316,17 +308,17 @@ var testSolaceEnvCreds = []testSolaceMetadata{ "#102 - Environment vars referenced but not found", map[string]string{ // "": "", - solace_META_brokerBaseUrl: soltest_VALID_BASEURL, - solace_META_brokerProtocol: "", - solace_META_brokerHostname: "", - solace_META_brokerPort: "", - solace_META_msgVpn: soltest_VALID_VPN, - solace_META_usernameEnv: "SOLTEST_DNE", - solace_META_passwordEnv: "SOLTEST_DNE", - // solace_META_username: "", - // solace_META_password: "", - solace_META_queueName: soltest_VALID_QUEUE_NAME, - solace_META_msgCountTarget: soltest_VALID_MSG_COUNT_TARGET, + solaceMetaBrokerBaseUrl: soltestValidBaseUrl, + solaceMetaBrokerProtocol: "", + solaceMetaBrokerHostname: "", + solaceMetaBrokerPort: "", + solaceMetamsgVpn: soltestValidVpn, + solaceMetaUsernameEnv: "SOLTEST_DNE", + solaceMetaPasswordEnv: "SOLTEST_DNE", + // solaceMetaUsername: "", + // solaceMetaPassword: "", + solaceMetaqueueName: soltestValidQueueName, + solaceMetamsgCountTarget: soltestValidMsgCountTarget, }, true, }, @@ -340,17 +332,17 @@ var testSolaceK8sSecretCreds = []testSolaceMetadata{ "#201 - Connect with credentials from Auth Record (ENV VAR Present)", map[string]string{ // "": "", - solace_META_brokerBaseUrl: soltest_VALID_BASEURL, - solace_META_brokerProtocol: "", - solace_META_brokerHostname: "", - solace_META_brokerPort: "", - solace_META_msgVpn: soltest_VALID_VPN, - solace_META_usernameEnv: soltest_ENVVAR_USERNAME, - solace_META_passwordEnv: soltest_ENVVAR_PASSWORD, - // solace_META_username: "", - // solace_META_password: "", - solace_META_queueName: soltest_VALID_QUEUE_NAME, - solace_META_msgCountTarget: soltest_VALID_MSG_COUNT_TARGET, + solaceMetaBrokerBaseUrl: soltestValidBaseUrl, + solaceMetaBrokerProtocol: "", + solaceMetaBrokerHostname: "", + solaceMetaBrokerPort: "", + solaceMetamsgVpn: soltestValidVpn, + solaceMetaUsernameEnv: soltestEnvUsername, + solaceMetaPasswordEnv: soltestEnvPassword, + // solaceMetaUsername: "", + // solaceMetaPassword: "", + solaceMetaqueueName: soltestValidQueueName, + solaceMetamsgCountTarget: soltestValidMsgCountTarget, }, false, }, @@ -359,17 +351,17 @@ var testSolaceK8sSecretCreds = []testSolaceMetadata{ "#202 - Connect with credentials from Auth Record (ENV VAR and Clear Auth not present)", map[string]string{ // "": "", - // solace_META_brokerBaseUrl: soltest_VALID_BASEURL, - solace_META_brokerProtocol: soltest_VALID_PROTOCOL, - solace_META_brokerHostname: soltest_VALID_HOSTNAME, - solace_META_brokerPort: soltest_VALID_PORT, - solace_META_msgVpn: soltest_VALID_VPN, - // solace_META_usernameEnv: soltest_ENVVAR_USERNAME, - // solace_META_passwordEnv: soltest_ENVVAR_PASSWORD, - // solace_META_username: "", - // solace_META_password: "", - solace_META_queueName: soltest_VALID_QUEUE_NAME, - solace_META_msgCountTarget: soltest_VALID_MSG_COUNT_TARGET, + // solaceMetaBrokerBaseUrl: soltestValidBaseUrl, + solaceMetaBrokerProtocol: soltestValidProtocol, + solaceMetaBrokerHostname: soltestValidHostname, + solaceMetaBrokerPort: soltestValidPort, + solaceMetamsgVpn: soltestValidVpn, + // solaceMetaUsernameEnv: soltestEnvUsername, + // solaceMetaPasswordEnv: soltestEnvPassword, + // solaceMetaUsername: "", + // solaceMetaPassword: "", + solaceMetaqueueName: soltestValidQueueName, + solaceMetamsgCountTarget: soltestValidMsgCountTarget, }, false, }, @@ -378,17 +370,17 @@ var testSolaceK8sSecretCreds = []testSolaceMetadata{ "#203 - Connect with credentials from Auth Record (ENV VAR Present, Clear Auth not present)", map[string]string{ // "": "", - solace_META_brokerBaseUrl: soltest_VALID_BASEURL, - solace_META_brokerProtocol: "", - solace_META_brokerHostname: "", - solace_META_brokerPort: "", - solace_META_msgVpn: soltest_VALID_VPN, - solace_META_usernameEnv: "SOLTEST_DNE", - solace_META_passwordEnv: "SOLTEST_DNE", - // solace_META_username: "", - // solace_META_password: "", - solace_META_queueName: soltest_VALID_QUEUE_NAME, - solace_META_msgCountTarget: soltest_VALID_MSG_COUNT_TARGET, + solaceMetaBrokerBaseUrl: soltestValidBaseUrl, + solaceMetaBrokerProtocol: "", + solaceMetaBrokerHostname: "", + solaceMetaBrokerPort: "", + solaceMetamsgVpn: soltestValidVpn, + solaceMetaUsernameEnv: "SOLTEST_DNE", + solaceMetaPasswordEnv: "SOLTEST_DNE", + // solaceMetaUsername: "", + // solaceMetaPassword: "", + solaceMetaqueueName: soltestValidQueueName, + solaceMetamsgCountTarget: soltestValidMsgCountTarget, }, false, }, @@ -398,308 +390,164 @@ var testSolaceGetMetricSpecData = []testSolaceMetadata{ { "#401 - Get Metric Spec - msgCountTarget", map[string]string{ - "": "", - solace_META_brokerBaseUrl: soltest_VALID_BASEURL, - solace_META_brokerProtocol: "", - solace_META_brokerHostname: "", - solace_META_brokerPort: "", - solace_META_msgVpn: soltest_VALID_VPN, - solace_META_usernameEnv: "", - solace_META_passwordEnv: "", - solace_META_username: soltest_VALID_USERNAME, - solace_META_password: soltest_VALID_PASSWORD, - solace_META_queueName: soltest_VALID_QUEUE_NAME, - solace_META_msgCountTarget: soltest_VALID_MSG_COUNT_TARGET, - // solace_META_msgSpoolUsageTarget: soltest_VALID_MSG_SPOOL_TARGET, + "": "", + solaceMetaBrokerBaseUrl: soltestValidBaseUrl, + solaceMetaBrokerProtocol: "", + solaceMetaBrokerHostname: "", + solaceMetaBrokerPort: "", + solaceMetamsgVpn: soltestValidVpn, + solaceMetaUsernameEnv: "", + solaceMetaPasswordEnv: "", + solaceMetaUsername: soltestValidUsername, + solaceMetaPassword: soltestValidPassword, + solaceMetaqueueName: soltestValidQueueName, + solaceMetamsgCountTarget: soltestValidMsgCountTarget, + // solaceMetamsgSpoolUsageTarget: soltestValidMsgSpoolTarget, }, false, }, { "#402 - Get Metric Spec - msgSpoolUsageTarget", map[string]string{ - "": "", - solace_META_brokerBaseUrl: soltest_VALID_BASEURL, - solace_META_brokerProtocol: "", - solace_META_brokerHostname: "", - solace_META_brokerPort: "", - solace_META_msgVpn: soltest_VALID_VPN, - solace_META_usernameEnv: "", - solace_META_passwordEnv: "", - solace_META_username: soltest_VALID_USERNAME, - solace_META_password: soltest_VALID_PASSWORD, - solace_META_queueName: soltest_VALID_QUEUE_NAME, - // solace_META_msgCountTarget: soltest_VALID_MSG_COUNT_TARGET, - solace_META_msgSpoolUsageTarget: soltest_VALID_MSG_SPOOL_TARGET, + "": "", + solaceMetaBrokerBaseUrl: soltestValidBaseUrl, + solaceMetaBrokerProtocol: "", + solaceMetaBrokerHostname: "", + solaceMetaBrokerPort: "", + solaceMetamsgVpn: soltestValidVpn, + solaceMetaUsernameEnv: "", + solaceMetaPasswordEnv: "", + solaceMetaUsername: soltestValidUsername, + solaceMetaPassword: soltestValidPassword, + solaceMetaqueueName: soltestValidQueueName, + // solaceMetamsgCountTarget: soltestValidMsgCountTarget, + solaceMetamsgSpoolUsageTarget: soltestValidMsgSpoolTarget, }, false, }, { "#403 - Get Metric Spec - BOTH msgSpoolUsage and msgCountTarget", map[string]string{ - "": "", - solace_META_brokerBaseUrl: soltest_VALID_BASEURL, - solace_META_brokerProtocol: "", - solace_META_brokerHostname: "", - solace_META_brokerPort: "", - solace_META_msgVpn: soltest_VALID_VPN, - solace_META_usernameEnv: "", - solace_META_passwordEnv: "", - solace_META_username: soltest_VALID_USERNAME, - solace_META_password: soltest_VALID_PASSWORD, - solace_META_queueName: soltest_VALID_QUEUE_NAME, - solace_META_msgCountTarget: soltest_VALID_MSG_COUNT_TARGET, - solace_META_msgSpoolUsageTarget: soltest_VALID_MSG_SPOOL_TARGET, + "": "", + solaceMetaBrokerBaseUrl: soltestValidBaseUrl, + solaceMetaBrokerProtocol: "", + solaceMetaBrokerHostname: "", + solaceMetaBrokerPort: "", + solaceMetamsgVpn: soltestValidVpn, + solaceMetaUsernameEnv: "", + solaceMetaPasswordEnv: "", + solaceMetaUsername: soltestValidUsername, + solaceMetaPassword: soltestValidPassword, + solaceMetaqueueName: soltestValidQueueName, + solaceMetamsgCountTarget: soltestValidMsgCountTarget, + solaceMetamsgSpoolUsageTarget: soltestValidMsgSpoolTarget, }, false, }, { "#404 - Get Metric Spec - BOTH MISSING", map[string]string{ - "": "", - solace_META_brokerBaseUrl: soltest_VALID_BASEURL, - solace_META_brokerProtocol: "", - solace_META_brokerHostname: "", - solace_META_brokerPort: "", - solace_META_msgVpn: soltest_VALID_VPN, - solace_META_usernameEnv: "", - solace_META_passwordEnv: "", - solace_META_username: soltest_VALID_USERNAME, - solace_META_password: soltest_VALID_PASSWORD, - solace_META_queueName: soltest_VALID_QUEUE_NAME, - // solace_META_msgCountTarget: soltest_VALID_MSG_COUNT_TARGET, - // solace_META_msgSpoolUsageTarget: soltest_VALID_MSG_SPOOL_TARGET, + "": "", + solaceMetaBrokerBaseUrl: soltestValidBaseUrl, + solaceMetaBrokerProtocol: "", + solaceMetaBrokerHostname: "", + solaceMetaBrokerPort: "", + solaceMetamsgVpn: soltestValidVpn, + solaceMetaUsernameEnv: "", + solaceMetaPasswordEnv: "", + solaceMetaUsername: soltestValidUsername, + solaceMetaPassword: soltestValidPassword, + solaceMetaqueueName: soltestValidQueueName, + // solaceMetamsgCountTarget: soltestValidMsgCountTarget, + // solaceMetamsgSpoolUsageTarget: soltestValidMsgSpoolTarget, }, true, }, { "#405 - Get Metric Spec - BOTH ZERO", map[string]string{ - "": "", - solace_META_brokerBaseUrl: soltest_VALID_BASEURL, - solace_META_brokerProtocol: "", - solace_META_brokerHostname: "", - solace_META_brokerPort: "", - solace_META_msgVpn: soltest_VALID_VPN, - solace_META_usernameEnv: "", - solace_META_passwordEnv: "", - solace_META_username: soltest_VALID_USERNAME, - solace_META_password: soltest_VALID_PASSWORD, - solace_META_queueName: soltest_VALID_QUEUE_NAME, - solace_META_msgCountTarget: "0", - solace_META_msgSpoolUsageTarget: "0", + "": "", + solaceMetaBrokerBaseUrl: soltestValidBaseUrl, + solaceMetaBrokerProtocol: "", + solaceMetaBrokerHostname: "", + solaceMetaBrokerPort: "", + solaceMetamsgVpn: soltestValidVpn, + solaceMetaUsernameEnv: "", + solaceMetaPasswordEnv: "", + solaceMetaUsername: soltestValidUsername, + solaceMetaPassword: soltestValidPassword, + solaceMetaqueueName: soltestValidQueueName, + solaceMetamsgCountTarget: "0", + solaceMetamsgSpoolUsageTarget: "0", }, true, }, { "#406 - Get Metric Spec - ONE ZERO; OTHER VALID", map[string]string{ - "": "", - solace_META_brokerBaseUrl: soltest_VALID_BASEURL, - solace_META_brokerProtocol: "", - solace_META_brokerHostname: "", - solace_META_brokerPort: "", - solace_META_msgVpn: soltest_VALID_VPN, - solace_META_usernameEnv: "", - solace_META_passwordEnv: "", - solace_META_username: soltest_VALID_USERNAME, - solace_META_password: soltest_VALID_PASSWORD, - solace_META_queueName: soltest_VALID_QUEUE_NAME, - solace_META_msgCountTarget: "0", - solace_META_msgSpoolUsageTarget: soltest_VALID_MSG_SPOOL_TARGET, + "": "", + solaceMetaBrokerBaseUrl: soltestValidBaseUrl, + solaceMetaBrokerProtocol: "", + solaceMetaBrokerHostname: "", + solaceMetaBrokerPort: "", + solaceMetamsgVpn: soltestValidVpn, + solaceMetaUsernameEnv: "", + solaceMetaPasswordEnv: "", + solaceMetaUsername: soltestValidUsername, + solaceMetaPassword: soltestValidPassword, + solaceMetaqueueName: soltestValidQueueName, + solaceMetamsgCountTarget: "0", + solaceMetamsgSpoolUsageTarget: soltestValidMsgSpoolTarget, }, false, }, } var testSolaceExpectedMetricNames = map[string]string{ - solace_SCALER_ID + "-" + soltest_VALID_VPN + "-" + soltest_VALID_QUEUE_NAME + "-" + "msgCount": "", - solace_SCALER_ID + "-" + soltest_VALID_VPN + "-" + soltest_VALID_QUEUE_NAME + "-" + "msgSpoolUsage": "", -} - -var testSolaceSEMPConnectionMetadata = []testSolaceMetadata{ - /* - IF brokerBaseUrl is present, use it without interpretation as the base URL: http://my.host.domain:1234 - IF brokerBaseUrl in not present, Use protocol, host, and port - */ - - // +Case - Should Connect (Base URL Provided) - { - "#301 - Connect w/ baseUrl + Clear Auth", - map[string]string{ - "": "", - solace_META_brokerBaseUrl: soltest_VALID_BASEURL, - solace_META_brokerProtocol: "", - solace_META_brokerHostname: "", - solace_META_brokerPort: "", - solace_META_msgVpn: soltest_VALID_VPN, - solace_META_usernameEnv: "", - solace_META_passwordEnv: "", - solace_META_username: soltest_VALID_USERNAME, - solace_META_password: soltest_VALID_PASSWORD, - solace_META_queueName: soltest_VALID_QUEUE_NAME, - solace_META_msgCountTarget: soltest_VALID_MSG_COUNT_TARGET, - }, - false, - }, - { - "#302 - Connect with invalid username", - map[string]string{ - solace_META_brokerBaseUrl: "", - solace_META_brokerProtocol: soltest_VALID_PROTOCOL, - solace_META_brokerHostname: soltest_VALID_HOSTNAME, - solace_META_brokerPort: soltest_VALID_PORT, - solace_META_username: "NOT_A_REAL_USER", - solace_META_password: soltest_VALID_PASSWORD, - solace_META_msgVpn: soltest_VALID_VPN, - solace_META_queueName: soltest_VALID_QUEUE_NAME, - solace_META_msgSpoolUsageTarget: soltest_VALID_MSG_SPOOL_TARGET, - }, - true, - }, - { - "#303 - Connect with invalid password", - map[string]string{ - solace_META_brokerBaseUrl: "", - solace_META_brokerProtocol: soltest_VALID_PROTOCOL, - solace_META_brokerHostname: soltest_VALID_HOSTNAME, - solace_META_brokerPort: soltest_VALID_PORT, - solace_META_username: soltest_VALID_USERNAME, - solace_META_password: "THIS_IS_NOT_MY_PASSWORD", - solace_META_msgVpn: soltest_VALID_VPN, - solace_META_queueName: soltest_VALID_QUEUE_NAME, - solace_META_msgCountTarget: soltest_VALID_MSG_COUNT_TARGET, - solace_META_msgSpoolUsageTarget: soltest_VALID_MSG_SPOOL_TARGET, - }, - true, - }, - // +Case - Should Connect (Derived Base URL) - { - "#304 - Connect with component URL + Env Var Auth", - map[string]string{ - solace_META_brokerBaseUrl: "", - solace_META_brokerProtocol: soltest_VALID_PROTOCOL, - solace_META_brokerHostname: soltest_VALID_HOSTNAME, - solace_META_brokerPort: soltest_VALID_PORT, - solace_META_msgVpn: soltest_VALID_VPN, - solace_META_usernameEnv: "", - solace_META_passwordEnv: "", - solace_META_username: soltest_VALID_USERNAME, - solace_META_password: soltest_VALID_PASSWORD, - solace_META_queueName: soltest_VALID_QUEUE_NAME, - solace_META_msgCountTarget: soltest_VALID_MSG_COUNT_TARGET, - }, - false, - }, - { - "#305 - Connect with component URL + K8S Auth Record", - map[string]string{ - solace_META_brokerBaseUrl: "", - solace_META_brokerProtocol: soltest_VALID_PROTOCOL, - solace_META_brokerHostname: soltest_VALID_HOSTNAME, - solace_META_brokerPort: soltest_VALID_PORT, - solace_META_msgVpn: soltest_VALID_VPN, - solace_META_usernameEnv: "", - solace_META_passwordEnv: "", - // solace_META_username: soltest_VALID_USERNAME, - // solace_META_password: soltest_VALID_PASSWORD, - solace_META_queueName: soltest_VALID_QUEUE_NAME, - solace_META_msgCountTarget: soltest_VALID_MSG_COUNT_TARGET, - }, - false, - }, - // -Case - Solace VPN DNE - { - "#306 - Solace VPN DNE", - map[string]string{ - solace_META_brokerBaseUrl: "", - solace_META_brokerProtocol: soltest_VALID_PROTOCOL, - solace_META_brokerHostname: soltest_VALID_HOSTNAME, - solace_META_brokerPort: soltest_VALID_PORT, - solace_META_msgVpn: "THIS_VPN_DOES_NOT_EXIST", - solace_META_usernameEnv: "", - solace_META_passwordEnv: "", - solace_META_username: soltest_VALID_USERNAME, - solace_META_password: soltest_VALID_PASSWORD, - solace_META_queueName: soltest_VALID_QUEUE_NAME, - solace_META_msgCountTarget: soltest_VALID_MSG_COUNT_TARGET, - }, - true, - }, - // -Case - Queue DNE - { - "#307 - Solace Queue DNE", - map[string]string{ - solace_META_brokerBaseUrl: "", - solace_META_brokerProtocol: soltest_VALID_PROTOCOL, - solace_META_brokerHostname: soltest_VALID_HOSTNAME, - solace_META_brokerPort: soltest_VALID_PORT, - solace_META_msgVpn: soltest_VALID_VPN, - solace_META_usernameEnv: "", - solace_META_passwordEnv: "", - solace_META_username: soltest_VALID_USERNAME, - solace_META_password: soltest_VALID_PASSWORD, - solace_META_queueName: "THIS_QUEUE_DOES_NOT_EXIST", - solace_META_msgCountTarget: soltest_VALID_MSG_COUNT_TARGET, - }, - true, - }, - // -Case - Bad baseUrl - { - "#308 - Bad Base URL", - map[string]string{ - solace_META_brokerBaseUrl: "http://not-a-real-server.nothing:999", - solace_META_brokerProtocol: "", - solace_META_brokerHostname: "", - solace_META_brokerPort: "", - solace_META_msgVpn: soltest_VALID_VPN, - solace_META_usernameEnv: "", - solace_META_passwordEnv: "", - solace_META_username: soltest_VALID_USERNAME, - solace_META_password: soltest_VALID_PASSWORD, - solace_META_queueName: soltest_VALID_QUEUE_NAME, - solace_META_msgCountTarget: soltest_VALID_MSG_COUNT_TARGET, - }, - true, - }, + solaceScalerId + "-" + soltestValidVpn + "-" + soltestValidQueueName + "-" + "msgcount": "", + solaceScalerId + "-" + soltestValidVpn + "-" + soltestValidQueueName + "-" + "msgspoolusage": "", } func TestSolaceParseSolaceMetadata(t *testing.T) { for _, testData := range testParseSolaceMetadata { fmt.Print(testData.testId) _, err := parseSolaceMetadata(&ScalerConfig{ResolvedEnv: nil, TriggerMetadata: testData.metadata, AuthParams: nil}) - if err != nil && !testData.isError { + switch { + case err != nil && !testData.isError: t.Error("Expected success but got error: ", err) fmt.Println(" --> FAIL") - } else if testData.isError && err == nil { + case testData.isError && err == nil: t.Error("Expected error but got success") fmt.Println(" --> FAIL") - } else { + default: fmt.Println(" --> PASS") } } for _, testData := range testSolaceEnvCreds { fmt.Print(testData.testId) _, err := parseSolaceMetadata(&ScalerConfig{ResolvedEnv: testDataSolaceResolvedEnvVALID, TriggerMetadata: testData.metadata, AuthParams: nil}) - if err != nil && !testData.isError { + switch { + case err != nil && !testData.isError: t.Error("Expected success but got error: ", err) fmt.Println(" --> FAIL") - } else if testData.isError && err == nil { + case testData.isError && err == nil: t.Error("Expected error but got success") fmt.Println(" --> FAIL") - } else { + default: fmt.Println(" --> PASS") } } for _, testData := range testSolaceK8sSecretCreds { fmt.Print(testData.testId) _, err := parseSolaceMetadata(&ScalerConfig{ResolvedEnv: nil, TriggerMetadata: testData.metadata, AuthParams: testDataSolaceAuthParamsVALID}) - if err != nil && !testData.isError { - t.Error("Expected success but result is error: ", err) + switch { + case err != nil && !testData.isError: + t.Error("Expected success but got error: ", err) fmt.Println(" --> FAIL") - } else if testData.isError && err == nil { - t.Error("Expected error but result is success") + case testData.isError && err == nil: + t.Error("Expected error but got success") fmt.Println(" --> FAIL") - } else { + default: fmt.Println(" --> PASS") } } @@ -712,13 +560,7 @@ func TestSolaceGetMetricSpec(t *testing.T) { fmt.Print(testData.testId) var err error var solaceMeta *SolaceMetadata - if idx == 0 { - // The first instance will have nil ResolvedEnv and AuthParams -- for Clear Auth - solaceMeta, err = parseSolaceMetadata(&ScalerConfig{ResolvedEnv: nil, TriggerMetadata: testData.metadata, AuthParams: nil}) - } else { - // The first instance will have nil ResolvedEnv and AuthParams -- for Clear Auth - solaceMeta, err = parseSolaceMetadata(&ScalerConfig{ResolvedEnv: testDataSolaceResolvedEnvVALID, TriggerMetadata: testData.metadata, AuthParams: testDataSolaceAuthParamsVALID}) - } + solaceMeta, err = parseSolaceMetadata(&ScalerConfig{ResolvedEnv: testDataSolaceResolvedEnvVALID, TriggerMetadata: testData.metadata, AuthParams: testDataSolaceAuthParamsVALID}) if err != nil { fmt.Printf("\n Failed to parse metadata: %v", err) } else { @@ -730,69 +572,24 @@ func TestSolaceGetMetricSpec(t *testing.T) { var metric []v2beta2.MetricSpec if metric = testSolaceScaler.GetMetricSpecForScaling(); metric == nil || len(metric) == 0 { - t.Error("Metric value not found") + err = fmt.Errorf("Metric value not found\n") + } else { + metricName := metric[0].External.Metric.Name + if _, ok := testSolaceExpectedMetricNames[metricName]; ok == false { + err = fmt.Errorf("Expected Metric value not found\n") + } } - metricName := metric[0].External.Metric.Name - metricValue := metric[0].External.Target.AverageValue - if _, ok := testSolaceExpectedMetricNames[metricName]; ok == false { - t.Error("Expected Metric value not found") - } - - fmt.Printf("\n Found Metric: %s=%v", metricName, metricValue) } - if testData.isError && err == nil { + switch { + case testData.isError && err == nil: fmt.Println(" --> FAIL") t.Error("Expected to fail but passed", err) - } else if !testData.isError && err != nil { + case !testData.isError && err != nil: + fmt.Println(" --> FAIL") t.Error("Expected success but failed", err) - } else { + default: fmt.Println(" --> PASS") } - - } -} - -func TestSolaceSEMPConnection(t *testing.T) { - for idx := 0; idx < len(testSolaceSEMPConnectionMetadata); idx++ { - - testData := testSolaceSEMPConnectionMetadata[idx] - fmt.Print(testData.testId) - var err error - var solaceMeta *SolaceMetadata - if idx < 3 { - // The first instance will have nil ResolvedEnv and AuthParams -- for Clear Auth - solaceMeta, err = parseSolaceMetadata(&ScalerConfig{ResolvedEnv: nil, TriggerMetadata: testData.metadata, AuthParams: nil}) - } else { - // The first instance will have nil ResolvedEnv and AuthParams -- for Clear Auth - solaceMeta, err = parseSolaceMetadata(&ScalerConfig{ResolvedEnv: testDataSolaceResolvedEnvVALID, TriggerMetadata: testData.metadata, AuthParams: testDataSolaceAuthParamsVALID}) - } - if err != nil { - t.Fatal("FAILED to parse metadata: ", err) - } - - testSolaceScaler := SolaceScaler{ - metadata: solaceMeta, - httpClient: http.DefaultClient, - } - - val, err := testSolaceScaler.getSolaceQueueMetricsFromSEMP() - - if testData.isError && err == nil { - fmt.Println(" --> FAIL") - t.Error("Expected to fail but passed", err) - } else if !testData.isError && err != nil { - fmt.Println(" --> FAIL: Connection to SEMP Failed") - t.Error("Expected successful connection to SEMP Failed", err) - } else { - fmt.Printf(" --> PASS") - if val.msgCount > 0 { - fmt.Printf("; msgCount=%d", val.msgCount) - } - if val.msgSpoolUsage > 0 { - fmt.Printf("; msgSpoolUsage=%d", val.msgSpoolUsage) - } - fmt.Println() - } } } diff --git a/tests/scalers/solace.tests.ts b/tests/scalers/solace.tests.ts index f6b2ece8a61..22d312a5804 100644 --- a/tests/scalers/solace.tests.ts +++ b/tests/scalers/solace.tests.ts @@ -1,7 +1,4 @@ -//import * as async from 'async' -//import * as fs from 'fs' import * as sh from 'shelljs' -//import * as tmp from 'tmp' import test from 'ava' import { SolaceHelper } from './solace-helpers' From cf8b77e745c2f220ac0409eff1368e31118ee518 Mon Sep 17 00:00:00 2001 From: Dennis Brinley Date: Mon, 12 Jul 2021 13:25:55 -0400 Subject: [PATCH 4/7] Corrected linting errors Signed-off-by: Dennis Brinley By making a contribution to this project, I certify that: (a) The contribution was created in whole or in part by me and I have the right to submit it under the open source license indicated in the file; or (b) The contribution is based upon previous work that, to the best of my knowledge, is covered under an appropriate open source license and I have the right under that license to submit that work with modifications, whether created in whole or in part by me, under the same open source license (unless I am permitted to submit under a different license), as indicated in the file; or (c) The contribution was provided directly to me by some other person who certified (a), (b) or (c) and I have not modified it. (d) I understand and agree that this project and the contribution are public and that a record of the contribution (including all personal information I submit with it, including my sign-off) is maintained indefinitely and may be redistributed consistent with this project or the open source license(s) involved. --- pkg/scalers/solace_scaler.go | 230 ++++++++++------- pkg/scalers/solace_scaler_test.go | 412 ++++++++++++++---------------- tests/scalers/solace-helpers.ts | 8 +- 3 files changed, 333 insertions(+), 317 deletions(-) diff --git a/pkg/scalers/solace_scaler.go b/pkg/scalers/solace_scaler.go index fd4fb5f85d3..2f4d987a564 100644 --- a/pkg/scalers/solace_scaler.go +++ b/pkg/scalers/solace_scaler.go @@ -20,25 +20,24 @@ import ( const ( solaceExtMetricType = "External" - solaceScalerId = "solace" - + solaceScalerID = "solace" // REST ENDPOINT String Patterns - solaceBrokerBaseUrlTemplate = "%s://%s:%s" - solaceSempEndpointUrlTemplate = "%s/%s/%s/monitor/msgVpns/%s/%ss/%s" + // solaceBrokerBaseURLTemplate = "%s://%s:%s" + solaceSempEndpointURLTemplate = "%s/%s/%s/monitor/msgVpns/%s/%ss/%s" // SEMP REST API Context - solaceApiName = "SEMP" - solaceApiVersion = "v2" - solaceApiObjectTypeQueue = "queue" - + solaceAPIName = "SEMP" + solaceAPIVersion = "v2" + solaceAPIObjectTypeQueue = "queue" // Log Message Templates - solaceFoundMetaFalse = "Required Field %s NOT FOUND in Solace Metadata" - + solaceFoundMetaFalse = "required Field %s NOT FOUND in Solace Metadata" // YAML Configuration Metadata Field Names // Broker Identifiers - solaceMetaBrokerBaseUrl = "brokerBaseUrl" - solaceMetaBrokerProtocol = "brokerProtocol" - solaceMetaBrokerHostname = "brokerHostname" - solaceMetaBrokerPort = "brokerPort" + solaceMetaBrokerBaseURL = "brokerBaseUrl" + + // solaceMetaBrokerProtocol = "brokerProtocol" + // solaceMetaBrokerHostname = "brokerHostname" + // solaceMetaBrokerPort = "brokerPort" + // Credential Identifiers solaceMetaUsername = "username" solaceMetaPassword = "password" @@ -50,7 +49,6 @@ const ( // Metric Targets solaceMetamsgCountTarget = "msgCountTarget" solaceMetamsgSpoolUsageTarget = "msgSpoolUsageTarget" - // Trigger type identifiers solaceTriggermsgcount = "msgcount" solaceTriggermsgspoolusage = "msgspoolusage" @@ -71,12 +69,12 @@ type SolaceScaler struct { type SolaceMetadata struct { // Full SEMP URL to target queue (CONSTRUCTED IN CODE) - endpointUrl string + endpointURL string // Protocol-Host-Port: http://host-name:12345 - brokerBaseUrl string - brokerProtocol string // Used if brokerBaseUrl not present - brokerHostname string // Used if brokerBaseUrl not present - brokerPort string // Used if brokerBaseUrl not present + brokerBaseURL string + // brokerProtocol string + // brokerHostname string + // brokerPort string // Solace Message VPN messageVpn string queueName string @@ -117,11 +115,10 @@ type solaceSEMPMetadata struct { } // Solace Logger -var solaceLog = logf.Log.WithName(solaceScalerId + "_scaler") +var solaceLog = logf.Log.WithName(solaceScalerID + "_scaler") // Constructor for SolaceScaler func NewSolaceScaler(config *ScalerConfig) (Scaler, error) { - // Create HTTP Client httpClient := kedautil.CreateHTTPClient(config.GlobalHTTPTimeout) @@ -141,39 +138,41 @@ func NewSolaceScaler(config *ScalerConfig) (Scaler, error) { // Called by constructor func parseSolaceMetadata(config *ScalerConfig) (*SolaceMetadata, error) { meta := SolaceMetadata{} - // GET THE SEMP API ENDPOINT - // First look for brokerBaseUrl in config; Use components if not found - if val, ok := config.TriggerMetadata[solaceMetaBrokerBaseUrl]; ok && val != "" { - meta.brokerBaseUrl = val + // First look for brokerBaseURL in config; Use components if not found + if val, ok := config.TriggerMetadata[solaceMetaBrokerBaseURL]; ok && val != "" { + meta.brokerBaseURL = val } else { - // IF brokerBaseUrl is not present, then get components - // GET Protocol - if val, ok := config.TriggerMetadata[solaceMetaBrokerProtocol]; ok && (val == "https" || val == "http") { - meta.brokerProtocol = val - } else { - return nil, fmt.Errorf(solaceFoundMetaFalse, solaceMetaBrokerProtocol) - } - // GET Hostname - if val, ok := config.TriggerMetadata[solaceMetaBrokerHostname]; ok && val != "" { - meta.brokerHostname = val - } else { - return nil, fmt.Errorf(solaceFoundMetaFalse, solaceMetaBrokerHostname) - } - // GET Port - if val, ok := config.TriggerMetadata[solaceMetaBrokerPort]; ok && val != "" { - if _, err := strconv.Atoi(val); err == nil { - meta.brokerPort = val + /* + // IF brokerBaseURL is not present, then get components + // GET Protocol + if val, ok := config.TriggerMetadata[solaceMetaBrokerProtocol]; ok && (val == "https" || val == "http") { + meta.brokerProtocol = val } else { - return nil, fmt.Errorf("Can't parse brokerPort, not a valid integer: %s", err) + return nil, fmt.Errorf(solaceFoundMetaFalse, solaceMetaBrokerProtocol) } - } else { - return nil, fmt.Errorf(solaceFoundMetaFalse, solaceMetaBrokerPort) - } - // Format Solace Broker Base URL from components - meta.brokerBaseUrl = fmt.Sprintf(solaceBrokerBaseUrlTemplate, meta.brokerProtocol, meta.brokerHostname, meta.brokerPort) - } + // GET Hostname + if val, ok := config.TriggerMetadata[solaceMetaBrokerHostname]; ok && val != "" { + meta.brokerHostname = val + } else { + return nil, fmt.Errorf(solaceFoundMetaFalse, solaceMetaBrokerHostname) + } + // GET Port + if val, ok := config.TriggerMetadata[solaceMetaBrokerPort]; ok && val != "" { + if _, err := strconv.Atoi(val); err == nil { + meta.brokerPort = val + } else { + return nil, fmt.Errorf("can't parse brokerPort, not a valid integer: %s", err) + } + } else { + return nil, fmt.Errorf(solaceFoundMetaFalse, solaceMetaBrokerPort) + } + // Format Solace Broker Base URL from components + meta.brokerBaseURL = fmt.Sprintf(solaceBrokerBaseURLTemplate, meta.brokerProtocol, meta.brokerHostname, meta.brokerPort) + */ + return nil, fmt.Errorf(solaceFoundMetaFalse, solaceMetaBrokerBaseURL) + } // GET Message VPN if val, ok := config.TriggerMetadata[solaceMetamsgVpn]; ok && val != "" { meta.messageVpn = val @@ -194,33 +193,77 @@ func parseSolaceMetadata(config *ScalerConfig) (*SolaceMetadata, error) { if msgCount, err := strconv.Atoi(val); err == nil { meta.msgCountTarget = msgCount } else { - return nil, fmt.Errorf("Can't parse [%s], not a valid integer: %s", solaceMetamsgCountTarget, err) + return nil, fmt.Errorf("can't parse [%s], not a valid integer: %s", solaceMetamsgCountTarget, err) } } + // GET msgSpoolUsageTarget if val, ok := config.TriggerMetadata[solaceMetamsgSpoolUsageTarget]; ok && val != "" { if msgSpoolUsage, err := strconv.Atoi(val); err == nil { meta.msgSpoolUsageTarget = msgSpoolUsage } else { - return nil, fmt.Errorf("Can't parse [%s], not a valid integer: %s", solaceMetamsgSpoolUsageTarget, err) + return nil, fmt.Errorf("can't parse [%s], not a valid integer: %s", solaceMetamsgSpoolUsageTarget, err) } } // Check that we have at least one positive target value for the scaler if meta.msgCountTarget < 1 && meta.msgSpoolUsageTarget < 1 { - return nil, fmt.Errorf("No Target Value found in the Scaler Configuration") + return nil, fmt.Errorf("no target value found in the scaler configuration") } // Format Solace SEMP Queue Endpoint (REST URL) - meta.endpointUrl = fmt.Sprintf( - solaceSempEndpointUrlTemplate, - meta.brokerBaseUrl, - solaceApiName, - solaceApiVersion, + meta.endpointURL = fmt.Sprintf( + solaceSempEndpointURLTemplate, + meta.brokerBaseURL, + solaceAPIName, + solaceAPIVersion, meta.messageVpn, - solaceApiObjectTypeQueue, + solaceAPIObjectTypeQueue, meta.queueName) + /* + // GET CREDENTIALS + // The username must be a valid broker ADMIN user identifier with read access to SEMP for the broker, VPN, and relevant objects + // The scaler will attempt to acquire username and then password independently. For each: + // - Search K8S Secret (Encoded) + // - Search environment variable specified by config at 'usernameEnv' / 'passwordEnv' + // - Search 'username' / 'password' fields (Clear Text) + // Get username + if usernameSecret, ok := config.AuthParams[solaceMetaUsername]; ok && usernameSecret != "" { + meta.username = usernameSecret + } else if usernameEnv, ok := config.TriggerMetadata[solaceMetaUsernameEnv]; ok && usernameEnv != "" { + if resolvedUser, ok := config.ResolvedEnv[config.TriggerMetadata[solaceMetaUsernameEnv]]; ok && resolvedUser != "" { + meta.username = resolvedUser + } else { + return nil, fmt.Errorf("username could not be resolved from the environment variable: %s", usernameEnv) + } + } else if usernameClear, ok := config.TriggerMetadata[solaceMetaUsername]; ok && usernameClear != "" { + meta.username = usernameClear + } else { + return nil, fmt.Errorf("username is required and not found in K8Secret, environment, or clear text") + } + // Get Password + if passwordSecret, ok := config.AuthParams[solaceMetaPassword]; ok && passwordSecret != "" { + meta.password = passwordSecret + } else if passwordEnv, ok := config.TriggerMetadata[solaceMetaPasswordEnv]; ok && passwordEnv != "" { + if resolvedPassword, ok := config.ResolvedEnv[config.TriggerMetadata[solaceMetaPasswordEnv]]; ok && resolvedPassword != "" { + meta.password = resolvedPassword + } else { + return nil, fmt.Errorf("password could not be resolved from the environment variable: %s", passwordEnv) + } + } else if passwordClear, ok := config.TriggerMetadata[solaceMetaPassword]; ok && passwordClear != "" { + meta.password = passwordClear + } else { + return nil, fmt.Errorf("password is required and not found in K8Secret, environment, or clear text") + } + */ + var e error + if meta.username, meta.password, e = getSolaceSempCredentials(config); e != nil { + return nil, e + } + return &meta, nil +} +func getSolaceSempCredentials(config *ScalerConfig) (u string, p string, err error) { // GET CREDENTIALS // The username must be a valid broker ADMIN user identifier with read access to SEMP for the broker, VPN, and relevant objects // The scaler will attempt to acquire username and then password independently. For each: @@ -229,34 +272,33 @@ func parseSolaceMetadata(config *ScalerConfig) (*SolaceMetadata, error) { // - Search 'username' / 'password' fields (Clear Text) // Get username if usernameSecret, ok := config.AuthParams[solaceMetaUsername]; ok && usernameSecret != "" { - meta.username = usernameSecret + u = usernameSecret } else if usernameEnv, ok := config.TriggerMetadata[solaceMetaUsernameEnv]; ok && usernameEnv != "" { if resolvedUser, ok := config.ResolvedEnv[config.TriggerMetadata[solaceMetaUsernameEnv]]; ok && resolvedUser != "" { - meta.username = resolvedUser + u = resolvedUser } else { - return nil, fmt.Errorf("username could not be resolved from the environment variable: %s", usernameEnv) + return "", "", fmt.Errorf("username could not be resolved from the environment variable: %s", usernameEnv) } } else if usernameClear, ok := config.TriggerMetadata[solaceMetaUsername]; ok && usernameClear != "" { - meta.username = usernameClear + u = usernameClear } else { - return nil, fmt.Errorf("username is required and not found in K8Secret, environment, or clear text") + return "", "", fmt.Errorf("username is required and not found in K8Secret, environment, or clear text") } // Get Password if passwordSecret, ok := config.AuthParams[solaceMetaPassword]; ok && passwordSecret != "" { - meta.password = passwordSecret + p = passwordSecret } else if passwordEnv, ok := config.TriggerMetadata[solaceMetaPasswordEnv]; ok && passwordEnv != "" { if resolvedPassword, ok := config.ResolvedEnv[config.TriggerMetadata[solaceMetaPasswordEnv]]; ok && resolvedPassword != "" { - meta.password = resolvedPassword + p = resolvedPassword } else { - return nil, fmt.Errorf("password could not be resolved from the environment variable: %s", passwordEnv) + return "", "", fmt.Errorf("password could not be resolved from the environment variable: %s", passwordEnv) } } else if passwordClear, ok := config.TriggerMetadata[solaceMetaPassword]; ok && passwordClear != "" { - meta.password = passwordClear + p = passwordClear } else { - return nil, fmt.Errorf("password is required and not found in K8Secret, environment, or clear text") + return "", "", fmt.Errorf("password is required and not found in K8Secret, environment, or clear text") } - - return &meta, nil + return u, p, nil } // INTERFACE METHOD @@ -268,15 +310,13 @@ func parseSolaceMetadata(config *ScalerConfig) (*SolaceMetadata, error) { // - solace-[VPN_Name]-[Queue_Name]-[metric_type] // e.g. solace-myvpn-QUEUE1-msgCount func (s *SolaceScaler) GetMetricSpecForScaling() []v2beta2.MetricSpec { - var metricSpecList []v2beta2.MetricSpec - // Message Count Target Spec if s.metadata.msgCountTarget > 0 { targetMetricValue := resource.NewQuantity(int64(s.metadata.msgCountTarget), resource.DecimalSI) externalMetric := &v2beta2.ExternalMetricSource{ Metric: v2beta2.MetricIdentifier{ - Name: kedautil.NormalizeString(fmt.Sprintf("%s-%s-%s-%s", solaceScalerId, s.metadata.messageVpn, s.metadata.queueName, solaceTriggermsgcount)), + Name: kedautil.NormalizeString(fmt.Sprintf("%s-%s-%s-%s", solaceScalerID, s.metadata.messageVpn, s.metadata.queueName, solaceTriggermsgcount)), }, Target: v2beta2.MetricTarget{ Type: v2beta2.AverageValueMetricType, @@ -291,7 +331,7 @@ func (s *SolaceScaler) GetMetricSpecForScaling() []v2beta2.MetricSpec { targetMetricValue := resource.NewQuantity(int64(s.metadata.msgSpoolUsageTarget), resource.DecimalSI) externalMetric := &v2beta2.ExternalMetricSource{ Metric: v2beta2.MetricIdentifier{ - Name: kedautil.NormalizeString(fmt.Sprintf("%s-%s-%s-%s", solaceScalerId, s.metadata.messageVpn, s.metadata.queueName, solaceTriggermsgspoolusage)), + Name: kedautil.NormalizeString(fmt.Sprintf("%s-%s-%s-%s", solaceScalerID, s.metadata.messageVpn, s.metadata.queueName, solaceTriggermsgspoolusage)), }, Target: v2beta2.MetricTarget{ Type: v2beta2.AverageValueMetricType, @@ -306,40 +346,41 @@ func (s *SolaceScaler) GetMetricSpecForScaling() []v2beta2.MetricSpec { // returns SolaceMetricValues struct populated from broker SEMP endpoint func (s *SolaceScaler) getSolaceQueueMetricsFromSEMP() (SolaceMetricValues, error) { - - var scaledMetricEndpointUrl string = s.metadata.endpointUrl - var httpClient *http.Client = s.httpClient + var scaledMetricEndpointURL = s.metadata.endpointURL + var httpClient = s.httpClient var sempResponse solaceSEMPResponse var metricValues SolaceMetricValues // RETRIEVE METRICS FROM SOLACE SEMP API // Define HTTP Request - request, err := http.NewRequest("GET", scaledMetricEndpointUrl, nil) + request, err := http.NewRequest("GET", scaledMetricEndpointURL, nil) if err != nil { - return SolaceMetricValues{}, fmt.Errorf("Failed attempting request to Solace SEMP API: %s", err) + return SolaceMetricValues{}, fmt.Errorf("failed attempting request to solace semp api: %s", err) } + // Add HTTP Auth and Headers request.SetBasicAuth(s.metadata.username, s.metadata.password) request.Header.Set("Content-Type", "application/json") + // Call Solace SEMP API response, err := httpClient.Do(request) if err != nil { - return SolaceMetricValues{}, fmt.Errorf("Call to Solace SEMP API failed: %s", err) + return SolaceMetricValues{}, fmt.Errorf("call to solace semp api failed: %s", err) } defer response.Body.Close() // Check HTTP Status Code if response.StatusCode < 200 || response.StatusCode > 299 { - sempError := fmt.Errorf("SEMP Request HTTP Status Code: %s - %s", strconv.Itoa(response.StatusCode), response.Status) + sempError := fmt.Errorf("semp request http status code: %s - %s", strconv.Itoa(response.StatusCode), response.Status) return SolaceMetricValues{}, sempError } // Decode SEMP Response and Test if err := json.NewDecoder(response.Body).Decode(&sempResponse); err != nil { - return SolaceMetricValues{}, fmt.Errorf("Failed to read SEMP response body: %s", err) + return SolaceMetricValues{}, fmt.Errorf("failed to read semp response body: %s", err) } if sempResponse.Meta.ResponseCode < 200 || sempResponse.Meta.ResponseCode > 299 { - return SolaceMetricValues{}, fmt.Errorf("Solace SEMP API returned error status: %d", sempResponse.Meta.ResponseCode) + return SolaceMetricValues{}, fmt.Errorf("solace semp api returned error status: %d", sempResponse.Meta.ResponseCode) } // Set Return Values @@ -352,14 +393,13 @@ func (s *SolaceScaler) getSolaceQueueMetricsFromSEMP() (SolaceMetricValues, erro // Call SEMP API to retrieve metrics // returns value for named metric func (s *SolaceScaler) GetMetrics(ctx context.Context, metricName string, metricSelector labels.Selector) ([]external_metrics.ExternalMetricValue, error) { - - var metricValues SolaceMetricValues - if val, err := s.getSolaceQueueMetricsFromSEMP(); err != nil { - solaceLog.Error(err, fmt.Sprintf("Call to SEMP Endpoint Failed")) - return []external_metrics.ExternalMetricValue{}, err - } else { - metricValues = val + var metricValues, mv SolaceMetricValues + var mve error + if mv, mve = s.getSolaceQueueMetricsFromSEMP(); mve != nil { + solaceLog.Error(mve, "call to semp endpoint failed") + return []external_metrics.ExternalMetricValue{}, mve } + metricValues = mv var metric external_metrics.ExternalMetricValue switch { @@ -377,11 +417,10 @@ func (s *SolaceScaler) GetMetrics(ctx context.Context, metricName string, metric } default: // Should never end up here - err := fmt.Errorf("Unidentified Metric: %s", metricName) - solaceLog.Error(err, "Returning Error to calling app") + err := fmt.Errorf("unidentified metric: %s", metricName) + solaceLog.Error(err, "returning error to calling app") return []external_metrics.ExternalMetricValue{}, err } - return append([]external_metrics.ExternalMetricValue{}, metric), nil } @@ -389,10 +428,9 @@ func (s *SolaceScaler) GetMetrics(ctx context.Context, metricName string, metric // Call SEMP API to retrieve metrics // IsActive returns true if queue messageCount > 0 || msgSpoolUsage > 0 func (s *SolaceScaler) IsActive(ctx context.Context) (bool, error) { - metricValues, err := s.getSolaceQueueMetricsFromSEMP() if err != nil { - solaceLog.Error(err, "Call to SEMP Endpoint Failed") + solaceLog.Error(err, "call to semp endpoint failed") return false, err } return (metricValues.msgCount > 0 || metricValues.msgSpoolUsage > 0), nil diff --git a/pkg/scalers/solace_scaler_test.go b/pkg/scalers/solace_scaler_test.go index b7c0c4bd782..1832711406a 100644 --- a/pkg/scalers/solace_scaler_test.go +++ b/pkg/scalers/solace_scaler_test.go @@ -9,22 +9,16 @@ import ( ) type testSolaceMetadata struct { - testId string + testID string metadata map[string]string isError bool } -/* -type testSolaceMetricIdentifier struct { - metadataTestData *testSolaceMetadata - name string -} -*/ var ( - soltestValidBaseUrl = "http://localhost:8080" - soltestValidProtocol = "http" - soltestValidHostname = "localhost" - soltestValidPort = "8080" + soltestValidBaseURL = "http://localhost:8080" + // soltestValidProtocol = "http" + // soltestValidHostname = "localhost" + // soltestValidPort = "8080" soltestValidUsername = "admin" soltestValidPassword = "admin" soltestValidVpn = "dennis_vpn" @@ -50,10 +44,8 @@ var testDataSolaceResolvedEnvVALID = map[string]string{ // TEST CASES FOR SolaceParseMetadata() var testParseSolaceMetadata = []testSolaceMetadata{ - /* - IF brokerBaseUrl is present, use it without interpretation as the base URL: http://my.host.domain:1234 - IF brokerBaseUrl in not present, Use protocol, host, and port - */ + // IF brokerBaseUrl is present, use it without interpretation as the base URL: http://my.host.domain:1234 + // IF brokerBaseUrl in not present, Use protocol, host, and port // Empty { @@ -65,29 +57,11 @@ var testParseSolaceMetadata = []testSolaceMetadata{ { "#002 - brokerBaseUrl", map[string]string{ - "": "", - solaceMetaBrokerBaseUrl: soltestValidBaseUrl, - solaceMetaBrokerProtocol: "", - solaceMetaBrokerHostname: "", - solaceMetaBrokerPort: "", - solaceMetamsgVpn: soltestValidVpn, - solaceMetaUsernameEnv: "", - solaceMetaPasswordEnv: "", - solaceMetaUsername: soltestValidUsername, - solaceMetaPassword: soltestValidPassword, - solaceMetaqueueName: soltestValidQueueName, - solaceMetamsgCountTarget: soltestValidMsgCountTarget, - }, - false, - }, - // +Case - protocol + host + port - { - "#003 - protocol + host + port", - map[string]string{ - solaceMetaBrokerBaseUrl: "", - solaceMetaBrokerProtocol: soltestValidProtocol, - solaceMetaBrokerHostname: soltestValidHostname, - solaceMetaBrokerPort: soltestValidPort, + "": "", + solaceMetaBrokerBaseURL: soltestValidBaseURL, + // solaceMetaBrokerProtocol: "", + // solaceMetaBrokerHostname: "", + // solaceMetaBrokerPort: "", solaceMetamsgVpn: soltestValidVpn, solaceMetaUsernameEnv: "", solaceMetaPasswordEnv: "", @@ -99,68 +73,89 @@ var testParseSolaceMetadata = []testSolaceMetadata{ false, }, - // -Case - missing protocol - { - "#004 - missing protocol", - map[string]string{ - solaceMetaBrokerBaseUrl: "", - solaceMetaBrokerProtocol: "", - solaceMetaBrokerHostname: soltestValidHostname, - solaceMetaBrokerPort: soltestValidPort, - solaceMetamsgVpn: soltestValidVpn, - solaceMetaUsernameEnv: "", - solaceMetaPasswordEnv: "", - solaceMetaUsername: soltestValidUsername, - solaceMetaPassword: soltestValidPassword, - solaceMetaqueueName: soltestValidQueueName, - solaceMetamsgCountTarget: soltestValidMsgCountTarget, + /* + // +Case - protocol + host + port + { + "#003 - protocol + host + port", + map[string]string{ + solaceMetaBrokerBaseURL: "", + solaceMetaBrokerProtocol: soltestValidProtocol, + solaceMetaBrokerHostname: soltestValidHostname, + solaceMetaBrokerPort: soltestValidPort, + solaceMetamsgVpn: soltestValidVpn, + solaceMetaUsernameEnv: "", + solaceMetaPasswordEnv: "", + solaceMetaUsername: soltestValidUsername, + solaceMetaPassword: soltestValidPassword, + solaceMetaqueueName: soltestValidQueueName, + solaceMetamsgCountTarget: soltestValidMsgCountTarget, + }, + false, }, - true, - }, - // -Case - missing hostname - { - "#005 - missing hostname", - map[string]string{ - solaceMetaBrokerBaseUrl: "", - solaceMetaBrokerProtocol: soltestValidProtocol, - solaceMetaBrokerHostname: "", - solaceMetaBrokerPort: soltestValidPort, - solaceMetamsgVpn: soltestValidVpn, - solaceMetaUsernameEnv: "", - solaceMetaPasswordEnv: "", - solaceMetaUsername: soltestValidUsername, - solaceMetaPassword: soltestValidPassword, - solaceMetaqueueName: soltestValidQueueName, - solaceMetamsgCountTarget: soltestValidMsgCountTarget, + // -Case - missing protocol + { + "#004 - missing protocol", + map[string]string{ + solaceMetaBrokerBaseURL: "", + solaceMetaBrokerProtocol: "", + solaceMetaBrokerHostname: soltestValidHostname, + solaceMetaBrokerPort: soltestValidPort, + solaceMetamsgVpn: soltestValidVpn, + solaceMetaUsernameEnv: "", + solaceMetaPasswordEnv: "", + solaceMetaUsername: soltestValidUsername, + solaceMetaPassword: soltestValidPassword, + solaceMetaqueueName: soltestValidQueueName, + solaceMetamsgCountTarget: soltestValidMsgCountTarget, + }, + true, }, - true, - }, - // -Case - missing port - { - "#006 - missing port", - map[string]string{ - solaceMetaBrokerBaseUrl: "", - solaceMetaBrokerProtocol: soltestValidProtocol, - solaceMetaBrokerHostname: soltestValidHostname, - solaceMetaBrokerPort: "", - solaceMetamsgVpn: soltestValidVpn, - solaceMetaUsernameEnv: "", - solaceMetaPasswordEnv: "", - solaceMetaUsername: soltestValidUsername, - solaceMetaPassword: soltestValidPassword, - solaceMetaqueueName: soltestValidQueueName, - solaceMetamsgCountTarget: soltestValidMsgCountTarget, + // -Case - missing hostname + { + "#005 - missing hostname", + map[string]string{ + solaceMetaBrokerBaseURL: "", + solaceMetaBrokerProtocol: soltestValidProtocol, + solaceMetaBrokerHostname: "", + solaceMetaBrokerPort: soltestValidPort, + solaceMetamsgVpn: soltestValidVpn, + solaceMetaUsernameEnv: "", + solaceMetaPasswordEnv: "", + solaceMetaUsername: soltestValidUsername, + solaceMetaPassword: soltestValidPassword, + solaceMetaqueueName: soltestValidQueueName, + solaceMetamsgCountTarget: soltestValidMsgCountTarget, + }, + true, }, - true, - }, + // -Case - missing port + { + "#006 - missing port", + map[string]string{ + solaceMetaBrokerBaseURL: "", + solaceMetaBrokerProtocol: soltestValidProtocol, + solaceMetaBrokerHostname: soltestValidHostname, + solaceMetaBrokerPort: "", + solaceMetamsgVpn: soltestValidVpn, + solaceMetaUsernameEnv: "", + solaceMetaPasswordEnv: "", + solaceMetaUsername: soltestValidUsername, + solaceMetaPassword: soltestValidPassword, + solaceMetaqueueName: soltestValidQueueName, + solaceMetamsgCountTarget: soltestValidMsgCountTarget, + }, + true, + }, + + */ // -Case - missing username (clear) { "#007 - missing username (clear)", map[string]string{ - solaceMetaBrokerBaseUrl: "", - solaceMetaBrokerProtocol: soltestValidProtocol, - solaceMetaBrokerHostname: soltestValidHostname, - solaceMetaBrokerPort: soltestValidPort, + solaceMetaBrokerBaseURL: soltestValidBaseURL, + // solaceMetaBrokerProtocol: soltestValidProtocol, + // solaceMetaBrokerHostname: soltestValidHostname, + // solaceMetaBrokerPort: soltestValidPort, solaceMetamsgVpn: soltestValidVpn, solaceMetaUsernameEnv: "", solaceMetaPasswordEnv: "", @@ -175,10 +170,10 @@ var testParseSolaceMetadata = []testSolaceMetadata{ { "#008 - missing password (clear)", map[string]string{ - solaceMetaBrokerBaseUrl: "", - solaceMetaBrokerProtocol: soltestValidProtocol, - solaceMetaBrokerHostname: soltestValidHostname, - solaceMetaBrokerPort: soltestValidPort, + solaceMetaBrokerBaseURL: soltestValidBaseURL, + // solaceMetaBrokerProtocol: soltestValidProtocol, + // solaceMetaBrokerHostname: soltestValidHostname, + // solaceMetaBrokerPort: soltestValidPort, solaceMetamsgVpn: soltestValidVpn, solaceMetaUsernameEnv: "", solaceMetaPasswordEnv: "", @@ -193,10 +188,10 @@ var testParseSolaceMetadata = []testSolaceMetadata{ { "#009 - missing queueName", map[string]string{ - solaceMetaBrokerBaseUrl: "", - solaceMetaBrokerProtocol: soltestValidProtocol, - solaceMetaBrokerHostname: soltestValidHostname, - solaceMetaBrokerPort: soltestValidPort, + solaceMetaBrokerBaseURL: soltestValidBaseURL, + // solaceMetaBrokerProtocol: soltestValidProtocol, + // solaceMetaBrokerHostname: soltestValidHostname, + // solaceMetaBrokerPort: soltestValidPort, solaceMetamsgVpn: soltestValidVpn, solaceMetaUsernameEnv: "", solaceMetaPasswordEnv: "", @@ -211,10 +206,10 @@ var testParseSolaceMetadata = []testSolaceMetadata{ { "#010 - missing msgCountTarget", map[string]string{ - solaceMetaBrokerBaseUrl: "", - solaceMetaBrokerProtocol: soltestValidProtocol, - solaceMetaBrokerHostname: soltestValidHostname, - solaceMetaBrokerPort: soltestValidPort, + solaceMetaBrokerBaseURL: soltestValidBaseURL, + // solaceMetaBrokerProtocol: soltestValidProtocol, + // solaceMetaBrokerHostname: soltestValidHostname, + // solaceMetaBrokerPort: soltestValidPort, solaceMetamsgVpn: soltestValidVpn, solaceMetaUsernameEnv: "", solaceMetaPasswordEnv: "", @@ -230,10 +225,10 @@ var testParseSolaceMetadata = []testSolaceMetadata{ { "#011 - msgSpoolUsageTarget non-numeric", map[string]string{ - solaceMetaBrokerBaseUrl: "", - solaceMetaBrokerProtocol: soltestValidProtocol, - solaceMetaBrokerHostname: soltestValidHostname, - solaceMetaBrokerPort: soltestValidPort, + solaceMetaBrokerBaseURL: soltestValidBaseURL, + // solaceMetaBrokerProtocol: soltestValidProtocol, + // solaceMetaBrokerHostname: soltestValidHostname, + // solaceMetaBrokerPort: soltestValidPort, solaceMetamsgVpn: soltestValidVpn, solaceMetaUsernameEnv: "", solaceMetaPasswordEnv: "", @@ -248,10 +243,10 @@ var testParseSolaceMetadata = []testSolaceMetadata{ { "#012 - msgSpoolUsage non-numeric", map[string]string{ - solaceMetaBrokerBaseUrl: "", - solaceMetaBrokerProtocol: soltestValidProtocol, - solaceMetaBrokerHostname: soltestValidHostname, - solaceMetaBrokerPort: soltestValidPort, + solaceMetaBrokerBaseURL: soltestValidBaseURL, + // solaceMetaBrokerProtocol: soltestValidProtocol, + // solaceMetaBrokerHostname: soltestValidHostname, + // solaceMetaBrokerPort: soltestValidPort, solaceMetamsgVpn: soltestValidVpn, solaceMetaUsernameEnv: "", solaceMetaPasswordEnv: "", @@ -266,11 +261,7 @@ var testParseSolaceMetadata = []testSolaceMetadata{ { "#013 - brokerBaseUrl", map[string]string{ - "": "", - solaceMetaBrokerBaseUrl: soltestValidBaseUrl, - solaceMetaBrokerProtocol: "", - solaceMetaBrokerHostname: "", - solaceMetaBrokerPort: "", + solaceMetaBrokerBaseURL: soltestValidBaseURL, solaceMetamsgVpn: soltestValidVpn, solaceMetaUsernameEnv: "", solaceMetaPasswordEnv: "", @@ -288,14 +279,13 @@ var testSolaceEnvCreds = []testSolaceMetadata{ { "#101 - Connect with Credentials in env", map[string]string{ - // "": "", - solaceMetaBrokerBaseUrl: soltestValidBaseUrl, - solaceMetaBrokerProtocol: "", - solaceMetaBrokerHostname: "", - solaceMetaBrokerPort: "", - solaceMetamsgVpn: soltestValidVpn, - solaceMetaUsernameEnv: soltestEnvUsername, - solaceMetaPasswordEnv: soltestEnvPassword, + solaceMetaBrokerBaseURL: soltestValidBaseURL, + // solaceMetaBrokerProtocol: "", + // solaceMetaBrokerHostname: "", + // solaceMetaBrokerPort: "", + solaceMetamsgVpn: soltestValidVpn, + solaceMetaUsernameEnv: soltestEnvUsername, + solaceMetaPasswordEnv: soltestEnvPassword, // solaceMetaUsername: "", // solaceMetaPassword: "", solaceMetaqueueName: soltestValidQueueName, @@ -307,14 +297,13 @@ var testSolaceEnvCreds = []testSolaceMetadata{ { "#102 - Environment vars referenced but not found", map[string]string{ - // "": "", - solaceMetaBrokerBaseUrl: soltestValidBaseUrl, - solaceMetaBrokerProtocol: "", - solaceMetaBrokerHostname: "", - solaceMetaBrokerPort: "", - solaceMetamsgVpn: soltestValidVpn, - solaceMetaUsernameEnv: "SOLTEST_DNE", - solaceMetaPasswordEnv: "SOLTEST_DNE", + solaceMetaBrokerBaseURL: soltestValidBaseURL, + // solaceMetaBrokerProtocol: "", + // solaceMetaBrokerHostname: "", + // solaceMetaBrokerPort: "", + solaceMetamsgVpn: soltestValidVpn, + solaceMetaUsernameEnv: "SOLTEST_DNE", + solaceMetaPasswordEnv: "SOLTEST_DNE", // solaceMetaUsername: "", // solaceMetaPassword: "", solaceMetaqueueName: soltestValidQueueName, @@ -331,14 +320,13 @@ var testSolaceK8sSecretCreds = []testSolaceMetadata{ { "#201 - Connect with credentials from Auth Record (ENV VAR Present)", map[string]string{ - // "": "", - solaceMetaBrokerBaseUrl: soltestValidBaseUrl, - solaceMetaBrokerProtocol: "", - solaceMetaBrokerHostname: "", - solaceMetaBrokerPort: "", - solaceMetamsgVpn: soltestValidVpn, - solaceMetaUsernameEnv: soltestEnvUsername, - solaceMetaPasswordEnv: soltestEnvPassword, + solaceMetaBrokerBaseURL: soltestValidBaseURL, + // solaceMetaBrokerProtocol: "", + // solaceMetaBrokerHostname: "", + // solaceMetaBrokerPort: "", + solaceMetamsgVpn: soltestValidVpn, + solaceMetaUsernameEnv: soltestEnvUsername, + solaceMetaPasswordEnv: soltestEnvPassword, // solaceMetaUsername: "", // solaceMetaPassword: "", solaceMetaqueueName: soltestValidQueueName, @@ -350,12 +338,11 @@ var testSolaceK8sSecretCreds = []testSolaceMetadata{ { "#202 - Connect with credentials from Auth Record (ENV VAR and Clear Auth not present)", map[string]string{ - // "": "", - // solaceMetaBrokerBaseUrl: soltestValidBaseUrl, - solaceMetaBrokerProtocol: soltestValidProtocol, - solaceMetaBrokerHostname: soltestValidHostname, - solaceMetaBrokerPort: soltestValidPort, - solaceMetamsgVpn: soltestValidVpn, + solaceMetaBrokerBaseURL: soltestValidBaseURL, + // solaceMetaBrokerProtocol: soltestValidProtocol, + // solaceMetaBrokerHostname: soltestValidHostname, + // solaceMetaBrokerPort: soltestValidPort, + solaceMetamsgVpn: soltestValidVpn, // solaceMetaUsernameEnv: soltestEnvUsername, // solaceMetaPasswordEnv: soltestEnvPassword, // solaceMetaUsername: "", @@ -369,14 +356,13 @@ var testSolaceK8sSecretCreds = []testSolaceMetadata{ { "#203 - Connect with credentials from Auth Record (ENV VAR Present, Clear Auth not present)", map[string]string{ - // "": "", - solaceMetaBrokerBaseUrl: soltestValidBaseUrl, - solaceMetaBrokerProtocol: "", - solaceMetaBrokerHostname: "", - solaceMetaBrokerPort: "", - solaceMetamsgVpn: soltestValidVpn, - solaceMetaUsernameEnv: "SOLTEST_DNE", - solaceMetaPasswordEnv: "SOLTEST_DNE", + solaceMetaBrokerBaseURL: soltestValidBaseURL, + // solaceMetaBrokerProtocol: "", + // solaceMetaBrokerHostname: "", + // solaceMetaBrokerPort: "", + solaceMetamsgVpn: soltestValidVpn, + solaceMetaUsernameEnv: "SOLTEST_DNE", + solaceMetaPasswordEnv: "SOLTEST_DNE", // solaceMetaUsername: "", // solaceMetaPassword: "", solaceMetaqueueName: soltestValidQueueName, @@ -390,11 +376,10 @@ var testSolaceGetMetricSpecData = []testSolaceMetadata{ { "#401 - Get Metric Spec - msgCountTarget", map[string]string{ - "": "", - solaceMetaBrokerBaseUrl: soltestValidBaseUrl, - solaceMetaBrokerProtocol: "", - solaceMetaBrokerHostname: "", - solaceMetaBrokerPort: "", + solaceMetaBrokerBaseURL: soltestValidBaseURL, + // solaceMetaBrokerProtocol: "", + // solaceMetaBrokerHostname: "", + // solaceMetaBrokerPort: "", solaceMetamsgVpn: soltestValidVpn, solaceMetaUsernameEnv: "", solaceMetaPasswordEnv: "", @@ -409,17 +394,16 @@ var testSolaceGetMetricSpecData = []testSolaceMetadata{ { "#402 - Get Metric Spec - msgSpoolUsageTarget", map[string]string{ - "": "", - solaceMetaBrokerBaseUrl: soltestValidBaseUrl, - solaceMetaBrokerProtocol: "", - solaceMetaBrokerHostname: "", - solaceMetaBrokerPort: "", - solaceMetamsgVpn: soltestValidVpn, - solaceMetaUsernameEnv: "", - solaceMetaPasswordEnv: "", - solaceMetaUsername: soltestValidUsername, - solaceMetaPassword: soltestValidPassword, - solaceMetaqueueName: soltestValidQueueName, + solaceMetaBrokerBaseURL: soltestValidBaseURL, + // solaceMetaBrokerProtocol: "", + // solaceMetaBrokerHostname: "", + // solaceMetaBrokerPort: "", + solaceMetamsgVpn: soltestValidVpn, + solaceMetaUsernameEnv: "", + solaceMetaPasswordEnv: "", + solaceMetaUsername: soltestValidUsername, + solaceMetaPassword: soltestValidPassword, + solaceMetaqueueName: soltestValidQueueName, // solaceMetamsgCountTarget: soltestValidMsgCountTarget, solaceMetamsgSpoolUsageTarget: soltestValidMsgSpoolTarget, }, @@ -428,11 +412,10 @@ var testSolaceGetMetricSpecData = []testSolaceMetadata{ { "#403 - Get Metric Spec - BOTH msgSpoolUsage and msgCountTarget", map[string]string{ - "": "", - solaceMetaBrokerBaseUrl: soltestValidBaseUrl, - solaceMetaBrokerProtocol: "", - solaceMetaBrokerHostname: "", - solaceMetaBrokerPort: "", + solaceMetaBrokerBaseURL: soltestValidBaseURL, + // solaceMetaBrokerProtocol: "", + // solaceMetaBrokerHostname: "", + // solaceMetaBrokerPort: "", solaceMetamsgVpn: soltestValidVpn, solaceMetaUsernameEnv: "", solaceMetaPasswordEnv: "", @@ -447,17 +430,16 @@ var testSolaceGetMetricSpecData = []testSolaceMetadata{ { "#404 - Get Metric Spec - BOTH MISSING", map[string]string{ - "": "", - solaceMetaBrokerBaseUrl: soltestValidBaseUrl, - solaceMetaBrokerProtocol: "", - solaceMetaBrokerHostname: "", - solaceMetaBrokerPort: "", - solaceMetamsgVpn: soltestValidVpn, - solaceMetaUsernameEnv: "", - solaceMetaPasswordEnv: "", - solaceMetaUsername: soltestValidUsername, - solaceMetaPassword: soltestValidPassword, - solaceMetaqueueName: soltestValidQueueName, + solaceMetaBrokerBaseURL: soltestValidBaseURL, + // solaceMetaBrokerProtocol: "", + // solaceMetaBrokerHostname: "", + // solaceMetaBrokerPort: "", + solaceMetamsgVpn: soltestValidVpn, + solaceMetaUsernameEnv: "", + solaceMetaPasswordEnv: "", + solaceMetaUsername: soltestValidUsername, + solaceMetaPassword: soltestValidPassword, + solaceMetaqueueName: soltestValidQueueName, // solaceMetamsgCountTarget: soltestValidMsgCountTarget, // solaceMetamsgSpoolUsageTarget: soltestValidMsgSpoolTarget, }, @@ -466,11 +448,10 @@ var testSolaceGetMetricSpecData = []testSolaceMetadata{ { "#405 - Get Metric Spec - BOTH ZERO", map[string]string{ - "": "", - solaceMetaBrokerBaseUrl: soltestValidBaseUrl, - solaceMetaBrokerProtocol: "", - solaceMetaBrokerHostname: "", - solaceMetaBrokerPort: "", + solaceMetaBrokerBaseURL: soltestValidBaseURL, + // solaceMetaBrokerProtocol: "", + // solaceMetaBrokerHostname: "", + // solaceMetaBrokerPort: "", solaceMetamsgVpn: soltestValidVpn, solaceMetaUsernameEnv: "", solaceMetaPasswordEnv: "", @@ -485,11 +466,10 @@ var testSolaceGetMetricSpecData = []testSolaceMetadata{ { "#406 - Get Metric Spec - ONE ZERO; OTHER VALID", map[string]string{ - "": "", - solaceMetaBrokerBaseUrl: soltestValidBaseUrl, - solaceMetaBrokerProtocol: "", - solaceMetaBrokerHostname: "", - solaceMetaBrokerPort: "", + solaceMetaBrokerBaseURL: soltestValidBaseURL, + // solaceMetaBrokerProtocol: "", + // solaceMetaBrokerHostname: "", + // solaceMetaBrokerPort: "", solaceMetamsgVpn: soltestValidVpn, solaceMetaUsernameEnv: "", solaceMetaPasswordEnv: "", @@ -504,48 +484,48 @@ var testSolaceGetMetricSpecData = []testSolaceMetadata{ } var testSolaceExpectedMetricNames = map[string]string{ - solaceScalerId + "-" + soltestValidVpn + "-" + soltestValidQueueName + "-" + "msgcount": "", - solaceScalerId + "-" + soltestValidVpn + "-" + soltestValidQueueName + "-" + "msgspoolusage": "", + solaceScalerID + "-" + soltestValidVpn + "-" + soltestValidQueueName + "-" + "msgcount": "", + solaceScalerID + "-" + soltestValidVpn + "-" + soltestValidQueueName + "-" + "msgspoolusage": "", } func TestSolaceParseSolaceMetadata(t *testing.T) { for _, testData := range testParseSolaceMetadata { - fmt.Print(testData.testId) + fmt.Print(testData.testID) _, err := parseSolaceMetadata(&ScalerConfig{ResolvedEnv: nil, TriggerMetadata: testData.metadata, AuthParams: nil}) switch { case err != nil && !testData.isError: - t.Error("Expected success but got error: ", err) + t.Error("expected success but got error: ", err) fmt.Println(" --> FAIL") case testData.isError && err == nil: - t.Error("Expected error but got success") + t.Error("expected error but got success") fmt.Println(" --> FAIL") default: fmt.Println(" --> PASS") } } for _, testData := range testSolaceEnvCreds { - fmt.Print(testData.testId) + fmt.Print(testData.testID) _, err := parseSolaceMetadata(&ScalerConfig{ResolvedEnv: testDataSolaceResolvedEnvVALID, TriggerMetadata: testData.metadata, AuthParams: nil}) switch { case err != nil && !testData.isError: - t.Error("Expected success but got error: ", err) + t.Error("expected success but got error: ", err) fmt.Println(" --> FAIL") case testData.isError && err == nil: - t.Error("Expected error but got success") + t.Error("expected error but got success") fmt.Println(" --> FAIL") default: fmt.Println(" --> PASS") } } for _, testData := range testSolaceK8sSecretCreds { - fmt.Print(testData.testId) + fmt.Print(testData.testID) _, err := parseSolaceMetadata(&ScalerConfig{ResolvedEnv: nil, TriggerMetadata: testData.metadata, AuthParams: testDataSolaceAuthParamsVALID}) switch { case err != nil && !testData.isError: - t.Error("Expected success but got error: ", err) + t.Error("expected success but got error: ", err) fmt.Println(" --> FAIL") case testData.isError && err == nil: - t.Error("Expected error but got success") + t.Error("expected error but got success") fmt.Println(" --> FAIL") default: fmt.Println(" --> PASS") @@ -555,9 +535,8 @@ func TestSolaceParseSolaceMetadata(t *testing.T) { func TestSolaceGetMetricSpec(t *testing.T) { for idx := 0; idx < len(testSolaceGetMetricSpecData); idx++ { - testData := testSolaceGetMetricSpecData[idx] - fmt.Print(testData.testId) + fmt.Print(testData.testID) var err error var solaceMeta *SolaceMetadata solaceMeta, err = parseSolaceMetadata(&ScalerConfig{ResolvedEnv: testDataSolaceResolvedEnvVALID, TriggerMetadata: testData.metadata, AuthParams: testDataSolaceAuthParamsVALID}) @@ -571,23 +550,22 @@ func TestSolaceGetMetricSpec(t *testing.T) { } var metric []v2beta2.MetricSpec - if metric = testSolaceScaler.GetMetricSpecForScaling(); metric == nil || len(metric) == 0 { - err = fmt.Errorf("Metric value not found\n") + if metric = testSolaceScaler.GetMetricSpecForScaling(); len(metric) == 0 { + err = fmt.Errorf("metric value not found") } else { metricName := metric[0].External.Metric.Name if _, ok := testSolaceExpectedMetricNames[metricName]; ok == false { - err = fmt.Errorf("Expected Metric value not found\n") + err = fmt.Errorf("expected Metric value not found") } } } - switch { case testData.isError && err == nil: fmt.Println(" --> FAIL") - t.Error("Expected to fail but passed", err) + t.Error("expected to fail but passed", err) case !testData.isError && err != nil: fmt.Println(" --> FAIL") - t.Error("Expected success but failed", err) + t.Error("expected success but failed", err) default: fmt.Println(" --> PASS") } diff --git a/tests/scalers/solace-helpers.ts b/tests/scalers/solace-helpers.ts index 8745e3436b3..7cb5f0b5db5 100644 --- a/tests/scalers/solace-helpers.ts +++ b/tests/scalers/solace-helpers.ts @@ -12,7 +12,7 @@ export class SolaceHelper { ) t.is( 0, - sh.exec(`helm repo update`).code, + sh.exec(`helm repo update`).code, 'Should update Helm Charts' ) } @@ -21,7 +21,7 @@ export class SolaceHelper { t.is( 0, sh.exec(`kubectl create namespace ${testNamespace}`).code, 'Should create solace namespace' - ) + ) t.is( 0, sh.exec(`helm install kedalab solacecharts/pubsubplus-dev --namespace ${testNamespace} --set solace.usernameAdminPassword=KedaLabAdminPwd1 --set storage.persistent=false`).code, 'Solace Broker should install' @@ -145,7 +145,7 @@ spec: - type: Pods value: 10 periodSeconds: 10 - selectPolicy: Max + selectPolicy: Max triggers: - type: solace-queue metadata: @@ -154,7 +154,7 @@ spec: queueName: SCALED_CONSUMER_QUEUE1 msgCountTarget: '20' msgSpoolUsageTarget: '100000' - authenticationRef: + authenticationRef: name: kedalab-trigger-auth ` From 25de86caf5e671349b28f7287b2c86d8b60c7286 Mon Sep 17 00:00:00 2001 From: Dennis Brinley Date: Mon, 12 Jul 2021 14:18:47 -0400 Subject: [PATCH 5/7] Mods for linting complete and tested -- additional minor mods Code cleanup, removed comments, unused meta fields Signed-off-by: Dennis Brinley By making a contribution to this project, I certify that: (a) The contribution was created in whole or in part by me and I have the right to submit it under the open source license indicated in the file; or (b) The contribution is based upon previous work that, to the best of my knowledge, is covered under an appropriate open source license and I have the right under that license to submit that work with modifications, whether created in whole or in part by me, under the same open source license (unless I am permitted to submit under a different license), as indicated in the file; or (c) The contribution was provided directly to me by some other person who certified (a), (b) or (c) and I have not modified it. (d) I understand and agree that this project and the contribution are public and that a record of the contribution (including all personal information I submit with it, including my sign-off) is maintained indefinitely and may be redistributed consistent with this project or the open source license(s) involved. --- pkg/scalers/solace_scaler.go | 93 ++------------- pkg/scalers/solace_scaler_test.go | 190 ++++-------------------------- tests/scalers/solace-helpers.ts | 2 +- 3 files changed, 36 insertions(+), 249 deletions(-) diff --git a/pkg/scalers/solace_scaler.go b/pkg/scalers/solace_scaler.go index 2f4d987a564..6026abcaca6 100644 --- a/pkg/scalers/solace_scaler.go +++ b/pkg/scalers/solace_scaler.go @@ -22,7 +22,6 @@ const ( solaceExtMetricType = "External" solaceScalerID = "solace" // REST ENDPOINT String Patterns - // solaceBrokerBaseURLTemplate = "%s://%s:%s" solaceSempEndpointURLTemplate = "%s/%s/%s/monitor/msgVpns/%s/%ss/%s" // SEMP REST API Context solaceAPIName = "SEMP" @@ -32,12 +31,7 @@ const ( solaceFoundMetaFalse = "required Field %s NOT FOUND in Solace Metadata" // YAML Configuration Metadata Field Names // Broker Identifiers - solaceMetaBrokerBaseURL = "brokerBaseUrl" - - // solaceMetaBrokerProtocol = "brokerProtocol" - // solaceMetaBrokerHostname = "brokerHostname" - // solaceMetaBrokerPort = "brokerPort" - + solaceMetaSempBaseURL = "solaceSempBaseURL" // Credential Identifiers solaceMetaUsername = "username" solaceMetaPassword = "password" @@ -69,12 +63,8 @@ type SolaceScaler struct { type SolaceMetadata struct { // Full SEMP URL to target queue (CONSTRUCTED IN CODE) - endpointURL string - // Protocol-Host-Port: http://host-name:12345 - brokerBaseURL string - // brokerProtocol string - // brokerHostname string - // brokerPort string + endpointURL string + solaceSempURL string // Solace Message VPN messageVpn string queueName string @@ -139,39 +129,10 @@ func NewSolaceScaler(config *ScalerConfig) (Scaler, error) { func parseSolaceMetadata(config *ScalerConfig) (*SolaceMetadata, error) { meta := SolaceMetadata{} // GET THE SEMP API ENDPOINT - // First look for brokerBaseURL in config; Use components if not found - if val, ok := config.TriggerMetadata[solaceMetaBrokerBaseURL]; ok && val != "" { - meta.brokerBaseURL = val + if val, ok := config.TriggerMetadata[solaceMetaSempBaseURL]; ok && val != "" { + meta.solaceSempURL = val } else { - /* - // IF brokerBaseURL is not present, then get components - // GET Protocol - if val, ok := config.TriggerMetadata[solaceMetaBrokerProtocol]; ok && (val == "https" || val == "http") { - meta.brokerProtocol = val - } else { - return nil, fmt.Errorf(solaceFoundMetaFalse, solaceMetaBrokerProtocol) - } - // GET Hostname - if val, ok := config.TriggerMetadata[solaceMetaBrokerHostname]; ok && val != "" { - meta.brokerHostname = val - } else { - return nil, fmt.Errorf(solaceFoundMetaFalse, solaceMetaBrokerHostname) - } - // GET Port - if val, ok := config.TriggerMetadata[solaceMetaBrokerPort]; ok && val != "" { - if _, err := strconv.Atoi(val); err == nil { - meta.brokerPort = val - } else { - return nil, fmt.Errorf("can't parse brokerPort, not a valid integer: %s", err) - } - } else { - return nil, fmt.Errorf(solaceFoundMetaFalse, solaceMetaBrokerPort) - } - // Format Solace Broker Base URL from components - meta.brokerBaseURL = fmt.Sprintf(solaceBrokerBaseURLTemplate, meta.brokerProtocol, meta.brokerHostname, meta.brokerPort) - - */ - return nil, fmt.Errorf(solaceFoundMetaFalse, solaceMetaBrokerBaseURL) + return nil, fmt.Errorf(solaceFoundMetaFalse, solaceMetaSempBaseURL) } // GET Message VPN if val, ok := config.TriggerMetadata[solaceMetamsgVpn]; ok && val != "" { @@ -179,7 +140,6 @@ func parseSolaceMetadata(config *ScalerConfig) (*SolaceMetadata, error) { } else { return nil, fmt.Errorf(solaceFoundMetaFalse, solaceMetamsgVpn) } - // GET Queue Name if val, ok := config.TriggerMetadata[solaceMetaqueueName]; ok && val != "" { meta.queueName = val @@ -196,7 +156,6 @@ func parseSolaceMetadata(config *ScalerConfig) (*SolaceMetadata, error) { return nil, fmt.Errorf("can't parse [%s], not a valid integer: %s", solaceMetamsgCountTarget, err) } } - // GET msgSpoolUsageTarget if val, ok := config.TriggerMetadata[solaceMetamsgSpoolUsageTarget]; ok && val != "" { if msgSpoolUsage, err := strconv.Atoi(val); err == nil { @@ -214,48 +173,14 @@ func parseSolaceMetadata(config *ScalerConfig) (*SolaceMetadata, error) { // Format Solace SEMP Queue Endpoint (REST URL) meta.endpointURL = fmt.Sprintf( solaceSempEndpointURLTemplate, - meta.brokerBaseURL, + meta.solaceSempURL, solaceAPIName, solaceAPIVersion, meta.messageVpn, solaceAPIObjectTypeQueue, meta.queueName) - /* - // GET CREDENTIALS - // The username must be a valid broker ADMIN user identifier with read access to SEMP for the broker, VPN, and relevant objects - // The scaler will attempt to acquire username and then password independently. For each: - // - Search K8S Secret (Encoded) - // - Search environment variable specified by config at 'usernameEnv' / 'passwordEnv' - // - Search 'username' / 'password' fields (Clear Text) - // Get username - if usernameSecret, ok := config.AuthParams[solaceMetaUsername]; ok && usernameSecret != "" { - meta.username = usernameSecret - } else if usernameEnv, ok := config.TriggerMetadata[solaceMetaUsernameEnv]; ok && usernameEnv != "" { - if resolvedUser, ok := config.ResolvedEnv[config.TriggerMetadata[solaceMetaUsernameEnv]]; ok && resolvedUser != "" { - meta.username = resolvedUser - } else { - return nil, fmt.Errorf("username could not be resolved from the environment variable: %s", usernameEnv) - } - } else if usernameClear, ok := config.TriggerMetadata[solaceMetaUsername]; ok && usernameClear != "" { - meta.username = usernameClear - } else { - return nil, fmt.Errorf("username is required and not found in K8Secret, environment, or clear text") - } - // Get Password - if passwordSecret, ok := config.AuthParams[solaceMetaPassword]; ok && passwordSecret != "" { - meta.password = passwordSecret - } else if passwordEnv, ok := config.TriggerMetadata[solaceMetaPasswordEnv]; ok && passwordEnv != "" { - if resolvedPassword, ok := config.ResolvedEnv[config.TriggerMetadata[solaceMetaPasswordEnv]]; ok && resolvedPassword != "" { - meta.password = resolvedPassword - } else { - return nil, fmt.Errorf("password could not be resolved from the environment variable: %s", passwordEnv) - } - } else if passwordClear, ok := config.TriggerMetadata[solaceMetaPassword]; ok && passwordClear != "" { - meta.password = passwordClear - } else { - return nil, fmt.Errorf("password is required and not found in K8Secret, environment, or clear text") - } - */ + + // Get Credentials var e error if meta.username, meta.password, e = getSolaceSempCredentials(config); e != nil { return nil, e diff --git a/pkg/scalers/solace_scaler_test.go b/pkg/scalers/solace_scaler_test.go index 1832711406a..d2e1ecff4be 100644 --- a/pkg/scalers/solace_scaler_test.go +++ b/pkg/scalers/solace_scaler_test.go @@ -15,19 +15,15 @@ type testSolaceMetadata struct { } var ( - soltestValidBaseURL = "http://localhost:8080" - // soltestValidProtocol = "http" - // soltestValidHostname = "localhost" - // soltestValidPort = "8080" + soltestValidBaseURL = "http://localhost:8080" soltestValidUsername = "admin" soltestValidPassword = "admin" soltestValidVpn = "dennis_vpn" soltestValidQueueName = "queue3" soltestValidMsgCountTarget = "10" soltestValidMsgSpoolTarget = "20" - - soltestEnvUsername = "SOLTEST_USERNAME" - soltestEnvPassword = "SOLTEST_PASSWORD" + soltestEnvUsername = "SOLTEST_USERNAME" + soltestEnvPassword = "SOLTEST_PASSWORD" ) // AUTH RECORD FOR TEST @@ -44,24 +40,17 @@ var testDataSolaceResolvedEnvVALID = map[string]string{ // TEST CASES FOR SolaceParseMetadata() var testParseSolaceMetadata = []testSolaceMetadata{ - // IF brokerBaseUrl is present, use it without interpretation as the base URL: http://my.host.domain:1234 - // IF brokerBaseUrl in not present, Use protocol, host, and port - // Empty { "#001 - EMPTY", map[string]string{}, true, }, - // +Case - brokerBaseUrl { "#002 - brokerBaseUrl", map[string]string{ - "": "", - solaceMetaBrokerBaseURL: soltestValidBaseURL, - // solaceMetaBrokerProtocol: "", - // solaceMetaBrokerHostname: "", - // solaceMetaBrokerPort: "", + "": "", + solaceMetaSempBaseURL: soltestValidBaseURL, solaceMetamsgVpn: soltestValidVpn, solaceMetaUsernameEnv: "", solaceMetaPasswordEnv: "", @@ -72,90 +61,11 @@ var testParseSolaceMetadata = []testSolaceMetadata{ }, false, }, - - /* - // +Case - protocol + host + port - { - "#003 - protocol + host + port", - map[string]string{ - solaceMetaBrokerBaseURL: "", - solaceMetaBrokerProtocol: soltestValidProtocol, - solaceMetaBrokerHostname: soltestValidHostname, - solaceMetaBrokerPort: soltestValidPort, - solaceMetamsgVpn: soltestValidVpn, - solaceMetaUsernameEnv: "", - solaceMetaPasswordEnv: "", - solaceMetaUsername: soltestValidUsername, - solaceMetaPassword: soltestValidPassword, - solaceMetaqueueName: soltestValidQueueName, - solaceMetamsgCountTarget: soltestValidMsgCountTarget, - }, - false, - }, - // -Case - missing protocol - { - "#004 - missing protocol", - map[string]string{ - solaceMetaBrokerBaseURL: "", - solaceMetaBrokerProtocol: "", - solaceMetaBrokerHostname: soltestValidHostname, - solaceMetaBrokerPort: soltestValidPort, - solaceMetamsgVpn: soltestValidVpn, - solaceMetaUsernameEnv: "", - solaceMetaPasswordEnv: "", - solaceMetaUsername: soltestValidUsername, - solaceMetaPassword: soltestValidPassword, - solaceMetaqueueName: soltestValidQueueName, - solaceMetamsgCountTarget: soltestValidMsgCountTarget, - }, - true, - }, - // -Case - missing hostname - { - "#005 - missing hostname", - map[string]string{ - solaceMetaBrokerBaseURL: "", - solaceMetaBrokerProtocol: soltestValidProtocol, - solaceMetaBrokerHostname: "", - solaceMetaBrokerPort: soltestValidPort, - solaceMetamsgVpn: soltestValidVpn, - solaceMetaUsernameEnv: "", - solaceMetaPasswordEnv: "", - solaceMetaUsername: soltestValidUsername, - solaceMetaPassword: soltestValidPassword, - solaceMetaqueueName: soltestValidQueueName, - solaceMetamsgCountTarget: soltestValidMsgCountTarget, - }, - true, - }, - // -Case - missing port - { - "#006 - missing port", - map[string]string{ - solaceMetaBrokerBaseURL: "", - solaceMetaBrokerProtocol: soltestValidProtocol, - solaceMetaBrokerHostname: soltestValidHostname, - solaceMetaBrokerPort: "", - solaceMetamsgVpn: soltestValidVpn, - solaceMetaUsernameEnv: "", - solaceMetaPasswordEnv: "", - solaceMetaUsername: soltestValidUsername, - solaceMetaPassword: soltestValidPassword, - solaceMetaqueueName: soltestValidQueueName, - solaceMetamsgCountTarget: soltestValidMsgCountTarget, - }, - true, - }, - - */ // -Case - missing username (clear) { "#007 - missing username (clear)", map[string]string{ - solaceMetaBrokerBaseURL: soltestValidBaseURL, - // solaceMetaBrokerProtocol: soltestValidProtocol, - // solaceMetaBrokerHostname: soltestValidHostname, - // solaceMetaBrokerPort: soltestValidPort, + solaceMetaSempBaseURL: soltestValidBaseURL, solaceMetamsgVpn: soltestValidVpn, solaceMetaUsernameEnv: "", solaceMetaPasswordEnv: "", @@ -170,10 +80,7 @@ var testParseSolaceMetadata = []testSolaceMetadata{ { "#008 - missing password (clear)", map[string]string{ - solaceMetaBrokerBaseURL: soltestValidBaseURL, - // solaceMetaBrokerProtocol: soltestValidProtocol, - // solaceMetaBrokerHostname: soltestValidHostname, - // solaceMetaBrokerPort: soltestValidPort, + solaceMetaSempBaseURL: soltestValidBaseURL, solaceMetamsgVpn: soltestValidVpn, solaceMetaUsernameEnv: "", solaceMetaPasswordEnv: "", @@ -188,10 +95,7 @@ var testParseSolaceMetadata = []testSolaceMetadata{ { "#009 - missing queueName", map[string]string{ - solaceMetaBrokerBaseURL: soltestValidBaseURL, - // solaceMetaBrokerProtocol: soltestValidProtocol, - // solaceMetaBrokerHostname: soltestValidHostname, - // solaceMetaBrokerPort: soltestValidPort, + solaceMetaSempBaseURL: soltestValidBaseURL, solaceMetamsgVpn: soltestValidVpn, solaceMetaUsernameEnv: "", solaceMetaPasswordEnv: "", @@ -206,10 +110,7 @@ var testParseSolaceMetadata = []testSolaceMetadata{ { "#010 - missing msgCountTarget", map[string]string{ - solaceMetaBrokerBaseURL: soltestValidBaseURL, - // solaceMetaBrokerProtocol: soltestValidProtocol, - // solaceMetaBrokerHostname: soltestValidHostname, - // solaceMetaBrokerPort: soltestValidPort, + solaceMetaSempBaseURL: soltestValidBaseURL, solaceMetamsgVpn: soltestValidVpn, solaceMetaUsernameEnv: "", solaceMetaPasswordEnv: "", @@ -225,10 +126,7 @@ var testParseSolaceMetadata = []testSolaceMetadata{ { "#011 - msgSpoolUsageTarget non-numeric", map[string]string{ - solaceMetaBrokerBaseURL: soltestValidBaseURL, - // solaceMetaBrokerProtocol: soltestValidProtocol, - // solaceMetaBrokerHostname: soltestValidHostname, - // solaceMetaBrokerPort: soltestValidPort, + solaceMetaSempBaseURL: soltestValidBaseURL, solaceMetamsgVpn: soltestValidVpn, solaceMetaUsernameEnv: "", solaceMetaPasswordEnv: "", @@ -243,10 +141,7 @@ var testParseSolaceMetadata = []testSolaceMetadata{ { "#012 - msgSpoolUsage non-numeric", map[string]string{ - solaceMetaBrokerBaseURL: soltestValidBaseURL, - // solaceMetaBrokerProtocol: soltestValidProtocol, - // solaceMetaBrokerHostname: soltestValidHostname, - // solaceMetaBrokerPort: soltestValidPort, + solaceMetaSempBaseURL: soltestValidBaseURL, solaceMetamsgVpn: soltestValidVpn, solaceMetaUsernameEnv: "", solaceMetaPasswordEnv: "", @@ -261,7 +156,7 @@ var testParseSolaceMetadata = []testSolaceMetadata{ { "#013 - brokerBaseUrl", map[string]string{ - solaceMetaBrokerBaseURL: soltestValidBaseURL, + solaceMetaSempBaseURL: soltestValidBaseURL, solaceMetamsgVpn: soltestValidVpn, solaceMetaUsernameEnv: "", solaceMetaPasswordEnv: "", @@ -279,10 +174,7 @@ var testSolaceEnvCreds = []testSolaceMetadata{ { "#101 - Connect with Credentials in env", map[string]string{ - solaceMetaBrokerBaseURL: soltestValidBaseURL, - // solaceMetaBrokerProtocol: "", - // solaceMetaBrokerHostname: "", - // solaceMetaBrokerPort: "", + solaceMetaSempBaseURL: soltestValidBaseURL, solaceMetamsgVpn: soltestValidVpn, solaceMetaUsernameEnv: soltestEnvUsername, solaceMetaPasswordEnv: soltestEnvPassword, @@ -297,10 +189,7 @@ var testSolaceEnvCreds = []testSolaceMetadata{ { "#102 - Environment vars referenced but not found", map[string]string{ - solaceMetaBrokerBaseURL: soltestValidBaseURL, - // solaceMetaBrokerProtocol: "", - // solaceMetaBrokerHostname: "", - // solaceMetaBrokerPort: "", + solaceMetaSempBaseURL: soltestValidBaseURL, solaceMetamsgVpn: soltestValidVpn, solaceMetaUsernameEnv: "SOLTEST_DNE", solaceMetaPasswordEnv: "SOLTEST_DNE", @@ -320,10 +209,7 @@ var testSolaceK8sSecretCreds = []testSolaceMetadata{ { "#201 - Connect with credentials from Auth Record (ENV VAR Present)", map[string]string{ - solaceMetaBrokerBaseURL: soltestValidBaseURL, - // solaceMetaBrokerProtocol: "", - // solaceMetaBrokerHostname: "", - // solaceMetaBrokerPort: "", + solaceMetaSempBaseURL: soltestValidBaseURL, solaceMetamsgVpn: soltestValidVpn, solaceMetaUsernameEnv: soltestEnvUsername, solaceMetaPasswordEnv: soltestEnvPassword, @@ -338,11 +224,8 @@ var testSolaceK8sSecretCreds = []testSolaceMetadata{ { "#202 - Connect with credentials from Auth Record (ENV VAR and Clear Auth not present)", map[string]string{ - solaceMetaBrokerBaseURL: soltestValidBaseURL, - // solaceMetaBrokerProtocol: soltestValidProtocol, - // solaceMetaBrokerHostname: soltestValidHostname, - // solaceMetaBrokerPort: soltestValidPort, - solaceMetamsgVpn: soltestValidVpn, + solaceMetaSempBaseURL: soltestValidBaseURL, + solaceMetamsgVpn: soltestValidVpn, // solaceMetaUsernameEnv: soltestEnvUsername, // solaceMetaPasswordEnv: soltestEnvPassword, // solaceMetaUsername: "", @@ -356,10 +239,7 @@ var testSolaceK8sSecretCreds = []testSolaceMetadata{ { "#203 - Connect with credentials from Auth Record (ENV VAR Present, Clear Auth not present)", map[string]string{ - solaceMetaBrokerBaseURL: soltestValidBaseURL, - // solaceMetaBrokerProtocol: "", - // solaceMetaBrokerHostname: "", - // solaceMetaBrokerPort: "", + solaceMetaSempBaseURL: soltestValidBaseURL, solaceMetamsgVpn: soltestValidVpn, solaceMetaUsernameEnv: "SOLTEST_DNE", solaceMetaPasswordEnv: "SOLTEST_DNE", @@ -376,10 +256,7 @@ var testSolaceGetMetricSpecData = []testSolaceMetadata{ { "#401 - Get Metric Spec - msgCountTarget", map[string]string{ - solaceMetaBrokerBaseURL: soltestValidBaseURL, - // solaceMetaBrokerProtocol: "", - // solaceMetaBrokerHostname: "", - // solaceMetaBrokerPort: "", + solaceMetaSempBaseURL: soltestValidBaseURL, solaceMetamsgVpn: soltestValidVpn, solaceMetaUsernameEnv: "", solaceMetaPasswordEnv: "", @@ -394,10 +271,7 @@ var testSolaceGetMetricSpecData = []testSolaceMetadata{ { "#402 - Get Metric Spec - msgSpoolUsageTarget", map[string]string{ - solaceMetaBrokerBaseURL: soltestValidBaseURL, - // solaceMetaBrokerProtocol: "", - // solaceMetaBrokerHostname: "", - // solaceMetaBrokerPort: "", + solaceMetaSempBaseURL: soltestValidBaseURL, solaceMetamsgVpn: soltestValidVpn, solaceMetaUsernameEnv: "", solaceMetaPasswordEnv: "", @@ -412,10 +286,7 @@ var testSolaceGetMetricSpecData = []testSolaceMetadata{ { "#403 - Get Metric Spec - BOTH msgSpoolUsage and msgCountTarget", map[string]string{ - solaceMetaBrokerBaseURL: soltestValidBaseURL, - // solaceMetaBrokerProtocol: "", - // solaceMetaBrokerHostname: "", - // solaceMetaBrokerPort: "", + solaceMetaSempBaseURL: soltestValidBaseURL, solaceMetamsgVpn: soltestValidVpn, solaceMetaUsernameEnv: "", solaceMetaPasswordEnv: "", @@ -430,10 +301,7 @@ var testSolaceGetMetricSpecData = []testSolaceMetadata{ { "#404 - Get Metric Spec - BOTH MISSING", map[string]string{ - solaceMetaBrokerBaseURL: soltestValidBaseURL, - // solaceMetaBrokerProtocol: "", - // solaceMetaBrokerHostname: "", - // solaceMetaBrokerPort: "", + solaceMetaSempBaseURL: soltestValidBaseURL, solaceMetamsgVpn: soltestValidVpn, solaceMetaUsernameEnv: "", solaceMetaPasswordEnv: "", @@ -448,10 +316,7 @@ var testSolaceGetMetricSpecData = []testSolaceMetadata{ { "#405 - Get Metric Spec - BOTH ZERO", map[string]string{ - solaceMetaBrokerBaseURL: soltestValidBaseURL, - // solaceMetaBrokerProtocol: "", - // solaceMetaBrokerHostname: "", - // solaceMetaBrokerPort: "", + solaceMetaSempBaseURL: soltestValidBaseURL, solaceMetamsgVpn: soltestValidVpn, solaceMetaUsernameEnv: "", solaceMetaPasswordEnv: "", @@ -466,10 +331,7 @@ var testSolaceGetMetricSpecData = []testSolaceMetadata{ { "#406 - Get Metric Spec - ONE ZERO; OTHER VALID", map[string]string{ - solaceMetaBrokerBaseURL: soltestValidBaseURL, - // solaceMetaBrokerProtocol: "", - // solaceMetaBrokerHostname: "", - // solaceMetaBrokerPort: "", + solaceMetaSempBaseURL: soltestValidBaseURL, solaceMetamsgVpn: soltestValidVpn, solaceMetaUsernameEnv: "", solaceMetaPasswordEnv: "", @@ -484,8 +346,8 @@ var testSolaceGetMetricSpecData = []testSolaceMetadata{ } var testSolaceExpectedMetricNames = map[string]string{ - solaceScalerID + "-" + soltestValidVpn + "-" + soltestValidQueueName + "-" + "msgcount": "", - solaceScalerID + "-" + soltestValidVpn + "-" + soltestValidQueueName + "-" + "msgspoolusage": "", + solaceScalerID + "-" + soltestValidVpn + "-" + soltestValidQueueName + "-" + solaceTriggermsgcount: "", + solaceScalerID + "-" + soltestValidVpn + "-" + soltestValidQueueName + "-" + solaceTriggermsgspoolusage: "", } func TestSolaceParseSolaceMetadata(t *testing.T) { diff --git a/tests/scalers/solace-helpers.ts b/tests/scalers/solace-helpers.ts index 7cb5f0b5db5..eae2e8280a3 100644 --- a/tests/scalers/solace-helpers.ts +++ b/tests/scalers/solace-helpers.ts @@ -149,7 +149,7 @@ spec: triggers: - type: solace-queue metadata: - brokerBaseUrl: http://kedalab-pubsubplus-dev.solace.svc.cluster.local:8080 + solaceSempBaseURL: http://kedalab-pubsubplus-dev.solace.svc.cluster.local:8080 msgVpn: keda_vpn queueName: SCALED_CONSUMER_QUEUE1 msgCountTarget: '20' From 3b8cc5200aef412979f974d09f23eb8a1c775040 Mon Sep 17 00:00:00 2001 From: Dennis Brinley Date: Tue, 13 Jul 2021 13:57:46 -0400 Subject: [PATCH 6/7] Changes for Solace Scaler - PR #1945 - from review scale-handler.go: - Changed scaler ID to "solace-event-queue" solace_scaler.go: - changed metadata identifer prefixes from "msg" to "message" where applicable" - added multiplier to messageSpoolUsageTarget (1024^2) so metadata values are expressed in MBytes - updated some var names (camel case not followed after re-name) solace_scaler_test.go - Mods to reflect change in scaler code solace-helpers.ts - Mod to test procedure to allow message size to be specified for test publisher (test message spool usage) - Mod to trigger/scaler name in scaledobject config solace.tests.ts - added tests to scale up/down based on message spool usage (#5 and #6) (a) The contribution was created in whole or in part by me and I have the right to submit it under the open source license indicated in the file; or (b) The contribution is based upon previous work that, to the best of my knowledge, is covered under an appropriate open source license and I have the right under that license to submit that work with modifications, whether created in whole or in part by me, under the same open source license (unless I am permitted to submit under a different license), as indicated in the file; or (c) The contribution was provided directly to me by some other person who certified (a), (b) or (c) and I have not modified it. (d) I understand and agree that this project and the contribution are public and that a record of the contribution (including all personal information I submit with it, including my sign-off) is maintained indefinitely and may be redistributed consistent with this project or the open source license(s) involved. Signed-off-by: Dennis Brinley --- CHANGELOG.md | 1 + pkg/scalers/solace_scaler.go | 26 +++--- pkg/scalers/solace_scaler_test.go | 128 +++++++++++++++--------------- pkg/scaling/scale_handler.go | 2 +- tests/scalers/solace-helpers.ts | 25 +++--- tests/scalers/solace.tests.ts | 72 ++++++++++++++--- 6 files changed, 157 insertions(+), 97 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b32b64e409a..5f4d991d00f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ - Extend Azure Monitor scaler to support custom metrics ([#1883](https://github.com/kedacore/keda/pull/1883)) - Support non-public cloud environments in the Azure Storage Queue and Azure Storage Blob scalers ([#1863](https://github.com/kedacore/keda/pull/1863)) - Show HashiCorp Vault Address when using `kubectl get ta` or `kubectl get cta` ([#1862](https://github.com/kedacore/keda/pull/1862)) +- Add Solace PubSub+ Event Broker Scaler ([#1945](https://github.com/kedacore/keda/pull/1945)) ### Improvements diff --git a/pkg/scalers/solace_scaler.go b/pkg/scalers/solace_scaler.go index 6026abcaca6..7d4c5dfa1a4 100644 --- a/pkg/scalers/solace_scaler.go +++ b/pkg/scalers/solace_scaler.go @@ -38,11 +38,11 @@ const ( solaceMetaUsernameEnv = "usernameEnv" solaceMetaPasswordEnv = "passwordEnv" // Target Object Identifiers - solaceMetamsgVpn = "msgVpn" - solaceMetaqueueName = "queueName" + solaceMetaMsgVpn = "messageVpn" + solaceMetaQueueName = "queueName" // Metric Targets - solaceMetamsgCountTarget = "msgCountTarget" - solaceMetamsgSpoolUsageTarget = "msgSpoolUsageTarget" + solaceMetaMsgCountTarget = "messageCountTarget" + solaceMetaMsgSpoolUsageTarget = "messageSpoolUsageTarget" // Trigger type identifiers solaceTriggermsgcount = "msgcount" solaceTriggermsgspoolusage = "msgspoolusage" @@ -135,33 +135,33 @@ func parseSolaceMetadata(config *ScalerConfig) (*SolaceMetadata, error) { return nil, fmt.Errorf(solaceFoundMetaFalse, solaceMetaSempBaseURL) } // GET Message VPN - if val, ok := config.TriggerMetadata[solaceMetamsgVpn]; ok && val != "" { + if val, ok := config.TriggerMetadata[solaceMetaMsgVpn]; ok && val != "" { meta.messageVpn = val } else { - return nil, fmt.Errorf(solaceFoundMetaFalse, solaceMetamsgVpn) + return nil, fmt.Errorf(solaceFoundMetaFalse, solaceMetaMsgVpn) } // GET Queue Name - if val, ok := config.TriggerMetadata[solaceMetaqueueName]; ok && val != "" { + if val, ok := config.TriggerMetadata[solaceMetaQueueName]; ok && val != "" { meta.queueName = val } else { - return nil, fmt.Errorf(solaceFoundMetaFalse, solaceMetaqueueName) + return nil, fmt.Errorf(solaceFoundMetaFalse, solaceMetaQueueName) } // GET METRIC TARGET VALUES // GET msgCountTarget - if val, ok := config.TriggerMetadata[solaceMetamsgCountTarget]; ok && val != "" { + if val, ok := config.TriggerMetadata[solaceMetaMsgCountTarget]; ok && val != "" { if msgCount, err := strconv.Atoi(val); err == nil { meta.msgCountTarget = msgCount } else { - return nil, fmt.Errorf("can't parse [%s], not a valid integer: %s", solaceMetamsgCountTarget, err) + return nil, fmt.Errorf("can't parse [%s], not a valid integer: %s", solaceMetaMsgCountTarget, err) } } // GET msgSpoolUsageTarget - if val, ok := config.TriggerMetadata[solaceMetamsgSpoolUsageTarget]; ok && val != "" { + if val, ok := config.TriggerMetadata[solaceMetaMsgSpoolUsageTarget]; ok && val != "" { if msgSpoolUsage, err := strconv.Atoi(val); err == nil { - meta.msgSpoolUsageTarget = msgSpoolUsage + meta.msgSpoolUsageTarget = msgSpoolUsage * 1024 * 1024 } else { - return nil, fmt.Errorf("can't parse [%s], not a valid integer: %s", solaceMetamsgSpoolUsageTarget, err) + return nil, fmt.Errorf("can't parse [%s], not a valid integer: %s", solaceMetaMsgSpoolUsageTarget, err) } } diff --git a/pkg/scalers/solace_scaler_test.go b/pkg/scalers/solace_scaler_test.go index d2e1ecff4be..0f00d174da2 100644 --- a/pkg/scalers/solace_scaler_test.go +++ b/pkg/scalers/solace_scaler_test.go @@ -51,13 +51,13 @@ var testParseSolaceMetadata = []testSolaceMetadata{ map[string]string{ "": "", solaceMetaSempBaseURL: soltestValidBaseURL, - solaceMetamsgVpn: soltestValidVpn, + solaceMetaMsgVpn: soltestValidVpn, solaceMetaUsernameEnv: "", solaceMetaPasswordEnv: "", solaceMetaUsername: soltestValidUsername, solaceMetaPassword: soltestValidPassword, - solaceMetaqueueName: soltestValidQueueName, - solaceMetamsgCountTarget: soltestValidMsgCountTarget, + solaceMetaQueueName: soltestValidQueueName, + solaceMetaMsgCountTarget: soltestValidMsgCountTarget, }, false, }, @@ -66,13 +66,13 @@ var testParseSolaceMetadata = []testSolaceMetadata{ "#007 - missing username (clear)", map[string]string{ solaceMetaSempBaseURL: soltestValidBaseURL, - solaceMetamsgVpn: soltestValidVpn, + solaceMetaMsgVpn: soltestValidVpn, solaceMetaUsernameEnv: "", solaceMetaPasswordEnv: "", solaceMetaUsername: "", solaceMetaPassword: soltestValidPassword, - solaceMetaqueueName: soltestValidQueueName, - solaceMetamsgCountTarget: soltestValidMsgCountTarget, + solaceMetaQueueName: soltestValidQueueName, + solaceMetaMsgCountTarget: soltestValidMsgCountTarget, }, true, }, @@ -81,13 +81,13 @@ var testParseSolaceMetadata = []testSolaceMetadata{ "#008 - missing password (clear)", map[string]string{ solaceMetaSempBaseURL: soltestValidBaseURL, - solaceMetamsgVpn: soltestValidVpn, + solaceMetaMsgVpn: soltestValidVpn, solaceMetaUsernameEnv: "", solaceMetaPasswordEnv: "", solaceMetaUsername: soltestValidUsername, solaceMetaPassword: "", - solaceMetaqueueName: soltestValidQueueName, - solaceMetamsgCountTarget: soltestValidMsgCountTarget, + solaceMetaQueueName: soltestValidQueueName, + solaceMetaMsgCountTarget: soltestValidMsgCountTarget, }, true, }, @@ -96,13 +96,13 @@ var testParseSolaceMetadata = []testSolaceMetadata{ "#009 - missing queueName", map[string]string{ solaceMetaSempBaseURL: soltestValidBaseURL, - solaceMetamsgVpn: soltestValidVpn, + solaceMetaMsgVpn: soltestValidVpn, solaceMetaUsernameEnv: "", solaceMetaPasswordEnv: "", solaceMetaUsername: soltestValidUsername, solaceMetaPassword: soltestValidPassword, - solaceMetaqueueName: "", - solaceMetamsgCountTarget: soltestValidMsgCountTarget, + solaceMetaQueueName: "", + solaceMetaMsgCountTarget: soltestValidMsgCountTarget, }, true, }, @@ -111,14 +111,14 @@ var testParseSolaceMetadata = []testSolaceMetadata{ "#010 - missing msgCountTarget", map[string]string{ solaceMetaSempBaseURL: soltestValidBaseURL, - solaceMetamsgVpn: soltestValidVpn, + solaceMetaMsgVpn: soltestValidVpn, solaceMetaUsernameEnv: "", solaceMetaPasswordEnv: "", solaceMetaUsername: soltestValidUsername, solaceMetaPassword: soltestValidPassword, - solaceMetaqueueName: soltestValidQueueName, - solaceMetamsgCountTarget: "", - solaceMetamsgSpoolUsageTarget: "", + solaceMetaQueueName: soltestValidQueueName, + solaceMetaMsgCountTarget: "", + solaceMetaMsgSpoolUsageTarget: "", }, true, }, @@ -127,13 +127,13 @@ var testParseSolaceMetadata = []testSolaceMetadata{ "#011 - msgSpoolUsageTarget non-numeric", map[string]string{ solaceMetaSempBaseURL: soltestValidBaseURL, - solaceMetamsgVpn: soltestValidVpn, + solaceMetaMsgVpn: soltestValidVpn, solaceMetaUsernameEnv: "", solaceMetaPasswordEnv: "", solaceMetaUsername: soltestValidUsername, solaceMetaPassword: soltestValidPassword, - solaceMetaqueueName: soltestValidQueueName, - solaceMetamsgCountTarget: "NOT_AN_INTEGER", + solaceMetaQueueName: soltestValidQueueName, + solaceMetaMsgCountTarget: "NOT_AN_INTEGER", }, true, }, @@ -142,13 +142,13 @@ var testParseSolaceMetadata = []testSolaceMetadata{ "#012 - msgSpoolUsage non-numeric", map[string]string{ solaceMetaSempBaseURL: soltestValidBaseURL, - solaceMetamsgVpn: soltestValidVpn, + solaceMetaMsgVpn: soltestValidVpn, solaceMetaUsernameEnv: "", solaceMetaPasswordEnv: "", solaceMetaUsername: soltestValidUsername, solaceMetaPassword: soltestValidPassword, - solaceMetaqueueName: soltestValidQueueName, - solaceMetamsgSpoolUsageTarget: "NOT_AN_INTEGER", + solaceMetaQueueName: soltestValidQueueName, + solaceMetaMsgSpoolUsageTarget: "NOT_AN_INTEGER", }, true, }, @@ -157,13 +157,13 @@ var testParseSolaceMetadata = []testSolaceMetadata{ "#013 - brokerBaseUrl", map[string]string{ solaceMetaSempBaseURL: soltestValidBaseURL, - solaceMetamsgVpn: soltestValidVpn, + solaceMetaMsgVpn: soltestValidVpn, solaceMetaUsernameEnv: "", solaceMetaPasswordEnv: "", solaceMetaUsername: soltestValidUsername, solaceMetaPassword: soltestValidPassword, - solaceMetaqueueName: soltestValidQueueName, - solaceMetamsgSpoolUsageTarget: soltestValidMsgSpoolTarget, + solaceMetaQueueName: soltestValidQueueName, + solaceMetaMsgSpoolUsageTarget: soltestValidMsgSpoolTarget, }, false, }, @@ -175,13 +175,13 @@ var testSolaceEnvCreds = []testSolaceMetadata{ "#101 - Connect with Credentials in env", map[string]string{ solaceMetaSempBaseURL: soltestValidBaseURL, - solaceMetamsgVpn: soltestValidVpn, + solaceMetaMsgVpn: soltestValidVpn, solaceMetaUsernameEnv: soltestEnvUsername, solaceMetaPasswordEnv: soltestEnvPassword, // solaceMetaUsername: "", // solaceMetaPassword: "", - solaceMetaqueueName: soltestValidQueueName, - solaceMetamsgCountTarget: soltestValidMsgCountTarget, + solaceMetaQueueName: soltestValidQueueName, + solaceMetaMsgCountTarget: soltestValidMsgCountTarget, }, false, }, @@ -190,13 +190,13 @@ var testSolaceEnvCreds = []testSolaceMetadata{ "#102 - Environment vars referenced but not found", map[string]string{ solaceMetaSempBaseURL: soltestValidBaseURL, - solaceMetamsgVpn: soltestValidVpn, + solaceMetaMsgVpn: soltestValidVpn, solaceMetaUsernameEnv: "SOLTEST_DNE", solaceMetaPasswordEnv: "SOLTEST_DNE", // solaceMetaUsername: "", // solaceMetaPassword: "", - solaceMetaqueueName: soltestValidQueueName, - solaceMetamsgCountTarget: soltestValidMsgCountTarget, + solaceMetaQueueName: soltestValidQueueName, + solaceMetaMsgCountTarget: soltestValidMsgCountTarget, }, true, }, @@ -210,13 +210,13 @@ var testSolaceK8sSecretCreds = []testSolaceMetadata{ "#201 - Connect with credentials from Auth Record (ENV VAR Present)", map[string]string{ solaceMetaSempBaseURL: soltestValidBaseURL, - solaceMetamsgVpn: soltestValidVpn, + solaceMetaMsgVpn: soltestValidVpn, solaceMetaUsernameEnv: soltestEnvUsername, solaceMetaPasswordEnv: soltestEnvPassword, // solaceMetaUsername: "", // solaceMetaPassword: "", - solaceMetaqueueName: soltestValidQueueName, - solaceMetamsgCountTarget: soltestValidMsgCountTarget, + solaceMetaQueueName: soltestValidQueueName, + solaceMetaMsgCountTarget: soltestValidMsgCountTarget, }, false, }, @@ -225,13 +225,13 @@ var testSolaceK8sSecretCreds = []testSolaceMetadata{ "#202 - Connect with credentials from Auth Record (ENV VAR and Clear Auth not present)", map[string]string{ solaceMetaSempBaseURL: soltestValidBaseURL, - solaceMetamsgVpn: soltestValidVpn, + solaceMetaMsgVpn: soltestValidVpn, // solaceMetaUsernameEnv: soltestEnvUsername, // solaceMetaPasswordEnv: soltestEnvPassword, // solaceMetaUsername: "", // solaceMetaPassword: "", - solaceMetaqueueName: soltestValidQueueName, - solaceMetamsgCountTarget: soltestValidMsgCountTarget, + solaceMetaQueueName: soltestValidQueueName, + solaceMetaMsgCountTarget: soltestValidMsgCountTarget, }, false, }, @@ -240,13 +240,13 @@ var testSolaceK8sSecretCreds = []testSolaceMetadata{ "#203 - Connect with credentials from Auth Record (ENV VAR Present, Clear Auth not present)", map[string]string{ solaceMetaSempBaseURL: soltestValidBaseURL, - solaceMetamsgVpn: soltestValidVpn, + solaceMetaMsgVpn: soltestValidVpn, solaceMetaUsernameEnv: "SOLTEST_DNE", solaceMetaPasswordEnv: "SOLTEST_DNE", // solaceMetaUsername: "", // solaceMetaPassword: "", - solaceMetaqueueName: soltestValidQueueName, - solaceMetamsgCountTarget: soltestValidMsgCountTarget, + solaceMetaQueueName: soltestValidQueueName, + solaceMetaMsgCountTarget: soltestValidMsgCountTarget, }, false, }, @@ -257,14 +257,14 @@ var testSolaceGetMetricSpecData = []testSolaceMetadata{ "#401 - Get Metric Spec - msgCountTarget", map[string]string{ solaceMetaSempBaseURL: soltestValidBaseURL, - solaceMetamsgVpn: soltestValidVpn, + solaceMetaMsgVpn: soltestValidVpn, solaceMetaUsernameEnv: "", solaceMetaPasswordEnv: "", solaceMetaUsername: soltestValidUsername, solaceMetaPassword: soltestValidPassword, - solaceMetaqueueName: soltestValidQueueName, - solaceMetamsgCountTarget: soltestValidMsgCountTarget, - // solaceMetamsgSpoolUsageTarget: soltestValidMsgSpoolTarget, + solaceMetaQueueName: soltestValidQueueName, + solaceMetaMsgCountTarget: soltestValidMsgCountTarget, + // solaceMetaMsgSpoolUsageTarget: soltestValidMsgSpoolTarget, }, false, }, @@ -272,14 +272,14 @@ var testSolaceGetMetricSpecData = []testSolaceMetadata{ "#402 - Get Metric Spec - msgSpoolUsageTarget", map[string]string{ solaceMetaSempBaseURL: soltestValidBaseURL, - solaceMetamsgVpn: soltestValidVpn, + solaceMetaMsgVpn: soltestValidVpn, solaceMetaUsernameEnv: "", solaceMetaPasswordEnv: "", solaceMetaUsername: soltestValidUsername, solaceMetaPassword: soltestValidPassword, - solaceMetaqueueName: soltestValidQueueName, - // solaceMetamsgCountTarget: soltestValidMsgCountTarget, - solaceMetamsgSpoolUsageTarget: soltestValidMsgSpoolTarget, + solaceMetaQueueName: soltestValidQueueName, + // solaceMetaMsgCountTarget: soltestValidMsgCountTarget, + solaceMetaMsgSpoolUsageTarget: soltestValidMsgSpoolTarget, }, false, }, @@ -287,14 +287,14 @@ var testSolaceGetMetricSpecData = []testSolaceMetadata{ "#403 - Get Metric Spec - BOTH msgSpoolUsage and msgCountTarget", map[string]string{ solaceMetaSempBaseURL: soltestValidBaseURL, - solaceMetamsgVpn: soltestValidVpn, + solaceMetaMsgVpn: soltestValidVpn, solaceMetaUsernameEnv: "", solaceMetaPasswordEnv: "", solaceMetaUsername: soltestValidUsername, solaceMetaPassword: soltestValidPassword, - solaceMetaqueueName: soltestValidQueueName, - solaceMetamsgCountTarget: soltestValidMsgCountTarget, - solaceMetamsgSpoolUsageTarget: soltestValidMsgSpoolTarget, + solaceMetaQueueName: soltestValidQueueName, + solaceMetaMsgCountTarget: soltestValidMsgCountTarget, + solaceMetaMsgSpoolUsageTarget: soltestValidMsgSpoolTarget, }, false, }, @@ -302,14 +302,14 @@ var testSolaceGetMetricSpecData = []testSolaceMetadata{ "#404 - Get Metric Spec - BOTH MISSING", map[string]string{ solaceMetaSempBaseURL: soltestValidBaseURL, - solaceMetamsgVpn: soltestValidVpn, + solaceMetaMsgVpn: soltestValidVpn, solaceMetaUsernameEnv: "", solaceMetaPasswordEnv: "", solaceMetaUsername: soltestValidUsername, solaceMetaPassword: soltestValidPassword, - solaceMetaqueueName: soltestValidQueueName, - // solaceMetamsgCountTarget: soltestValidMsgCountTarget, - // solaceMetamsgSpoolUsageTarget: soltestValidMsgSpoolTarget, + solaceMetaQueueName: soltestValidQueueName, + // solaceMetaMsgCountTarget: soltestValidMsgCountTarget, + // solaceMetaMsgSpoolUsageTarget: soltestValidMsgSpoolTarget, }, true, }, @@ -317,14 +317,14 @@ var testSolaceGetMetricSpecData = []testSolaceMetadata{ "#405 - Get Metric Spec - BOTH ZERO", map[string]string{ solaceMetaSempBaseURL: soltestValidBaseURL, - solaceMetamsgVpn: soltestValidVpn, + solaceMetaMsgVpn: soltestValidVpn, solaceMetaUsernameEnv: "", solaceMetaPasswordEnv: "", solaceMetaUsername: soltestValidUsername, solaceMetaPassword: soltestValidPassword, - solaceMetaqueueName: soltestValidQueueName, - solaceMetamsgCountTarget: "0", - solaceMetamsgSpoolUsageTarget: "0", + solaceMetaQueueName: soltestValidQueueName, + solaceMetaMsgCountTarget: "0", + solaceMetaMsgSpoolUsageTarget: "0", }, true, }, @@ -332,14 +332,14 @@ var testSolaceGetMetricSpecData = []testSolaceMetadata{ "#406 - Get Metric Spec - ONE ZERO; OTHER VALID", map[string]string{ solaceMetaSempBaseURL: soltestValidBaseURL, - solaceMetamsgVpn: soltestValidVpn, + solaceMetaMsgVpn: soltestValidVpn, solaceMetaUsernameEnv: "", solaceMetaPasswordEnv: "", solaceMetaUsername: soltestValidUsername, solaceMetaPassword: soltestValidPassword, - solaceMetaqueueName: soltestValidQueueName, - solaceMetamsgCountTarget: "0", - solaceMetamsgSpoolUsageTarget: soltestValidMsgSpoolTarget, + solaceMetaQueueName: soltestValidQueueName, + solaceMetaMsgCountTarget: "0", + solaceMetaMsgSpoolUsageTarget: soltestValidMsgSpoolTarget, }, false, }, diff --git a/pkg/scaling/scale_handler.go b/pkg/scaling/scale_handler.go index 26e30415a51..fb20612e0dc 100644 --- a/pkg/scaling/scale_handler.go +++ b/pkg/scaling/scale_handler.go @@ -446,7 +446,7 @@ func buildScaler(triggerType string, config *scalers.ScalerConfig) (scalers.Scal return scalers.NewRedisStreamsScaler(true, config) case "redis-streams": return scalers.NewRedisStreamsScaler(false, config) - case "solace-queue": + case "solace-event-queue": return scalers.NewSolaceScaler(config) case "stan": return scalers.NewStanScaler(config) diff --git a/tests/scalers/solace-helpers.ts b/tests/scalers/solace-helpers.ts index eae2e8280a3..c69ec6e3eac 100644 --- a/tests/scalers/solace-helpers.ts +++ b/tests/scalers/solace-helpers.ts @@ -82,15 +82,22 @@ export class SolaceHelper { fs.writeFileSync(tmpFile.name, solaceKedaScaledObjectYaml) sh.exec(`kubectl apply -f ${tmpFile.name}`).code, 'creating scaled object should work.' } - +/* static publishMessages(t, testNamespace: string, messageRate: string, messageNumber: string) { t.is( 0, - sh.exec(`kubectl exec -n ${testNamespace} kedalab-helper -- ./sdkperf/sdkperf_java.sh -cip=kedalab-pubsubplus-dev:55555 -cu consumer_user@keda_vpn -cp=consumer_pwd -mr ${messageRate} -mn ${messageNumber} -mt=persistent -pql=SCALED_CONSUMER_QUEUE1`).code, 'creating solace producer deployment should work.' + sh.exec(`kubectl exec -n ${testNamespace} kedalab-helper -- ./sdkperf/sdkperf_java.sh -cip=kedalab-pubsubplus-dev:55555 -cu consumer_user@keda_vpn -cp=consumer_pwd -mr ${messageRate} -mn ${messageNumber} -mt=persistent -pql=SCALED_CONSUMER_QUEUE1`).code, 'publishing messages should work' ) } +*/ + static publishMessages(t, testNamespace: string, messageRate: string, messageNumber: string, messageSize: string) { + t.is( + 0, + sh.exec(`kubectl exec -n ${testNamespace} kedalab-helper -- ./sdkperf/sdkperf_java.sh -cip=kedalab-pubsubplus-dev:55555 -cu consumer_user@keda_vpn -cp=consumer_pwd -mr ${messageRate} -mn ${messageNumber} -msx ${messageSize} -mt=persistent -pql=SCALED_CONSUMER_QUEUE1`).code, 'publishing large messages should work' + ) + } - static uninstallSolaceKedaObjects(t){ + static uninstallSolaceKedaObjects(t){ const tmpFile = tmp.fileSync() fs.writeFileSync(tmpFile.name, solaceKedaScaledObjectYaml) sh.exec(`kubectl delete -f ${tmpFile.name}`) @@ -147,13 +154,13 @@ spec: periodSeconds: 10 selectPolicy: Max triggers: - - type: solace-queue + - type: solace-event-queue metadata: - solaceSempBaseURL: http://kedalab-pubsubplus-dev.solace.svc.cluster.local:8080 - msgVpn: keda_vpn - queueName: SCALED_CONSUMER_QUEUE1 - msgCountTarget: '20' - msgSpoolUsageTarget: '100000' + solaceSempBaseURL: http://kedalab-pubsubplus-dev.solace.svc.cluster.local:8080 + messageVpn: keda_vpn + queueName: SCALED_CONSUMER_QUEUE1 + messageCountTarget: '20' + messageSpoolUsageTarget: '1' authenticationRef: name: kedalab-trigger-auth ` diff --git a/tests/scalers/solace.tests.ts b/tests/scalers/solace.tests.ts index 22d312a5804..4c7cd28d62c 100644 --- a/tests/scalers/solace.tests.ts +++ b/tests/scalers/solace.tests.ts @@ -28,6 +28,7 @@ test.serial('#2 Create Scaled Object; Consumer Deployment replicas scale to zero SolaceHelper.installSolaceKedaScaledObject(t) let replicas = '1' + let success = false for (let i = 0; i <= 20 && replicas !== '10'; i++) { replicas = sh.exec(`kubectl get deployment.apps/solace-consumer --namespace ${testNamespace} -o jsonpath="{.spec.replicas}"`).stdout t.log('pod replicas (of 0 expected): ' + replicas) @@ -35,38 +36,85 @@ test.serial('#2 Create Scaled Object; Consumer Deployment replicas scale to zero sh.exec('sleep 3s') } else { t.log('scale to zero goal met') -// t.log('scale to zero goal met; delay to allow pod time to terminate') -// sh.exec('sleep 10s') + success = true break } } - t.is('0', replicas, 'Replica count should be 0 after 60 seconds') + t.is('0', replicas, 'replica count should be 0 after 60 seconds') + if (success) { + sh.exec('sleep 5s') + } }) -test.serial('#3 Publish 400 messages to Consumer Queue; Scale Replicas to 10', t => { - // publish messages to queue -- 500 msgs at 50 msgs/sec - SolaceHelper.publishMessages(t, testNamespace, '50', '400') +test.serial('#3 Publish 400 messages to Consumer Queue; Scale Replicas to 10 for message count', t => { + // publish messages to queue -- 400 msgs at 50 msgs/sec + SolaceHelper.publishMessages(t, testNamespace, '50', '400', '256') // with messages published, the consumer deployment should start receiving the messages let replicas = '0' - for (let i = 0; i < 15 && replicas !== '10'; i++) { + for (let i = 0; i < 30 && replicas !== '10'; i++) { replicas = sh.exec(`kubectl get deployment.apps/solace-consumer --namespace ${testNamespace} -o jsonpath="{.spec.replicas}"`).stdout t.log('pod replicas (of 10 expected): ' + replicas) if (replicas !== '10') { - sh.exec('sleep 4s') + sh.exec('sleep 2s') } else { - t.log('max pod replica count goal met') + t.log('max pod replica count goal met - msg count') break } } - t.is('10', replicas, 'Replica count should be 10 after 60 seconds') + t.is('10', replicas, 'replica count should be 10 after 60 seconds - msg count') }) test.serial('#4 Consumer Deployment scales to zero replicas after all messages read', t => { let replicas = '10' + let success = false + + // Replicas should decrease as messages are consumed + for (let i = 0; i < 60 && replicas !== '0'; i++) { + replicas = sh.exec(`kubectl get deployment.apps/solace-consumer --namespace ${testNamespace} -o jsonpath="{.spec.replicas}"`).stdout + t.log('pod replicas (of 0 expected): ' + replicas) + if (replicas !== '0') { + sh.exec('sleep 5s') + } else { + t.log('min pod replica count goal met (scale to zero)') + success = true + break + } + } + + t.is('0', replicas, 'replica count should be 0 after 5 minutes') + if (success) { + sh.exec('sleep 5s') + } +}) + +test.serial('#5 Publish 50 LARGE messages to Consumer Queue; Scale Replicas to 10 for spool usage', t => { + // publish messages to queue -- 400 msgs at 50 msgs/sec + SolaceHelper.publishMessages(t, testNamespace, '10', '50', '4194304') + + // with messages published, the consumer deployment should start receiving the messages + let replicas = '0' + for (let i = 0; i < 30 && replicas !== '10'; i++) { + replicas = sh.exec(`kubectl get deployment.apps/solace-consumer --namespace ${testNamespace} -o jsonpath="{.spec.replicas}"`).stdout + t.log('pod replicas (of 10 expected): ' + replicas) + if (replicas !== '10') { + sh.exec('sleep 2s') + } else { + t.log('max pod replica count goal met - spool size') + break + } + } + + t.is('10', replicas, 'replica count should be 10 after 60 seconds - spool size') +}) + +test.serial('#6 Consumer Deployment scales to zero replicas after all messages read', t => { + + let replicas = '10' + let success = false // Replicas should decrease as messages are consumed for (let i = 0; i < 60 && replicas !== '0'; i++) { @@ -76,11 +124,15 @@ test.serial('#4 Consumer Deployment scales to zero replicas after all messages r sh.exec('sleep 5s') } else { t.log('min pod replica count goal met (scale to zero)') + success = true break } } t.is('0', replicas, 'Replica count should be 0 after 5 minutes') + if (success) { + sh.exec('sleep 5s') + } }) test.after.always.cb('clean up the cluster', t => { From 1b03918e0a2f463d3ae67c3d1de41e5dc7651bae Mon Sep 17 00:00:00 2001 From: Dennis Brinley Date: Wed, 14 Jul 2021 09:42:16 -0400 Subject: [PATCH 7/7] Commit Solace Scaler for #1945 Updated var names for config metadata passed from env Signed-off-by: Dennis Brinley (a) The contribution was created in whole or in part by me and I have the right to submit it under the open source license indicated in the file; or (b) The contribution is based upon previous work that, to the best of my knowledge, is covered under an appropriate open source license and I have the right under that license to submit that work with modifications, whether created in whole or in part by me, under the same open source license (unless I am permitted to submit under a different license), as indicated in the file; or (c) The contribution was provided directly to me by some other person who certified (a), (b) or (c) and I have not modified it. (d) I understand and agree that this project and the contribution are public and that a record of the contribution (including all personal information I submit with it, including my sign-off) is maintained indefinitely and may be redistributed consistent with this project or the open source license(s) involved. --- pkg/scalers/solace_scaler.go | 20 ++-- pkg/scalers/solace_scaler_test.go | 186 +++++++++++++++--------------- 2 files changed, 103 insertions(+), 103 deletions(-) diff --git a/pkg/scalers/solace_scaler.go b/pkg/scalers/solace_scaler.go index 7d4c5dfa1a4..34b77c69b9a 100644 --- a/pkg/scalers/solace_scaler.go +++ b/pkg/scalers/solace_scaler.go @@ -33,10 +33,10 @@ const ( // Broker Identifiers solaceMetaSempBaseURL = "solaceSempBaseURL" // Credential Identifiers - solaceMetaUsername = "username" - solaceMetaPassword = "password" - solaceMetaUsernameEnv = "usernameEnv" - solaceMetaPasswordEnv = "passwordEnv" + solaceMetaUsername = "username" + solaceMetaPassword = "password" + solaceMetaUsernameFromEnv = "usernameFromEnv" + solaceMetaPasswordFromEnv = "passwordFromEnv" // Target Object Identifiers solaceMetaMsgVpn = "messageVpn" solaceMetaQueueName = "queueName" @@ -193,16 +193,16 @@ func getSolaceSempCredentials(config *ScalerConfig) (u string, p string, err err // The username must be a valid broker ADMIN user identifier with read access to SEMP for the broker, VPN, and relevant objects // The scaler will attempt to acquire username and then password independently. For each: // - Search K8S Secret (Encoded) - // - Search environment variable specified by config at 'usernameEnv' / 'passwordEnv' + // - Search environment variable specified by config at 'usernameFromEnv' / 'passwordFromEnv' // - Search 'username' / 'password' fields (Clear Text) // Get username if usernameSecret, ok := config.AuthParams[solaceMetaUsername]; ok && usernameSecret != "" { u = usernameSecret - } else if usernameEnv, ok := config.TriggerMetadata[solaceMetaUsernameEnv]; ok && usernameEnv != "" { - if resolvedUser, ok := config.ResolvedEnv[config.TriggerMetadata[solaceMetaUsernameEnv]]; ok && resolvedUser != "" { + } else if usernameFromEnv, ok := config.TriggerMetadata[solaceMetaUsernameFromEnv]; ok && usernameFromEnv != "" { + if resolvedUser, ok := config.ResolvedEnv[config.TriggerMetadata[solaceMetaUsernameFromEnv]]; ok && resolvedUser != "" { u = resolvedUser } else { - return "", "", fmt.Errorf("username could not be resolved from the environment variable: %s", usernameEnv) + return "", "", fmt.Errorf("username could not be resolved from the environment variable: %s", usernameFromEnv) } } else if usernameClear, ok := config.TriggerMetadata[solaceMetaUsername]; ok && usernameClear != "" { u = usernameClear @@ -212,8 +212,8 @@ func getSolaceSempCredentials(config *ScalerConfig) (u string, p string, err err // Get Password if passwordSecret, ok := config.AuthParams[solaceMetaPassword]; ok && passwordSecret != "" { p = passwordSecret - } else if passwordEnv, ok := config.TriggerMetadata[solaceMetaPasswordEnv]; ok && passwordEnv != "" { - if resolvedPassword, ok := config.ResolvedEnv[config.TriggerMetadata[solaceMetaPasswordEnv]]; ok && resolvedPassword != "" { + } else if passwordEnv, ok := config.TriggerMetadata[solaceMetaPasswordFromEnv]; ok && passwordEnv != "" { + if resolvedPassword, ok := config.ResolvedEnv[config.TriggerMetadata[solaceMetaPasswordFromEnv]]; ok && resolvedPassword != "" { p = resolvedPassword } else { return "", "", fmt.Errorf("password could not be resolved from the environment variable: %s", passwordEnv) diff --git a/pkg/scalers/solace_scaler_test.go b/pkg/scalers/solace_scaler_test.go index 0f00d174da2..613f917f8f5 100644 --- a/pkg/scalers/solace_scaler_test.go +++ b/pkg/scalers/solace_scaler_test.go @@ -49,15 +49,15 @@ var testParseSolaceMetadata = []testSolaceMetadata{ { "#002 - brokerBaseUrl", map[string]string{ - "": "", - solaceMetaSempBaseURL: soltestValidBaseURL, - solaceMetaMsgVpn: soltestValidVpn, - solaceMetaUsernameEnv: "", - solaceMetaPasswordEnv: "", - solaceMetaUsername: soltestValidUsername, - solaceMetaPassword: soltestValidPassword, - solaceMetaQueueName: soltestValidQueueName, - solaceMetaMsgCountTarget: soltestValidMsgCountTarget, + "": "", + solaceMetaSempBaseURL: soltestValidBaseURL, + solaceMetaMsgVpn: soltestValidVpn, + solaceMetaUsernameFromEnv: "", + solaceMetaPasswordFromEnv: "", + solaceMetaUsername: soltestValidUsername, + solaceMetaPassword: soltestValidPassword, + solaceMetaQueueName: soltestValidQueueName, + solaceMetaMsgCountTarget: soltestValidMsgCountTarget, }, false, }, @@ -65,14 +65,14 @@ var testParseSolaceMetadata = []testSolaceMetadata{ { "#007 - missing username (clear)", map[string]string{ - solaceMetaSempBaseURL: soltestValidBaseURL, - solaceMetaMsgVpn: soltestValidVpn, - solaceMetaUsernameEnv: "", - solaceMetaPasswordEnv: "", - solaceMetaUsername: "", - solaceMetaPassword: soltestValidPassword, - solaceMetaQueueName: soltestValidQueueName, - solaceMetaMsgCountTarget: soltestValidMsgCountTarget, + solaceMetaSempBaseURL: soltestValidBaseURL, + solaceMetaMsgVpn: soltestValidVpn, + solaceMetaUsernameFromEnv: "", + solaceMetaPasswordFromEnv: "", + solaceMetaUsername: "", + solaceMetaPassword: soltestValidPassword, + solaceMetaQueueName: soltestValidQueueName, + solaceMetaMsgCountTarget: soltestValidMsgCountTarget, }, true, }, @@ -80,14 +80,14 @@ var testParseSolaceMetadata = []testSolaceMetadata{ { "#008 - missing password (clear)", map[string]string{ - solaceMetaSempBaseURL: soltestValidBaseURL, - solaceMetaMsgVpn: soltestValidVpn, - solaceMetaUsernameEnv: "", - solaceMetaPasswordEnv: "", - solaceMetaUsername: soltestValidUsername, - solaceMetaPassword: "", - solaceMetaQueueName: soltestValidQueueName, - solaceMetaMsgCountTarget: soltestValidMsgCountTarget, + solaceMetaSempBaseURL: soltestValidBaseURL, + solaceMetaMsgVpn: soltestValidVpn, + solaceMetaUsernameFromEnv: "", + solaceMetaPasswordFromEnv: "", + solaceMetaUsername: soltestValidUsername, + solaceMetaPassword: "", + solaceMetaQueueName: soltestValidQueueName, + solaceMetaMsgCountTarget: soltestValidMsgCountTarget, }, true, }, @@ -95,14 +95,14 @@ var testParseSolaceMetadata = []testSolaceMetadata{ { "#009 - missing queueName", map[string]string{ - solaceMetaSempBaseURL: soltestValidBaseURL, - solaceMetaMsgVpn: soltestValidVpn, - solaceMetaUsernameEnv: "", - solaceMetaPasswordEnv: "", - solaceMetaUsername: soltestValidUsername, - solaceMetaPassword: soltestValidPassword, - solaceMetaQueueName: "", - solaceMetaMsgCountTarget: soltestValidMsgCountTarget, + solaceMetaSempBaseURL: soltestValidBaseURL, + solaceMetaMsgVpn: soltestValidVpn, + solaceMetaUsernameFromEnv: "", + solaceMetaPasswordFromEnv: "", + solaceMetaUsername: soltestValidUsername, + solaceMetaPassword: soltestValidPassword, + solaceMetaQueueName: "", + solaceMetaMsgCountTarget: soltestValidMsgCountTarget, }, true, }, @@ -112,8 +112,8 @@ var testParseSolaceMetadata = []testSolaceMetadata{ map[string]string{ solaceMetaSempBaseURL: soltestValidBaseURL, solaceMetaMsgVpn: soltestValidVpn, - solaceMetaUsernameEnv: "", - solaceMetaPasswordEnv: "", + solaceMetaUsernameFromEnv: "", + solaceMetaPasswordFromEnv: "", solaceMetaUsername: soltestValidUsername, solaceMetaPassword: soltestValidPassword, solaceMetaQueueName: soltestValidQueueName, @@ -126,14 +126,14 @@ var testParseSolaceMetadata = []testSolaceMetadata{ { "#011 - msgSpoolUsageTarget non-numeric", map[string]string{ - solaceMetaSempBaseURL: soltestValidBaseURL, - solaceMetaMsgVpn: soltestValidVpn, - solaceMetaUsernameEnv: "", - solaceMetaPasswordEnv: "", - solaceMetaUsername: soltestValidUsername, - solaceMetaPassword: soltestValidPassword, - solaceMetaQueueName: soltestValidQueueName, - solaceMetaMsgCountTarget: "NOT_AN_INTEGER", + solaceMetaSempBaseURL: soltestValidBaseURL, + solaceMetaMsgVpn: soltestValidVpn, + solaceMetaUsernameFromEnv: "", + solaceMetaPasswordFromEnv: "", + solaceMetaUsername: soltestValidUsername, + solaceMetaPassword: soltestValidPassword, + solaceMetaQueueName: soltestValidQueueName, + solaceMetaMsgCountTarget: "NOT_AN_INTEGER", }, true, }, @@ -143,8 +143,8 @@ var testParseSolaceMetadata = []testSolaceMetadata{ map[string]string{ solaceMetaSempBaseURL: soltestValidBaseURL, solaceMetaMsgVpn: soltestValidVpn, - solaceMetaUsernameEnv: "", - solaceMetaPasswordEnv: "", + solaceMetaUsernameFromEnv: "", + solaceMetaPasswordFromEnv: "", solaceMetaUsername: soltestValidUsername, solaceMetaPassword: soltestValidPassword, solaceMetaQueueName: soltestValidQueueName, @@ -158,8 +158,8 @@ var testParseSolaceMetadata = []testSolaceMetadata{ map[string]string{ solaceMetaSempBaseURL: soltestValidBaseURL, solaceMetaMsgVpn: soltestValidVpn, - solaceMetaUsernameEnv: "", - solaceMetaPasswordEnv: "", + solaceMetaUsernameFromEnv: "", + solaceMetaPasswordFromEnv: "", solaceMetaUsername: soltestValidUsername, solaceMetaPassword: soltestValidPassword, solaceMetaQueueName: soltestValidQueueName, @@ -174,10 +174,10 @@ var testSolaceEnvCreds = []testSolaceMetadata{ { "#101 - Connect with Credentials in env", map[string]string{ - solaceMetaSempBaseURL: soltestValidBaseURL, - solaceMetaMsgVpn: soltestValidVpn, - solaceMetaUsernameEnv: soltestEnvUsername, - solaceMetaPasswordEnv: soltestEnvPassword, + solaceMetaSempBaseURL: soltestValidBaseURL, + solaceMetaMsgVpn: soltestValidVpn, + solaceMetaUsernameFromEnv: soltestEnvUsername, + solaceMetaPasswordFromEnv: soltestEnvPassword, // solaceMetaUsername: "", // solaceMetaPassword: "", solaceMetaQueueName: soltestValidQueueName, @@ -189,10 +189,10 @@ var testSolaceEnvCreds = []testSolaceMetadata{ { "#102 - Environment vars referenced but not found", map[string]string{ - solaceMetaSempBaseURL: soltestValidBaseURL, - solaceMetaMsgVpn: soltestValidVpn, - solaceMetaUsernameEnv: "SOLTEST_DNE", - solaceMetaPasswordEnv: "SOLTEST_DNE", + solaceMetaSempBaseURL: soltestValidBaseURL, + solaceMetaMsgVpn: soltestValidVpn, + solaceMetaUsernameFromEnv: "SOLTEST_DNE", + solaceMetaPasswordFromEnv: "SOLTEST_DNE", // solaceMetaUsername: "", // solaceMetaPassword: "", solaceMetaQueueName: soltestValidQueueName, @@ -209,10 +209,10 @@ var testSolaceK8sSecretCreds = []testSolaceMetadata{ { "#201 - Connect with credentials from Auth Record (ENV VAR Present)", map[string]string{ - solaceMetaSempBaseURL: soltestValidBaseURL, - solaceMetaMsgVpn: soltestValidVpn, - solaceMetaUsernameEnv: soltestEnvUsername, - solaceMetaPasswordEnv: soltestEnvPassword, + solaceMetaSempBaseURL: soltestValidBaseURL, + solaceMetaMsgVpn: soltestValidVpn, + solaceMetaUsernameFromEnv: soltestEnvUsername, + solaceMetaPasswordFromEnv: soltestEnvPassword, // solaceMetaUsername: "", // solaceMetaPassword: "", solaceMetaQueueName: soltestValidQueueName, @@ -226,8 +226,8 @@ var testSolaceK8sSecretCreds = []testSolaceMetadata{ map[string]string{ solaceMetaSempBaseURL: soltestValidBaseURL, solaceMetaMsgVpn: soltestValidVpn, - // solaceMetaUsernameEnv: soltestEnvUsername, - // solaceMetaPasswordEnv: soltestEnvPassword, + // solaceMetaUsernameFromEnv: soltestEnvUsername, + // solaceMetaPasswordFromEnv: soltestEnvPassword, // solaceMetaUsername: "", // solaceMetaPassword: "", solaceMetaQueueName: soltestValidQueueName, @@ -239,10 +239,10 @@ var testSolaceK8sSecretCreds = []testSolaceMetadata{ { "#203 - Connect with credentials from Auth Record (ENV VAR Present, Clear Auth not present)", map[string]string{ - solaceMetaSempBaseURL: soltestValidBaseURL, - solaceMetaMsgVpn: soltestValidVpn, - solaceMetaUsernameEnv: "SOLTEST_DNE", - solaceMetaPasswordEnv: "SOLTEST_DNE", + solaceMetaSempBaseURL: soltestValidBaseURL, + solaceMetaMsgVpn: soltestValidVpn, + solaceMetaUsernameFromEnv: "SOLTEST_DNE", + solaceMetaPasswordFromEnv: "SOLTEST_DNE", // solaceMetaUsername: "", // solaceMetaPassword: "", solaceMetaQueueName: soltestValidQueueName, @@ -256,14 +256,14 @@ var testSolaceGetMetricSpecData = []testSolaceMetadata{ { "#401 - Get Metric Spec - msgCountTarget", map[string]string{ - solaceMetaSempBaseURL: soltestValidBaseURL, - solaceMetaMsgVpn: soltestValidVpn, - solaceMetaUsernameEnv: "", - solaceMetaPasswordEnv: "", - solaceMetaUsername: soltestValidUsername, - solaceMetaPassword: soltestValidPassword, - solaceMetaQueueName: soltestValidQueueName, - solaceMetaMsgCountTarget: soltestValidMsgCountTarget, + solaceMetaSempBaseURL: soltestValidBaseURL, + solaceMetaMsgVpn: soltestValidVpn, + solaceMetaUsernameFromEnv: "", + solaceMetaPasswordFromEnv: "", + solaceMetaUsername: soltestValidUsername, + solaceMetaPassword: soltestValidPassword, + solaceMetaQueueName: soltestValidQueueName, + solaceMetaMsgCountTarget: soltestValidMsgCountTarget, // solaceMetaMsgSpoolUsageTarget: soltestValidMsgSpoolTarget, }, false, @@ -271,13 +271,13 @@ var testSolaceGetMetricSpecData = []testSolaceMetadata{ { "#402 - Get Metric Spec - msgSpoolUsageTarget", map[string]string{ - solaceMetaSempBaseURL: soltestValidBaseURL, - solaceMetaMsgVpn: soltestValidVpn, - solaceMetaUsernameEnv: "", - solaceMetaPasswordEnv: "", - solaceMetaUsername: soltestValidUsername, - solaceMetaPassword: soltestValidPassword, - solaceMetaQueueName: soltestValidQueueName, + solaceMetaSempBaseURL: soltestValidBaseURL, + solaceMetaMsgVpn: soltestValidVpn, + solaceMetaUsernameFromEnv: "", + solaceMetaPasswordFromEnv: "", + solaceMetaUsername: soltestValidUsername, + solaceMetaPassword: soltestValidPassword, + solaceMetaQueueName: soltestValidQueueName, // solaceMetaMsgCountTarget: soltestValidMsgCountTarget, solaceMetaMsgSpoolUsageTarget: soltestValidMsgSpoolTarget, }, @@ -288,8 +288,8 @@ var testSolaceGetMetricSpecData = []testSolaceMetadata{ map[string]string{ solaceMetaSempBaseURL: soltestValidBaseURL, solaceMetaMsgVpn: soltestValidVpn, - solaceMetaUsernameEnv: "", - solaceMetaPasswordEnv: "", + solaceMetaUsernameFromEnv: "", + solaceMetaPasswordFromEnv: "", solaceMetaUsername: soltestValidUsername, solaceMetaPassword: soltestValidPassword, solaceMetaQueueName: soltestValidQueueName, @@ -301,13 +301,13 @@ var testSolaceGetMetricSpecData = []testSolaceMetadata{ { "#404 - Get Metric Spec - BOTH MISSING", map[string]string{ - solaceMetaSempBaseURL: soltestValidBaseURL, - solaceMetaMsgVpn: soltestValidVpn, - solaceMetaUsernameEnv: "", - solaceMetaPasswordEnv: "", - solaceMetaUsername: soltestValidUsername, - solaceMetaPassword: soltestValidPassword, - solaceMetaQueueName: soltestValidQueueName, + solaceMetaSempBaseURL: soltestValidBaseURL, + solaceMetaMsgVpn: soltestValidVpn, + solaceMetaUsernameFromEnv: "", + solaceMetaPasswordFromEnv: "", + solaceMetaUsername: soltestValidUsername, + solaceMetaPassword: soltestValidPassword, + solaceMetaQueueName: soltestValidQueueName, // solaceMetaMsgCountTarget: soltestValidMsgCountTarget, // solaceMetaMsgSpoolUsageTarget: soltestValidMsgSpoolTarget, }, @@ -318,8 +318,8 @@ var testSolaceGetMetricSpecData = []testSolaceMetadata{ map[string]string{ solaceMetaSempBaseURL: soltestValidBaseURL, solaceMetaMsgVpn: soltestValidVpn, - solaceMetaUsernameEnv: "", - solaceMetaPasswordEnv: "", + solaceMetaUsernameFromEnv: "", + solaceMetaPasswordFromEnv: "", solaceMetaUsername: soltestValidUsername, solaceMetaPassword: soltestValidPassword, solaceMetaQueueName: soltestValidQueueName, @@ -333,8 +333,8 @@ var testSolaceGetMetricSpecData = []testSolaceMetadata{ map[string]string{ solaceMetaSempBaseURL: soltestValidBaseURL, solaceMetaMsgVpn: soltestValidVpn, - solaceMetaUsernameEnv: "", - solaceMetaPasswordEnv: "", + solaceMetaUsernameFromEnv: "", + solaceMetaPasswordFromEnv: "", solaceMetaUsername: soltestValidUsername, solaceMetaPassword: soltestValidPassword, solaceMetaQueueName: soltestValidQueueName,