Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Introduce activationThreshold/minMetricValue for Solace Scaler #3421

Merged
merged 4 commits into from
Jul 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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