Skip to content

Commit abd4b41

Browse files
committed
transfer to *Options struct
1 parent bb8f471 commit abd4b41

File tree

3 files changed

+29
-19
lines changed

3 files changed

+29
-19
lines changed

pkg/services/alertmanager.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ type AlertmanagerNotification struct {
3333

3434
// AlertmanagerOptions cluster configuration
3535
type AlertmanagerOptions struct {
36-
Targets []string `json:"targets"`
37-
Scheme string `json:"scheme"`
38-
APIPath string `json:"apiPath"`
39-
BasicAuth *BasicAuth `json:"basicAuth"`
40-
BearerToken string `json:"bearerToken"`
41-
InsecureSkipVerify bool `json:"insecureSkipVerify"`
42-
Timeout int `json:"timeout"`
36+
Targets []string `json:"targets"`
37+
Scheme string `json:"scheme"`
38+
APIPath string `json:"apiPath"`
39+
BasicAuth *BasicAuth `json:"basicAuth"`
40+
BearerToken string `json:"bearerToken"`
41+
Transport httputil.HTTPTransportSettings `json:"transport"`
42+
Timeout int `json:"timeout"`
4343
}
4444

4545
// NewAlertmanagerService new service
@@ -207,7 +207,7 @@ func (s alertmanagerService) Send(notification Notification, dest Destination) e
207207
func (s alertmanagerService) sendOneTarget(ctx context.Context, target string, rawBody []byte) error {
208208
rawURL := fmt.Sprintf("%v://%v%v", s.opts.Scheme, target, s.opts.APIPath)
209209

210-
transport := httputil.NewTransport(rawURL, s.opts.InsecureSkipVerify)
210+
transport := httputil.NewTransport(rawURL, s.opts.Transport)
211211
client := &http.Client{
212212
Transport: httputil.NewLoggingRoundTripper(transport, s.entry),
213213
}

pkg/services/github.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@ var (
2626
)
2727

2828
type GitHubOptions struct {
29-
AppID interface{} `json:"appID"`
30-
InstallationID interface{} `json:"installationID"`
31-
PrivateKey string `json:"privateKey"`
32-
EnterpriseBaseURL string `json:"enterpriseBaseURL"`
29+
AppID interface{} `json:"appID"`
30+
InstallationID interface{} `json:"installationID"`
31+
PrivateKey string `json:"privateKey"`
32+
EnterpriseBaseURL string `json:"enterpriseBaseURL"`
33+
Transport httputil.HTTPTransportSettings `json:"transport"`
3334
}
3435

3536
type GitHubNotification struct {
@@ -396,7 +397,7 @@ func NewGitHubService(opts GitHubOptions) (*gitHubService, error) {
396397
}
397398

398399
tr := httputil.NewLoggingRoundTripper(
399-
httputil.NewTransport(url, false), log.WithField("service", "github"))
400+
httputil.NewTransport(url, opts.Transport), log.WithField("service", "github"))
400401
itr, err := ghinstallation.New(tr, appID, installationID, []byte(opts.PrivateKey))
401402
if err != nil {
402403
return nil, err

pkg/util/http/transport.go

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,32 @@ import (
55
"crypto/x509"
66
"net/http"
77
"net/url"
8+
"time"
89
)
910

11+
type HTTPTransportSettings struct {
12+
MaxIdleConns int `json:"maxIdleConns"`
13+
MaxIdleConnsPerHost int `json:"maxIdleConnsPerHost"`
14+
MaxConnsPerHost int `json:"maxConnsPerHost"`
15+
IdleConnTimeout time.Duration `json:"idleConnTimeout"`
16+
InsecureSkipVerify bool `json:"insecureSkipVerify"`
17+
}
18+
1019
var certResolver func(serverName string) ([]string, error)
1120

1221
func SetCertResolver(resolver func(serverName string) ([]string, error)) {
1322
certResolver = resolver
1423
}
1524

16-
func NewTransport(rawURL string, insecureSkipVerify bool) *http.Transport {
25+
func NewTransport(rawURL string, set HTTPTransportSettings) *http.Transport {
1726
transport := &http.Transport{
1827
Proxy: http.ProxyFromEnvironment,
19-
MaxIdleConns: 0,
20-
MaxIdleConnsPerHost: 0,
21-
MaxConnsPerHost: 0,
22-
IdleConnTimeout: 0,
28+
MaxIdleConns: set.MaxIdleConns,
29+
MaxIdleConnsPerHost: set.MaxIdleConnsPerHost,
30+
MaxConnsPerHost: set.MaxConnsPerHost,
31+
IdleConnTimeout: set.IdleConnTimeout,
2332
}
24-
if insecureSkipVerify {
33+
if set.InsecureSkipVerify {
2534
transport.TLSClientConfig = &tls.Config{
2635
InsecureSkipVerify: true,
2736
}

0 commit comments

Comments
 (0)