Skip to content

Commit 33b036e

Browse files
committed
2 parents 153c5cb + c8c2454 commit 33b036e

File tree

7 files changed

+71
-41
lines changed

7 files changed

+71
-41
lines changed

modules/extensions/loghub/index/query/clients.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ func newHTTPClient(clusterName string) *http.Client {
262262
Proxy: http.ProxyFromEnvironment,
263263
DialContext: t.DialContext,
264264
ForceAttemptHTTP2: true,
265-
MaxIdleConns: 100,
265+
MaxIdleConns: -1,
266266
IdleConnTimeout: 90 * time.Second,
267267
TLSHandshakeTimeout: 10 * time.Second,
268268
ExpectContinueTimeout: 1 * time.Second,

pkg/http/httpclient/client.go

+57-38
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,6 @@ import (
3434
"github.com/erda-project/erda/pkg/clusterdialer"
3535
)
3636

37-
const (
38-
// DialTimeout 建立 tcp 连接的超时时间
39-
DialTimeout = 15 * time.Second
40-
// ClientDefaultTimeout 从建立 tcp 到读完 response body 超时时间
41-
ClientDefaultTimeout = 60 * time.Second
42-
)
43-
4437
type BasicAuth struct {
4538
name string
4639
password string
@@ -202,16 +195,40 @@ func WithEnableAutoRetry(enableAutoRetry bool) OpOption {
202195
}
203196
}
204197

205-
func mkDialContext(option *Option) func(ctx context.Context, network, addr string) (net.Conn, error) {
206-
raw := (&net.Dialer{
207-
Timeout: option.dialTimeout,
208-
KeepAlive: option.dialerKeepalive,
198+
var defaultTransport = newdefaultTransport(newDialContext(0, 0))
199+
200+
func newDialContext(dialTimeout, tcpKeepAlive time.Duration) func(ctx context.Context, network, addr string) (net.Conn, error) {
201+
if dialTimeout == 0 {
202+
dialTimeout = 15 * time.Second
203+
}
204+
if tcpKeepAlive == 0 {
205+
tcpKeepAlive = 60 * time.Second
206+
}
207+
return (&net.Dialer{
208+
Timeout: dialTimeout,
209+
KeepAlive: tcpKeepAlive,
209210
}).DialContext
211+
}
212+
213+
func newdefaultTransport(dialContext func(ctx context.Context, network, addr string) (net.Conn, error)) *http.Transport {
214+
return &http.Transport{
215+
DialContext: dialContext,
216+
Proxy: http.ProxyFromEnvironment,
217+
ForceAttemptHTTP2: false,
218+
MaxIdleConns: 10,
219+
IdleConnTimeout: 90 * time.Second,
220+
TLSHandshakeTimeout: 10 * time.Second,
221+
ExpectContinueTimeout: 1 * time.Second,
222+
}
223+
}
224+
225+
func mkDialContext(clusterDialKey string, dnscache *DNSCache, dialTimeout, tcpKeepAlive time.Duration) func(ctx context.Context, network, addr string) (net.Conn, error) {
226+
raw := newDialContext(dialTimeout, tcpKeepAlive)
210227
dialcontext := raw
211-
if option.clusterDialKey != "" {
212-
return clusterdialer.DialContext(option.clusterDialKey)
228+
if clusterDialKey != "" {
229+
return clusterdialer.DialContext(clusterDialKey)
213230
}
214-
if option.dnscache != nil {
231+
if dnscache != nil {
215232
dialcontext = func(ctx context.Context, network, addr string) (net.Conn, error) {
216233
var host string
217234
var remain string
@@ -231,7 +248,7 @@ func mkDialContext(option *Option) func(ctx context.Context, network, addr strin
231248
if net.ParseIP(host) != nil || (!strings.HasPrefix(network, "tcp") && !strings.HasPrefix(network, "udp")) {
232249
return raw(ctx, network, addr)
233250
}
234-
ips, err := option.dnscache.lookup(host)
251+
ips, err := dnscache.lookup(host)
235252
if err != nil {
236253
return raw(ctx, network, addr)
237254
}
@@ -250,37 +267,39 @@ func mkDialContext(option *Option) func(ctx context.Context, network, addr strin
250267

251268
func New(ops ...OpOption) *HTTPClient {
252269
option := &Option{}
253-
option.dialTimeout = DialTimeout
254-
option.clientTimeout = ClientDefaultTimeout
255270
for _, op := range ops {
256271
op(option)
257272
}
258273

259-
tr := &http.Transport{
260-
DialContext: mkDialContext(option),
261-
MaxIdleConns: 2,
262-
}
263-
if option.proxy != "" {
264-
tr.Proxy = func(request *http.Request) (u *url.URL, err error) {
265-
return url.Parse(option.proxy)
266-
}
267-
}
268-
if option.dialerKeepalive != 0 {
269-
tr.IdleConnTimeout = option.dialerKeepalive
270-
}
271-
tr.ExpectContinueTimeout = 1 * time.Second
272274
proto := "http"
273275
if option.isHTTPS {
274276
proto = "https"
275-
if option.ca != nil {
276-
tr.TLSClientConfig = &tls.Config{
277-
RootCAs: option.ca,
278-
Certificates: []tls.Certificate{option.keyPair},
277+
}
278+
279+
var tr = defaultTransport
280+
if option.clusterDialKey != "" || option.dnscache != nil || option.dialTimeout != 0 || option.clientTimeout != 0 ||
281+
option.proxy != "" || option.dialerKeepalive != 0 || option.ca != nil {
282+
tr = newdefaultTransport(mkDialContext(option.clusterDialKey, option.dnscache, option.dialTimeout, option.clientTimeout))
283+
tr.MaxIdleConns = -1 // disable connection pool
284+
if option.proxy != "" {
285+
tr.Proxy = func(request *http.Request) (u *url.URL, err error) {
286+
return url.Parse(option.proxy)
279287
}
280-
} else {
281-
tr.TLSClientConfig = &tls.Config{
282-
InsecureSkipVerify: true,
283-
Certificates: []tls.Certificate{option.keyPair},
288+
}
289+
if option.dialerKeepalive != 0 {
290+
tr.IdleConnTimeout = option.dialerKeepalive
291+
}
292+
if option.isHTTPS {
293+
if option.ca != nil {
294+
tr.TLSClientConfig = &tls.Config{
295+
RootCAs: option.ca,
296+
Certificates: []tls.Certificate{option.keyPair},
297+
}
298+
} else {
299+
tr.TLSClientConfig = &tls.Config{
300+
InsecureSkipVerify: true,
301+
Certificates: []tls.Certificate{option.keyPair},
302+
}
284303
}
285304
}
286305
}

pkg/http/httpclient/request.go

+1
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ func (r AfterDo) JSON(o interface{}) (*Response, error) {
201201
return nil, err
202202
}
203203
defer resp.Body.Close()
204+
204205
// check content-type before decode body
205206
contentType := resp.Header.Get("Content-Type")
206207
body, err := ioutil.ReadAll(resp.Body)

pkg/http/httpclient/trace.go

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ func (t *DefaultTracer) TraceResponse(r *http.Response) {
4747
io.WriteString(t.w, fmt.Sprintf("TraceResponse: read response body fail: %v", err))
4848
return
4949
}
50+
r.Body.Close()
5051
io.WriteString(t.w, fmt.Sprintf("ResponseBody: %s\n", string(body)))
5152
r.Body = ioutil.NopCloser(bytes.NewReader(body))
5253
}

quick-start/env

+1-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ MASTER_VIP_URL=https://172.21.0.1:443
143143
LB_ADDR=10.0.7.7:80
144144

145145
IS_FDP_CLUSTER=true
146-
DICE_VERSION=1.2.1
146+
DICE_VERSION=1.3.1
147147
DICE_PROTOCOL=http
148148
DICE_SSH_USER=root
149149
DICE_INSIDE=false

quick-start/nginx.conf

+9
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,13 @@ server {
6060
proxy_cache_bypass $http_upgrade;
6161
proxy_redirect off;
6262
}
63+
}
64+
65+
server {
66+
listen 80;
67+
server_name erda.local;
68+
69+
location / {
70+
return 301 http://one.erda.local;
71+
}
6372
}

quick-start/quick-start.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,6 @@ ohai "Erda has been started successfully using ${INSTALL_LOCATION}/quick-start/d
210210

211211
ohai "Next steps:"
212212
echo "visit ${tty_underline}http://erda.local${tty_reset} to start your journey on Erda"
213-
echo "visit ${tty_underline}https://docs.erda.cloud/1.2/manual/install/docker-install.html${tty_reset} for FAQs if you encounter problems installing Erda"
213+
echo "visit ${tty_underline}https://docs.erda.cloud/1.3/manual/install/docker-install.html${tty_reset} for FAQs if you encounter problems installing Erda"
214214
echo "visit ${tty_underline}https://docs.erda.cloud${tty_reset} for full introduction of Erda"
215215
echo "goto ${INSTALL_LOCATION}/quick-start/ dir to check and manage the docker-compose resources"

0 commit comments

Comments
 (0)