From 3deef0112557123ee95b0fbc5fa547941c703d49 Mon Sep 17 00:00:00 2001 From: Sergiy Poplavskyi Date: Tue, 11 Aug 2020 09:14:15 +0300 Subject: [PATCH 1/4] BugFix: Username and Password is empty This fix allows to use a scaler definition without kubernetes secret, passing username and password in scaler metadata according to documentation for scaler Signed-off-by: Sergiy Poplavskyi --- pkg/scalers/artemis_scaler.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/pkg/scalers/artemis_scaler.go b/pkg/scalers/artemis_scaler.go index c41ba4c4292..6152f67f746 100644 --- a/pkg/scalers/artemis_scaler.go +++ b/pkg/scalers/artemis_scaler.go @@ -92,13 +92,15 @@ func parseArtemisMetadata(resolvedEnv, metadata, authParams map[string]string) ( meta.queueLength = queueLength } - if val, ok := authParams["username"]; ok { + if val, ok := authParams["username"]; ok && val != "" { meta.username = val - } else if val, ok := metadata["username"]; ok { + } else if val, ok := metadata["username"]; ok && val != "" { username := val - if val, ok := resolvedEnv[username]; ok { + if val, ok := resolvedEnv[username]; ok && val != "" { meta.username = val + } else { + meta.username = username } } @@ -106,13 +108,15 @@ func parseArtemisMetadata(resolvedEnv, metadata, authParams map[string]string) ( return nil, fmt.Errorf("username cannot be empty") } - if val, ok := authParams["password"]; ok { + if val, ok := authParams["password"]; ok && val != "" { meta.password = val - } else if val, ok := metadata["password"]; ok { + } else if val, ok := metadata["password"]; ok && val != "" { password := val - if val, ok := resolvedEnv[password]; ok { + if val, ok := resolvedEnv[password]; ok && val != "" { meta.password = val + } else { + meta.password = password } } From cd8149dad0d792f78a9910b248aee4a61521625d Mon Sep 17 00:00:00 2001 From: Sergiy Poplavskyi Date: Tue, 11 Aug 2020 09:18:13 +0300 Subject: [PATCH 2/4] BugFix: Invalid argument when logging This fix address an "invalid argument" exception, that throwing any time, when this line executed. Signed-off-by: Sergiy Poplavskyi --- pkg/scalers/artemis_scaler.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/scalers/artemis_scaler.go b/pkg/scalers/artemis_scaler.go index 6152f67f746..e87c0a567c7 100644 --- a/pkg/scalers/artemis_scaler.go +++ b/pkg/scalers/artemis_scaler.go @@ -178,7 +178,7 @@ func (s *artemisScaler) getQueueMessageCount() (int, error) { return -1, fmt.Errorf("Artemis management endpoint response error code : %d", resp.StatusCode) } - artemisLog.V(1).Info("Artemis scaler: Providing metrics based on current queue length ", messageCount, "queue length limit", s.metadata.queueLength) + artemisLog.V(1).Info(fmt.Sprintf("Artemis scaler: Providing metrics based on current queue length %d queue length limit %d", messageCount, s.metadata.queueLength)) return messageCount, nil } From 94233626a2d1eb3286ce4f985670ece902166f05 Mon Sep 17 00:00:00 2001 From: Sergiy Poplavskyi Date: Tue, 11 Aug 2020 09:25:07 +0300 Subject: [PATCH 3/4] Feature: Introduce optional metadata patameter "restApiTemplate" to be able to finetune ActiveMQ endpoint In different versions (or configurations) ActiveMQ REST andpoint can be different, than hardcoded in this scaler. To be able to finetune it, I have introduced an optional parameter to change this template. Signed-off-by: Sergiy Poplavskyi --- pkg/scalers/artemis_scaler.go | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/pkg/scalers/artemis_scaler.go b/pkg/scalers/artemis_scaler.go index e87c0a567c7..acadb3c4d32 100644 --- a/pkg/scalers/artemis_scaler.go +++ b/pkg/scalers/artemis_scaler.go @@ -7,6 +7,7 @@ import ( "fmt" "net/http" "strconv" + "strings" "time" v2beta2 "k8s.io/api/autoscaling/v2beta2" @@ -28,6 +29,7 @@ type artemisMetadata struct { brokerAddress string username string password string + restApiTemplate string queueLength int } @@ -41,6 +43,7 @@ type artemisMonitoring struct { const ( artemisMetricType = "External" defaultArtemisQueueLength = 10 + defaultRestApiTemplate = "http://<>/console/jolokia/read/org.apache.activemq.artemis:broker=\"<>\",component=addresses,address=\"<>\",subcomponent=queues,routing-type=\"anycast\",queue=\"<>\"/MessageCount" ) var artemisLog = logf.Log.WithName("artemis_queue_scaler") @@ -63,6 +66,12 @@ func parseArtemisMetadata(resolvedEnv, metadata, authParams map[string]string) ( meta.queueLength = defaultArtemisQueueLength + if val, ok := metadata["restApiTemplate"]; ok && val != "" { + meta.restApiTemplate = metadata["restApiTemplate"] + } else { + meta.restApiTemplate = defaultRestApiTemplate + } + if metadata["managementEndpoint"] == "" { return nil, errors.New("no management endpoint given") } @@ -137,13 +146,15 @@ func (s *artemisScaler) IsActive(ctx context.Context) (bool, error) { return messages > 0, nil } -func (s *artemisScaler) getArtemisManagementEndpoint() string { - return "http://" + s.metadata.managementEndpoint -} - func (s *artemisScaler) getMonitoringEndpoint() string { - monitoringEndpoint := fmt.Sprintf("%s/console/jolokia/read/org.apache.activemq.artemis:broker=\"%s\",component=addresses,address=\"%s\",subcomponent=queues,routing-type=\"anycast\",queue=\"%s\"/MessageCount", - s.getArtemisManagementEndpoint(), s.metadata.brokerName, s.metadata.brokerAddress, s.metadata.queueName) + + replacer := strings.NewReplacer("<>", s.metadata.managementEndpoint, + "<>", s.metadata.queueName, + "<>", s.metadata.brokerName, + "<>", s.metadata.brokerAddress) + + monitoringEndpoint := replacer.Replace(s.metadata.restApiTemplate) + return monitoringEndpoint } From 5d6219b89b2059037eb2720d6cf69b0e6c91bf9c Mon Sep 17 00:00:00 2001 From: Sergiy Poplavskyi Date: Tue, 11 Aug 2020 09:28:20 +0300 Subject: [PATCH 4/4] [v2] Added "artemis-queue" scaler to list of scalers for v2 For some reason, ActiveMQ scaler wasn't added to v2. This commit will fix it. Signed-off-by: Sergiy Poplavskyi --- pkg/scaling/scale_handler.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkg/scaling/scale_handler.go b/pkg/scaling/scale_handler.go index 36f908c7c0c..a1279892bb9 100644 --- a/pkg/scaling/scale_handler.go +++ b/pkg/scaling/scale_handler.go @@ -364,6 +364,8 @@ func (h *scaleHandler) getPods(scalableObject interface{}) (*corev1.PodTemplateS func buildScaler(name, namespace, triggerType string, resolvedEnv, triggerMetadata, authParams map[string]string, podIdentity string) (scalers.Scaler, error) { switch triggerType { + case "artemis-queue": + return scalers.NewArtemisQueueScaler(resolvedEnv, triggerMetadata, authParams) case "azure-queue": return scalers.NewAzureQueueScaler(resolvedEnv, triggerMetadata, authParams, podIdentity) case "azure-servicebus":