mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
etcdserver, embed, v2http: move pprof setup to embed
Seems like a better place for prof setup since it's not specific to v2.
This commit is contained in:
parent
46e63cc14a
commit
2c06def8ca
@ -117,7 +117,6 @@ func StartEtcd(inCfg *Config) (e *Etcd, err error) {
|
||||
AutoCompactionRetention: cfg.AutoCompactionRetention,
|
||||
QuotaBackendBytes: cfg.QuotaBackendBytes,
|
||||
StrictReconfigCheck: cfg.StrictReconfigCheck,
|
||||
EnablePprof: cfg.EnablePprof,
|
||||
ClientCertAuthEnabled: cfg.ClientTLSInfo.ClientCertAuth,
|
||||
}
|
||||
|
||||
@ -230,6 +229,10 @@ func startClientListeners(cfg *Config) (sctxs map[string]*serveCtx, err error) {
|
||||
plog.Warningf("ignoring client auto TLS since certs given")
|
||||
}
|
||||
|
||||
if cfg.EnablePprof {
|
||||
plog.Infof("pprof is enabled under %s", pprofPrefix)
|
||||
}
|
||||
|
||||
sctxs = make(map[string]*serveCtx)
|
||||
for _, u := range cfg.LCUrls {
|
||||
sctx := newServeCtx()
|
||||
@ -284,6 +287,9 @@ func startClientListeners(cfg *Config) (sctxs map[string]*serveCtx, err error) {
|
||||
}
|
||||
}()
|
||||
sctx.userHandlers = cfg.UserHandlers
|
||||
if cfg.EnablePprof {
|
||||
sctx.registerPprof()
|
||||
}
|
||||
sctxs[u.Host] = sctx
|
||||
}
|
||||
return sctxs, nil
|
||||
|
@ -20,6 +20,7 @@ import (
|
||||
defaultLog "log"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/http/pprof"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@ -35,6 +36,8 @@ import (
|
||||
"google.golang.org/grpc/credentials"
|
||||
)
|
||||
|
||||
const pprofPrefix = "/debug/pprof"
|
||||
|
||||
type serveCtx struct {
|
||||
l net.Listener
|
||||
secure bool
|
||||
@ -181,3 +184,23 @@ func (sctx *serveCtx) createMux(gwmux *gw.ServeMux, handler http.Handler) *http.
|
||||
httpmux.Handle("/", handler)
|
||||
return httpmux
|
||||
}
|
||||
|
||||
func (sctx *serveCtx) registerPprof() {
|
||||
f := func(s string, h http.Handler) {
|
||||
if sctx.userHandlers[s] != nil {
|
||||
plog.Warningf("path %s already registered by user handler", s)
|
||||
return
|
||||
}
|
||||
sctx.userHandlers[s] = h
|
||||
}
|
||||
f(pprofPrefix+"/", http.HandlerFunc(pprof.Index))
|
||||
f(pprofPrefix+"/profile", http.HandlerFunc(pprof.Profile))
|
||||
f(pprofPrefix+"/symbol", http.HandlerFunc(pprof.Symbol))
|
||||
f(pprofPrefix+"/cmdline", http.HandlerFunc(pprof.Cmdline))
|
||||
f(pprofPrefix+"/trace", http.HandlerFunc(pprof.Trace))
|
||||
|
||||
f(pprofPrefix+"/heap", pprof.Handler("heap"))
|
||||
f(pprofPrefix+"/goroutine", pprof.Handler("goroutine"))
|
||||
f(pprofPrefix+"/threadcreate", pprof.Handler("threadcreate"))
|
||||
f(pprofPrefix+"/block", pprof.Handler("block"))
|
||||
}
|
||||
|
@ -21,7 +21,6 @@ import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/http/pprof"
|
||||
"net/url"
|
||||
"path"
|
||||
"strconv"
|
||||
@ -57,7 +56,6 @@ const (
|
||||
healthPath = "/health"
|
||||
versionPath = "/version"
|
||||
configPath = "/config"
|
||||
pprofPrefix = "/debug/pprof"
|
||||
)
|
||||
|
||||
// NewClientHandler generates a muxed http.Handler with the given parameters to serve etcd client requests.
|
||||
@ -113,23 +111,6 @@ func NewClientHandler(server *etcdserver.EtcdServer, timeout time.Duration) http
|
||||
mux.Handle(deprecatedMachinesPrefix, dmh)
|
||||
handleAuth(mux, sech)
|
||||
|
||||
if server.IsPprofEnabled() {
|
||||
plog.Infof("pprof is enabled under %s", pprofPrefix)
|
||||
|
||||
mux.HandleFunc(pprofPrefix+"/", pprof.Index)
|
||||
mux.HandleFunc(pprofPrefix+"/profile", pprof.Profile)
|
||||
mux.HandleFunc(pprofPrefix+"/symbol", pprof.Symbol)
|
||||
mux.HandleFunc(pprofPrefix+"/cmdline", pprof.Cmdline)
|
||||
// TODO: currently, we don't create an entry for pprof.Trace,
|
||||
// because go 1.4 doesn't provide it. After support of go 1.4 is dropped,
|
||||
// we should add the entry.
|
||||
|
||||
mux.Handle(pprofPrefix+"/heap", pprof.Handler("heap"))
|
||||
mux.Handle(pprofPrefix+"/goroutine", pprof.Handler("goroutine"))
|
||||
mux.Handle(pprofPrefix+"/threadcreate", pprof.Handler("threadcreate"))
|
||||
mux.Handle(pprofPrefix+"/block", pprof.Handler("block"))
|
||||
}
|
||||
|
||||
return requestLogger(mux)
|
||||
}
|
||||
|
||||
|
@ -55,8 +55,6 @@ type ServerConfig struct {
|
||||
|
||||
StrictReconfigCheck bool
|
||||
|
||||
EnablePprof bool
|
||||
|
||||
// ClientCertAuthEnabled is true when cert has been signed by the client CA.
|
||||
ClientCertAuthEnabled bool
|
||||
}
|
||||
|
@ -1098,8 +1098,6 @@ func (s *EtcdServer) Lead() uint64 { return atomic.LoadUint64(&s.r.lead) }
|
||||
|
||||
func (s *EtcdServer) Leader() types.ID { return types.ID(s.Lead()) }
|
||||
|
||||
func (s *EtcdServer) IsPprofEnabled() bool { return s.Cfg.EnablePprof }
|
||||
|
||||
// configure sends a configuration change through consensus and
|
||||
// then waits for it to be applied to the server. It
|
||||
// will block until the change is performed or there is an error.
|
||||
|
Loading…
x
Reference in New Issue
Block a user