Reuse http.DefaultTransport in UIMetricsProxy (#14521)
http.Transport keeps a pool of connections and should be reused when possible. We instantiate a new http.DefaultTransport for every metrics request, making large numbers of concurrent requests inefficiently spin up new connections instead of reusing open ones.
This commit is contained in:
parent
6cd25728e5
commit
331c756471
|
@ -0,0 +1,3 @@
|
||||||
|
```release-note:improvement
|
||||||
|
ui: Reuse connections for requests to /v1/internal/ui/metrics-proxy/
|
||||||
|
```
|
|
@ -939,8 +939,9 @@ func (a *Agent) listenHTTP() ([]apiServer, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
srv := &HTTPHandlers{
|
srv := &HTTPHandlers{
|
||||||
agent: a,
|
agent: a,
|
||||||
denylist: NewDenylist(a.config.HTTPBlockEndpoints),
|
denylist: NewDenylist(a.config.HTTPBlockEndpoints),
|
||||||
|
proxyTransport: http.DefaultTransport,
|
||||||
}
|
}
|
||||||
a.configReloaders = append(a.configReloaders, srv.ReloadConfig)
|
a.configReloaders = append(a.configReloaders, srv.ReloadConfig)
|
||||||
a.httpHandlers = srv
|
a.httpHandlers = srv
|
||||||
|
|
|
@ -81,6 +81,10 @@ type HTTPHandlers struct {
|
||||||
configReloaders []ConfigReloader
|
configReloaders []ConfigReloader
|
||||||
h http.Handler
|
h http.Handler
|
||||||
metricsProxyCfg atomic.Value
|
metricsProxyCfg atomic.Value
|
||||||
|
|
||||||
|
// proxyTransport is used by UIMetricsProxy to keep
|
||||||
|
// a managed pool of connections.
|
||||||
|
proxyTransport http.RoundTripper
|
||||||
}
|
}
|
||||||
|
|
||||||
// endpoint is a Consul-specific HTTP handler that takes the usual arguments in
|
// endpoint is a Consul-specific HTTP handler that takes the usual arguments in
|
||||||
|
|
|
@ -771,6 +771,7 @@ func (s *HTTPHandlers) UIMetricsProxy(resp http.ResponseWriter, req *http.Reques
|
||||||
Director: func(r *http.Request) {
|
Director: func(r *http.Request) {
|
||||||
r.URL = u
|
r.URL = u
|
||||||
},
|
},
|
||||||
|
Transport: s.proxyTransport,
|
||||||
ErrorLog: log.StandardLogger(&hclog.StandardLoggerOptions{
|
ErrorLog: log.StandardLogger(&hclog.StandardLoggerOptions{
|
||||||
InferLevels: true,
|
InferLevels: true,
|
||||||
}),
|
}),
|
||||||
|
|
Loading…
Reference in New Issue