From 3e846ae65a15b43aec3578986c78f6d8af4cbc1f Mon Sep 17 00:00:00 2001 From: Aaron Schlesinger Date: Tue, 27 Apr 2021 14:09:35 -0700 Subject: [PATCH 1/3] Adding HTTP timeout to the IBM MQ Scaler Signed-off-by: Aaron Schlesinger --- pkg/scalers/ibmmq_scaler.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/pkg/scalers/ibmmq_scaler.go b/pkg/scalers/ibmmq_scaler.go index 625629f903f..c386bb6dffb 100644 --- a/pkg/scalers/ibmmq_scaler.go +++ b/pkg/scalers/ibmmq_scaler.go @@ -10,6 +10,7 @@ import ( "net/http" "net/url" "strconv" + "time" v2beta2 "k8s.io/api/autoscaling/v2beta2" "k8s.io/apimachinery/pkg/api/resource" @@ -29,7 +30,8 @@ const ( // IBMMQScaler assigns struct data pointer to metadata variable type IBMMQScaler struct { - metadata *IBMMQMetadata + metadata *IBMMQMetadata + defaultHTTPTimeout time.Duration } // IBMMQMetadata Metadata used by KEDA to query IBM MQ queue depth and scale @@ -65,7 +67,10 @@ func NewIBMMQScaler(config *ScalerConfig) (Scaler, error) { return nil, fmt.Errorf("error parsing IBM MQ metadata: %s", err) } - return &IBMMQScaler{metadata: meta}, nil + return &IBMMQScaler{ + metadata: meta, + defaultHTTPTimeout: config.GlobalHTTPTimeout, + }, nil } // Close closes and returns nil @@ -168,7 +173,8 @@ func (s *IBMMQScaler) getQueueDepthViaHTTP() (int, error) { tr := &http.Transport{ TLSClientConfig: &tls.Config{InsecureSkipVerify: s.metadata.tlsDisabled}, } - client := &http.Client{Transport: tr} + client := kedautil.CreateHTTPClient(s.defaultHTTPTimeout) + client.Transport = tr resp, err := client.Do(req) if err != nil { From 5101258693b26ebeb5f697654cf9b286b5cc1fe4 Mon Sep 17 00:00:00 2001 From: Aaron Schlesinger Date: Tue, 27 Apr 2021 14:14:52 -0700 Subject: [PATCH 2/3] adding to changelog Signed-off-by: Aaron Schlesinger --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c72e2649f1..b0c6035ad63 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ - Add Azure Pipelines Scaler ([#1706](https://github.com/kedacore/keda/pull/1706)) - Add OpenStack Metrics Scaler ([#1382](https://github.com/kedacore/keda/issues/1382)) - Fixed goroutine leaks in usage of timers ([#1704](https://github.com/kedacore/keda/pull/1704) | [#1739](https://github.com/kedacore/keda/pull/1739)) +- Setting timeouts in the HTTP client used by the IBM MQ scaler ([#1758](https://github.com/kedacore/keda/pull/1758)) ### New From 53351e03aa08dbcac397c02a4c06df648907854b Mon Sep 17 00:00:00 2001 From: Aaron Schlesinger Date: Tue, 27 Apr 2021 14:17:56 -0700 Subject: [PATCH 3/3] fixing tests Signed-off-by: Aaron Schlesinger --- pkg/scalers/ibmmq_scaler_test.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pkg/scalers/ibmmq_scaler_test.go b/pkg/scalers/ibmmq_scaler_test.go index 541fa3ac134..2b152352b4f 100644 --- a/pkg/scalers/ibmmq_scaler_test.go +++ b/pkg/scalers/ibmmq_scaler_test.go @@ -3,6 +3,7 @@ package scalers import ( "fmt" "testing" + "time" ) // Test host URLs for validation @@ -98,11 +99,15 @@ func TestParseDefaultQueueDepth(t *testing.T) { func TestIBMMQGetMetricSpecForScaling(t *testing.T) { for _, testData := range IBMMQMetricIdentifiers { metadata, err := parseIBMMQMetadata(&ScalerConfig{ResolvedEnv: sampleIBMMQResolvedEnv, TriggerMetadata: testData.metadataTestData.metadata, AuthParams: testData.metadataTestData.authParams}) + httpTimeout := 100 * time.Millisecond if err != nil { t.Fatal("Could not parse metadata:", err) } - mockIBMMQScaler := IBMMQScaler{metadata} + mockIBMMQScaler := IBMMQScaler{ + metadata: metadata, + defaultHTTPTimeout: httpTimeout, + } metricSpec := mockIBMMQScaler.GetMetricSpecForScaling() metricName := metricSpec[0].External.Metric.Name