-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Add e2e test for IBM MQ Scaler #1287
Comments
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions. |
There is a helm chart we can use to run IBM MQ inside testing clusters https://github.com/ibm-messaging/mq-helm/blob/main/charts/ibm-mq/README.md |
Hi @zroubalik could you please assign this issue to me if it's not already being addressed. Thanks |
Thanks! |
Hi @JorTurFer, After taking some time to play with the ibm-mq scaler in order to prepare the e2e test, I discovered some minor bugs and improvements that can be done on the current state of the ibm-scaler and I wanted to have your feedback about them before I apply them.
2024-05-11T15:28:42Z INFO Reconciling ScaledObject {"controller": "scaledobject", "controllerGroup": "keda.sh", "controllerKind": "ScaledObject", "ScaledObject": {"name":"ibmmq-consumer","namespace":"ibm-mq"}, "namespace": "ibm-mq", "name": "ibmmq-consumer", "reconcileID": "cc31d473-4c9a-4c2b-b5ae-7451e0e316a6"}
2024-05-11T15:28:42Z INFO Detected resource targeted for scaling {"controller": "scaledobject", "controllerGroup": "keda.sh", "controllerKind": "ScaledObject", "ScaledObject": {"name":"ibmmq-consumer","namespace":"ibm-mq"}, "namespace": "ibm-mq", "name": "ibmmq-consumer", "reconcileID": "cc31d473-4c9a-4c2b-b5ae-7451e0e316a6", "resource": "apps/v1.Deployment", "name": "ibmmq-consumer"}
2024-05-11T15:28:42Z INFO Updated HPA according to ScaledObject {"controller": "scaledobject", "controllerGroup": "keda.sh", "controllerKind": "ScaledObject", "ScaledObject": {"name":"ibmmq-consumer","namespace":"ibm-mq"}, "namespace": "ibm-mq", "name": "ibmmq-consumer", "reconcileID": "cc31d473-4c9a-4c2b-b5ae-7451e0e316a6", "HPA.Namespace": "ibm-mq", "HPA.Name": "keda-hpa-ibmmq-consumer"}
2024-05-11T15:28:42Z INFO Initializing Scaling logic according to ScaledObject Specification {"controller": "scaledobject", "controllerGroup": "keda.sh", "controllerKind": "ScaledObject", "ScaledObject": {"name":"ibmmq-consumer","namespace":"ibm-mq"}, "namespace": "ibm-mq", "name": "ibmmq-consumer", "reconcileID": "cc31d473-4c9a-4c2b-b5ae-7451e0e316a6"}
2024-05-11T15:28:42Z INFO Reconciling ScaledObject {"controller": "scaledobject", "controllerGroup": "keda.sh", "controllerKind": "ScaledObject", "ScaledObject": {"name":"ibmmq-consumer","namespace":"ibm-mq"}, "namespace": "ibm-mq", "name": "ibmmq-consumer", "reconcileID": "a8fac534-f7ef-4722-9c77-5bb10b262919"}
2024-05-11T15:28:42Z INFO Detected resource targeted for scaling {"controller": "scaledobject", "controllerGroup": "keda.sh", "controllerKind": "ScaledObject", "ScaledObject": {"name":"ibmmq-consumer","namespace":"ibm-mq"}, "namespace": "ibm-mq", "name": "ibmmq-consumer", "reconcileID": "a8fac534-f7ef-4722-9c77-5bb10b262919", "resource": "apps/v1.Deployment", "name": "ibmmq-consumer"}
+2024-05-11T15:28:43Z ERROR scale_handler error getting scale decision {"scaledObject.Namespace": "ibm-mq", "scaledObject.Name": "ibmmq-consumer", "scaler": "IBMMQScaler", "error": "error inspecting IBM MQ queue depth: failed to parse response from REST call: %!w(<nil>)"}
github.com/kedacore/keda/v2/pkg/scaling.(*scaleHandler).getScalerState
/workspace/pkg/scaling/scale_handler.go:783
github.com/kedacore/keda/v2/pkg/scaling.(*scaleHandler).getScaledObjectState.func1
/workspace/pkg/scaling/scale_handler.go:636
package main
import (
"bytes"
"context"
"crypto/tls"
"encoding/json"
"fmt"
"io"
"net/http"
"os"
)
// CommandResponse Full structured response from MQ admin REST query
type CommandResponse struct {
CommandResponse []Response `json:"commandResponse"`
}
// Response The body of the response returned from the MQ admin query
type Response struct {
Parameters Parameters `json:"parameters"`
}
// Parameters Contains the current depth of the IBM MQ Queue
type Parameters struct {
Curdepth int `json:"curdepth"`
}
// getQueueDepthViaHTTP returns the depth of the MQ Queue from the Admin endpoint
func getQueueDepthViaHTTP(ctx context.Context, url, queue string) (int64, error) {
var requestJSON = []byte(`{"type": "runCommandJSON", "command": "display", "qualifier": "qlocal", "name": "` + queue + `", "responseParameters" : ["CURDEPTH"]}`)
fmt.Printf("mqsc command: %s\n\n", string(requestJSON))
req, err := http.NewRequestWithContext(ctx, "POST", url, bytes.NewBuffer(requestJSON))
if err != nil {
return 0, fmt.Errorf("failed to request queue depth: %w", err)
}
req.Header.Set("ibm-mq-rest-csrf-token", "value")
req.Header.Set("Content-Type", "application/json")
req.SetBasicAuth("admin", "my-admin-password")
client := http.Client{
Transport: &http.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: true,
},
Proxy: http.ProxyFromEnvironment,
},
}
resp, err := client.Do(req)
if err != nil {
return 0, fmt.Errorf("failed to contact MQ via REST: %w", err)
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
return 0, fmt.Errorf("failed to ready body of request: %w", err)
}
fmt.Println(string(body))
var response CommandResponse
err = json.Unmarshal(body, &response)
if err != nil {
return 0, fmt.Errorf("failed to parse JSON: %w", err)
}
if response.CommandResponse == nil || len(response.CommandResponse) == 0 {
return 0, fmt.Errorf("failed to parse response from REST call: %v . %w",
response.CommandResponse, err)
}
return int64(response.CommandResponse[0].Parameters.Curdepth), nil
}
func main() {
queueName := os.Args[1]
url := "https://192.168.49.2:30948/ibmmq/rest/v2/admin/action/qmgr/ibmmqnonativeha/mqsc"
fmt.Println(getQueueDepthViaHTTP(context.TODO(), url, queueName))
} Thanks in advance for your feedback. |
Hello!
I'd update docs to reflects the current code, as the code is the real usage.
It's a good idea :)
I'd say that not existing queue should return an error WDYT about these points @zroubalik @tomkerkhove ? |
BTW, the docker image has been already created with this tag |
agree |
IBM MQ Scaler issue: #1253
The text was updated successfully, but these errors were encountered: