Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-pages.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgor <iwiedler@gitlab.com>2020-05-08 13:11:49 +0300
committerVladimir Shushlin <vshushlin@gitlab.com>2020-05-08 13:11:49 +0300
commit8b60c18f1f68a0899815ebc0e2f24559c74649f3 (patch)
tree7910e77b6a9bcdfdab21e8a5b7b1372841a84d62 /internal
parent71417ad27d55fe2dd197f21d4a1454fb3bb552eb (diff)
explicitly set MaxIdleConns, so that it is clear we need to update it when increasing MaxIdleConnsPerHost
Diffstat (limited to 'internal')
-rw-r--r--internal/artifact/artifact.go2
-rw-r--r--internal/auth/auth.go2
-rw-r--r--internal/httptransport/transport.go24
-rw-r--r--internal/httptransport/transport_test.go8
4 files changed, 26 insertions, 10 deletions
diff --git a/internal/artifact/artifact.go b/internal/artifact/artifact.go
index 91ecbcf8..ef173d9e 100644
--- a/internal/artifact/artifact.go
+++ b/internal/artifact/artifact.go
@@ -51,7 +51,7 @@ func New(server string, timeoutSeconds int, pagesDomain string) *Artifact {
suffix: "." + strings.ToLower(pagesDomain),
client: &http.Client{
Timeout: time.Second * time.Duration(timeoutSeconds),
- Transport: httptransport.Transport,
+ Transport: httptransport.InternalTransport,
},
}
}
diff --git a/internal/auth/auth.go b/internal/auth/auth.go
index f30c7407..c582d96b 100644
--- a/internal/auth/auth.go
+++ b/internal/auth/auth.go
@@ -618,7 +618,7 @@ func New(pagesDomain string, storeSecret string, clientID string, clientSecret s
gitLabServer: strings.TrimRight(gitLabServer, "/"),
apiClient: &http.Client{
Timeout: 5 * time.Second,
- Transport: httptransport.Transport,
+ Transport: httptransport.InternalTransport,
},
store: createCookieStore(storeSecret),
}
diff --git a/internal/httptransport/transport.go b/internal/httptransport/transport.go
index ba2aa5eb..78da6e99 100644
--- a/internal/httptransport/transport.go
+++ b/internal/httptransport/transport.go
@@ -19,13 +19,8 @@ var (
sysPoolOnce = &sync.Once{}
sysPool *x509.CertPool
- // Transport can be used with http.Client with TLS and certificates
- Transport = &http.Transport{
- DialTLS: func(network, addr string) (net.Conn, error) {
- return tls.Dial(network, addr, &tls.Config{RootCAs: pool()})
- },
- Proxy: http.ProxyFromEnvironment,
- }
+ // InternalTransport can be used with http.Client with TLS and certificates
+ InternalTransport = newInternalTransport()
)
type meteredRoundTripper struct {
@@ -34,11 +29,24 @@ type meteredRoundTripper struct {
counter *prometheus.CounterVec
}
+func newInternalTransport() *http.Transport {
+ return &http.Transport{
+ DialTLS: func(network, addr string) (net.Conn, error) {
+ return tls.Dial(network, addr, &tls.Config{RootCAs: pool()})
+ },
+ Proxy: http.ProxyFromEnvironment,
+ // overrides the DefaultMaxIdleConnsPerHost = 2
+ MaxIdleConns: 100,
+ MaxIdleConnsPerHost: 100,
+ IdleConnTimeout: 90 * time.Second,
+ }
+}
+
// NewTransportWithMetrics will create a custom http.RoundTripper that can be used with an http.Client.
// The RoundTripper will report metrics based on the collectors passed.
func NewTransportWithMetrics(gaugeVec *prometheus.GaugeVec, counterVec *prometheus.CounterVec) http.RoundTripper {
return &meteredRoundTripper{
- next: Transport,
+ next: InternalTransport,
durations: gaugeVec,
counter: counterVec,
}
diff --git a/internal/httptransport/transport_test.go b/internal/httptransport/transport_test.go
index cfb8d708..e3270ebe 100644
--- a/internal/httptransport/transport_test.go
+++ b/internal/httptransport/transport_test.go
@@ -6,6 +6,7 @@ import (
"net/http/httptest"
"strconv"
"testing"
+ "time"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/testutil"
@@ -89,3 +90,10 @@ type mockRoundTripper struct {
func (mrt *mockRoundTripper) RoundTrip(r *http.Request) (*http.Response, error) {
return mrt.res, mrt.err
}
+
+func TestInternalTransportShouldHaveCustomConnectionPoolSettings(t *testing.T) {
+ require.EqualValues(t, 100, InternalTransport.MaxIdleConns)
+ require.EqualValues(t, 100, InternalTransport.MaxIdleConnsPerHost)
+ require.EqualValues(t, 0, InternalTransport.MaxConnsPerHost)
+ require.EqualValues(t, 90*time.Second, InternalTransport.IdleConnTimeout)
+}