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 Artemis Scaler #3346

Merged
merged 3 commits into from
Jul 11, 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
42 changes: 27 additions & 15 deletions pkg/scalers/artemis_scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,17 @@ type artemisScaler struct {

//revive:disable:var-naming breaking change on restApiTemplate, wouldn't bring any benefit to users
type artemisMetadata struct {
managementEndpoint string
queueName string
brokerName string
brokerAddress string
username string
password string
restAPITemplate string
queueLength int64
corsHeader string
scalerIndex int
managementEndpoint string
queueName string
brokerName string
brokerAddress string
username string
password string
restAPITemplate string
queueLength int64
activationQueueLength int64
corsHeader string
scalerIndex int
}

//revive:enable:var-naming
Expand All @@ -47,10 +48,11 @@ type artemisMonitoring struct {
}

const (
artemisMetricType = "External"
defaultArtemisQueueLength = 10
defaultRestAPITemplate = "http://<<managementEndpoint>>/console/jolokia/read/org.apache.activemq.artemis:broker=\"<<brokerName>>\",component=addresses,address=\"<<brokerAddress>>\",subcomponent=queues,routing-type=\"anycast\",queue=\"<<queueName>>\"/MessageCount"
defaultCorsHeader = "http://%s"
artemisMetricType = "External"
defaultArtemisQueueLength = 10
defaultArtemisActivationQueueLength = 0
defaultRestAPITemplate = "http://<<managementEndpoint>>/console/jolokia/read/org.apache.activemq.artemis:broker=\"<<brokerName>>\",component=addresses,address=\"<<brokerAddress>>\",subcomponent=queues,routing-type=\"anycast\",queue=\"<<queueName>>\"/MessageCount"
defaultCorsHeader = "http://%s"
)

var artemisLog = logf.Log.WithName("artemis_queue_scaler")
Expand Down Expand Up @@ -83,6 +85,7 @@ func parseArtemisMetadata(config *ScalerConfig) (*artemisMetadata, error) {
meta := artemisMetadata{}

meta.queueLength = defaultArtemisQueueLength
meta.activationQueueLength = defaultArtemisActivationQueueLength

if val, ok := config.TriggerMetadata["restApiTemplate"]; ok && val != "" {
meta.restAPITemplate = config.TriggerMetadata["restApiTemplate"]
Expand Down Expand Up @@ -128,6 +131,15 @@ func parseArtemisMetadata(config *ScalerConfig) (*artemisMetadata, error) {
meta.queueLength = queueLength
}

if val, ok := config.TriggerMetadata["activationQueueLength"]; ok {
activationQueueLength, err := strconv.ParseInt(val, 10, 64)
if err != nil {
return nil, fmt.Errorf("can't parse activationQueueLength: %s", err)
}

meta.activationQueueLength = activationQueueLength
}

if val, ok := config.AuthParams["username"]; ok && val != "" {
meta.username = val
} else if val, ok := config.TriggerMetadata["username"]; ok && val != "" {
Expand Down Expand Up @@ -173,7 +185,7 @@ func (s *artemisScaler) IsActive(ctx context.Context) (bool, error) {
return false, err
}

return messages > 0, nil
return messages > s.metadata.activationQueueLength, nil
}

// getAPIParameters parse restAPITemplate to provide managementEndpoint , brokerName, brokerAddress, queueName
Expand Down
20 changes: 20 additions & 0 deletions tests/helper/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,26 @@ func WaitForDeploymentReplicaCount(t *testing.T, kc *kubernetes.Clientset, name,
return false
}

// Waits until deployment count hits target or number of iterations are done.
func WaitForDeploymentReplicaReadyCount(t *testing.T, kc *kubernetes.Clientset, name, namespace string,
target, iterations, intervalSeconds int) bool {
for i := 0; i < iterations; i++ {
deployment, _ := kc.AppsV1().Deployments(namespace).Get(context.Background(), name, metav1.GetOptions{})
replicas := deployment.Status.ReadyReplicas

t.Logf("Waiting for deployment replicas to hit target. Deployment - %s, Current - %d, Target - %d",
name, replicas, target)

if replicas == int32(target) {
return true
}

time.Sleep(time.Duration(intervalSeconds) * time.Second)
}

return false
}

// Waits until statefulset count hits target or number of iterations are done.
func WaitForStatefulsetReplicaReadyCount(t *testing.T, kc *kubernetes.Clientset, name, namespace string,
target, iterations, intervalSeconds int) bool {
Expand Down
Loading