Skip to content

Commit

Permalink
feat: Introduce activationThreshold/minMetricValue for Solace Scaler (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Jorge Turrado Ferrero authored Jul 26, 2022
1 parent 0b607be commit 17b78dd
Show file tree
Hide file tree
Showing 5 changed files with 304 additions and 389 deletions.
28 changes: 27 additions & 1 deletion pkg/scalers/solace_scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ const (
// Metric Targets
solaceMetaMsgCountTarget = "messageCountTarget"
solaceMetaMsgSpoolUsageTarget = "messageSpoolUsageTarget"
// Metric Activation Targets
solaceMetaActivationMsgCountTarget = "activationMessageCountTarget"
solaceMetaActivationMsgSpoolUsageTarget = "activationMessageSpoolUsageTarget"
// Trigger type identifiers
solaceTriggermsgcount = "msgcount"
solaceTriggermsgspoolusage = "msgspoolusage"
Expand Down Expand Up @@ -74,6 +77,9 @@ type SolaceMetadata struct {
// Target Message Count
msgCountTarget int64
msgSpoolUsageTarget int64 // Spool Use Target in Megabytes
// Activation Target Message Count
activationMsgCountTarget int
activationMsgSpoolUsageTarget int // Spool Use Target in Megabytes
// Scaler index
scalerIndex int
}
Expand Down Expand Up @@ -177,6 +183,26 @@ func parseSolaceMetadata(config *ScalerConfig) (*SolaceMetadata, error) {
return nil, fmt.Errorf("no target value found in the scaler configuration")
}

// GET ACTIVATION METRIC TARGET VALUES
// GET activationMsgCountTarget
meta.activationMsgCountTarget = 0
if val, ok := config.TriggerMetadata[solaceMetaActivationMsgCountTarget]; ok && val != "" {
if activationMsgCountTarget, err := strconv.Atoi(val); err == nil {
meta.activationMsgCountTarget = activationMsgCountTarget
} else {
return nil, fmt.Errorf("can't parse [%s], not a valid integer: %s", solaceMetaActivationMsgCountTarget, err)
}
}
// GET activationMsgSpoolUsageTarget
meta.activationMsgSpoolUsageTarget = 0
if val, ok := config.TriggerMetadata[solaceMetaActivationMsgSpoolUsageTarget]; ok && val != "" {
if activationMsgSpoolUsageTarget, err := strconv.Atoi(val); err == nil {
meta.activationMsgSpoolUsageTarget = activationMsgSpoolUsageTarget * 1024 * 1024
} else {
return nil, fmt.Errorf("can't parse [%s], not a valid integer: %s", solaceMetaActivationMsgSpoolUsageTarget, err)
}
}

// Format Solace SEMP Queue Endpoint (REST URL)
meta.endpointURL = fmt.Sprintf(
solaceSempEndpointURLTemplate,
Expand Down Expand Up @@ -354,7 +380,7 @@ func (s *SolaceScaler) IsActive(ctx context.Context) (bool, error) {
solaceLog.Error(err, "call to semp endpoint failed")
return false, err
}
return (metricValues.msgCount > 0 || metricValues.msgSpoolUsage > 0), nil
return (metricValues.msgCount > s.metadata.activationMsgCountTarget || metricValues.msgSpoolUsage > s.metadata.activationMsgSpoolUsageTarget), nil
}

// Do Nothing - Satisfies Interface
Expand Down
34 changes: 34 additions & 0 deletions pkg/scalers/solace_scaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,40 @@ var testParseSolaceMetadata = []testSolaceMetadata{
1,
true,
},
// -Case - activationMsgSpoolUsageTarget non-numeric
{
"#011 - msgSpoolUsageTarget non-numeric",
map[string]string{
solaceMetaSempBaseURL: soltestValidBaseURL,
solaceMetaMsgVpn: soltestValidVpn,
solaceMetaUsernameFromEnv: "",
solaceMetaPasswordFromEnv: "",
solaceMetaUsername: soltestValidUsername,
solaceMetaPassword: soltestValidPassword,
solaceMetaQueueName: soltestValidQueueName,
solaceMetaMsgCountTarget: "1",
solaceMetaActivationMsgCountTarget: "NOT_AN_INTEGER",
},
1,
true,
},
// -Case - activationMsgSpoolUsage non-numeric
{
"#012 - msgSpoolUsage non-numeric",
map[string]string{
solaceMetaSempBaseURL: soltestValidBaseURL,
solaceMetaMsgVpn: soltestValidVpn,
solaceMetaUsernameFromEnv: "",
solaceMetaPasswordFromEnv: "",
solaceMetaUsername: soltestValidUsername,
solaceMetaPassword: soltestValidPassword,
solaceMetaQueueName: soltestValidQueueName,
solaceMetaMsgSpoolUsageTarget: "1",
solaceMetaActivationMsgSpoolUsageTarget: "NOT_AN_INTEGER",
},
1,
true,
},
// +Case - Pass with msgSpoolUsageTarget and not msgCountTarget
{
"#013 - brokerBaseUrl",
Expand Down
245 changes: 0 additions & 245 deletions tests/scalers/solace-helpers.ts

This file was deleted.

Loading

0 comments on commit 17b78dd

Please sign in to comment.