mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Merge pull request #7384 from heyitsanthony/debug-grpc-tracing
etcdmain: enable grpc tracing with --debug
This commit is contained in:
commit
8f744fe46b
@ -290,9 +290,12 @@ func startClientListeners(cfg *Config) (sctxs map[string]*serveCtx, err error) {
|
||||
sctx.userHandlers[k] = cfg.UserHandlers[k]
|
||||
}
|
||||
sctx.serviceRegister = cfg.ServiceRegister
|
||||
if cfg.EnablePprof {
|
||||
if cfg.EnablePprof || cfg.Debug {
|
||||
sctx.registerPprof()
|
||||
}
|
||||
if cfg.Debug {
|
||||
sctx.registerTrace()
|
||||
}
|
||||
sctxs[u.Host] = sctx
|
||||
}
|
||||
return sctxs, nil
|
||||
|
@ -32,6 +32,7 @@ import (
|
||||
"github.com/cockroachdb/cmux"
|
||||
gw "github.com/grpc-ecosystem/grpc-gateway/runtime"
|
||||
"golang.org/x/net/context"
|
||||
"golang.org/x/net/trace"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/credentials"
|
||||
)
|
||||
@ -199,22 +200,30 @@ func (sctx *serveCtx) createMux(gwmux *gw.ServeMux, handler http.Handler) *http.
|
||||
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
|
||||
func (sctx *serveCtx) registerUserHandler(s string, h http.Handler) {
|
||||
if sctx.userHandlers[s] != nil {
|
||||
plog.Warningf("path %s already registered by user handler", s)
|
||||
return
|
||||
}
|
||||
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"))
|
||||
sctx.userHandlers[s] = h
|
||||
}
|
||||
|
||||
func (sctx *serveCtx) registerPprof() {
|
||||
sctx.registerUserHandler(pprofPrefix+"/", http.HandlerFunc(pprof.Index))
|
||||
sctx.registerUserHandler(pprofPrefix+"/profile", http.HandlerFunc(pprof.Profile))
|
||||
sctx.registerUserHandler(pprofPrefix+"/symbol", http.HandlerFunc(pprof.Symbol))
|
||||
sctx.registerUserHandler(pprofPrefix+"/cmdline", http.HandlerFunc(pprof.Cmdline))
|
||||
sctx.registerUserHandler(pprofPrefix+"/trace", http.HandlerFunc(pprof.Trace))
|
||||
|
||||
sctx.registerUserHandler(pprofPrefix+"/heap", pprof.Handler("heap"))
|
||||
sctx.registerUserHandler(pprofPrefix+"/goroutine", pprof.Handler("goroutine"))
|
||||
sctx.registerUserHandler(pprofPrefix+"/threadcreate", pprof.Handler("threadcreate"))
|
||||
sctx.registerUserHandler(pprofPrefix+"/block", pprof.Handler("block"))
|
||||
}
|
||||
|
||||
func (sctx *serveCtx) registerTrace() {
|
||||
reqf := func(w http.ResponseWriter, r *http.Request) { trace.Render(w, r, true) }
|
||||
sctx.registerUserHandler("/debug/requests", http.HandlerFunc(reqf))
|
||||
evf := func(w http.ResponseWriter, r *http.Request) { trace.RenderEvents(w, r, true) }
|
||||
sctx.registerUserHandler("/debug/events", http.HandlerFunc(evf))
|
||||
}
|
||||
|
@ -382,6 +382,7 @@ func setupLogging(cfg *config) {
|
||||
capnslog.SetGlobalLogLevel(capnslog.INFO)
|
||||
if cfg.Debug {
|
||||
capnslog.SetGlobalLogLevel(capnslog.DEBUG)
|
||||
grpc.EnableTracing = true
|
||||
}
|
||||
if cfg.LogPkgLevels != "" {
|
||||
repoLog := capnslog.MustRepoLogger("github.com/coreos/etcd")
|
||||
|
Loading…
x
Reference in New Issue
Block a user