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

Adding HTTP timeout to the IBM MQ Scaler #1758

Merged
merged 3 commits into from
Apr 28, 2021
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 9 additions & 3 deletions pkg/scalers/ibmmq_scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"net/http"
"net/url"
"strconv"
"time"

v2beta2 "k8s.io/api/autoscaling/v2beta2"
"k8s.io/apimachinery/pkg/api/resource"
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
7 changes: 6 additions & 1 deletion pkg/scalers/ibmmq_scaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package scalers
import (
"fmt"
"testing"
"time"
)

// Test host URLs for validation
Expand Down Expand Up @@ -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

Expand Down