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{
|
||||
agent: a,
|
||||
denylist: NewDenylist(a.config.HTTPBlockEndpoints),
|
||||
agent: a,
|
||||
denylist: NewDenylist(a.config.HTTPBlockEndpoints),
|
||||
proxyTransport: http.DefaultTransport,
|
||||
}
|
||||
a.configReloaders = append(a.configReloaders, srv.ReloadConfig)
|
||||
a.httpHandlers = srv
|
||||
|
|
|
@ -81,6 +81,10 @@ type HTTPHandlers struct {
|
|||
configReloaders []ConfigReloader
|
||||
h http.Handler
|
||||
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
|
||||
|
|
|
@ -771,6 +771,7 @@ func (s *HTTPHandlers) UIMetricsProxy(resp http.ResponseWriter, req *http.Reques
|
|||
Director: func(r *http.Request) {
|
||||
r.URL = u
|
||||
},
|
||||
Transport: s.proxyTransport,
|
||||
ErrorLog: log.StandardLogger(&hclog.StandardLoggerOptions{
|
||||
InferLevels: true,
|
||||
}),
|
||||
|
|
Loading…
Reference in New Issue