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,
|
AutoCompactionRetention: cfg.AutoCompactionRetention,
|
||||||
QuotaBackendBytes: cfg.QuotaBackendBytes,
|
QuotaBackendBytes: cfg.QuotaBackendBytes,
|
||||||
StrictReconfigCheck: cfg.StrictReconfigCheck,
|
StrictReconfigCheck: cfg.StrictReconfigCheck,
|
||||||
EnablePprof: cfg.EnablePprof,
|
|
||||||
ClientCertAuthEnabled: cfg.ClientTLSInfo.ClientCertAuth,
|
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")
|
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)
|
sctxs = make(map[string]*serveCtx)
|
||||||
for _, u := range cfg.LCUrls {
|
for _, u := range cfg.LCUrls {
|
||||||
sctx := newServeCtx()
|
sctx := newServeCtx()
|
||||||
@ -284,6 +287,9 @@ func startClientListeners(cfg *Config) (sctxs map[string]*serveCtx, err error) {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
sctx.userHandlers = cfg.UserHandlers
|
sctx.userHandlers = cfg.UserHandlers
|
||||||
|
if cfg.EnablePprof {
|
||||||
|
sctx.registerPprof()
|
||||||
|
}
|
||||||
sctxs[u.Host] = sctx
|
sctxs[u.Host] = sctx
|
||||||
}
|
}
|
||||||
return sctxs, nil
|
return sctxs, nil
|
||||||
|
@ -20,6 +20,7 @@ import (
|
|||||||
defaultLog "log"
|
defaultLog "log"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/http/pprof"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -35,6 +36,8 @@ import (
|
|||||||
"google.golang.org/grpc/credentials"
|
"google.golang.org/grpc/credentials"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const pprofPrefix = "/debug/pprof"
|
||||||
|
|
||||||
type serveCtx struct {
|
type serveCtx struct {
|
||||||
l net.Listener
|
l net.Listener
|
||||||
secure bool
|
secure bool
|
||||||
@ -181,3 +184,23 @@ func (sctx *serveCtx) createMux(gwmux *gw.ServeMux, handler http.Handler) *http.
|
|||||||
httpmux.Handle("/", handler)
|
httpmux.Handle("/", handler)
|
||||||
return httpmux
|
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"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/pprof"
|
|
||||||
"net/url"
|
"net/url"
|
||||||
"path"
|
"path"
|
||||||
"strconv"
|
"strconv"
|
||||||
@ -57,7 +56,6 @@ const (
|
|||||||
healthPath = "/health"
|
healthPath = "/health"
|
||||||
versionPath = "/version"
|
versionPath = "/version"
|
||||||
configPath = "/config"
|
configPath = "/config"
|
||||||
pprofPrefix = "/debug/pprof"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewClientHandler generates a muxed http.Handler with the given parameters to serve etcd client requests.
|
// 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)
|
mux.Handle(deprecatedMachinesPrefix, dmh)
|
||||||
handleAuth(mux, sech)
|
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)
|
return requestLogger(mux)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,8 +55,6 @@ type ServerConfig struct {
|
|||||||
|
|
||||||
StrictReconfigCheck bool
|
StrictReconfigCheck bool
|
||||||
|
|
||||||
EnablePprof bool
|
|
||||||
|
|
||||||
// ClientCertAuthEnabled is true when cert has been signed by the client CA.
|
// ClientCertAuthEnabled is true when cert has been signed by the client CA.
|
||||||
ClientCertAuthEnabled bool
|
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) 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
|
// configure sends a configuration change through consensus and
|
||||||
// then waits for it to be applied to the server. It
|
// then waits for it to be applied to the server. It
|
||||||
// will block until the change is performed or there is an error.
|
// will block until the change is performed or there is an error.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user