Skip to content

Commit

Permalink
server: register all status routes with mux.Router (#51915)
Browse files Browse the repository at this point in the history
close #51914
  • Loading branch information
yzhan1 authored Mar 28, 2024
1 parent 9104291 commit 9855a55
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions pkg/server/http_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,14 +294,11 @@ func (s *Server) startHTTPServer() {
router.PathPrefix("/static/").Handler(http.StripPrefix("/static", http.FileServer(static.Data)))
}

serverMux := http.NewServeMux()
serverMux.Handle("/", router)

serverMux.HandleFunc("/debug/pprof/", pprof.Index)
serverMux.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
serverMux.HandleFunc("/debug/pprof/profile", cpuprofile.ProfileHTTPHandler)
serverMux.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
serverMux.HandleFunc("/debug/pprof/trace", pprof.Trace)
router.HandleFunc("/debug/pprof/", pprof.Index)
router.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
router.HandleFunc("/debug/pprof/profile", cpuprofile.ProfileHTTPHandler)
router.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
router.HandleFunc("/debug/pprof/trace", pprof.Trace)

ballast := newBallast(s.cfg.MaxBallastObjectSize)
{
Expand All @@ -310,9 +307,9 @@ func (s *Server) startHTTPServer() {
logutil.BgLogger().Error("set initial ballast object size failed", zap.Error(err))
}
}
serverMux.HandleFunc("/debug/ballast-object-sz", ballast.GenHTTPHandler())
router.HandleFunc("/debug/ballast-object-sz", ballast.GenHTTPHandler())

serverMux.HandleFunc("/debug/gogc", func(w http.ResponseWriter, r *http.Request) {
router.HandleFunc("/debug/gogc", func(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case http.MethodGet:
_, err := w.Write([]byte(strconv.Itoa(util.GetGOGC())))
Expand All @@ -337,7 +334,7 @@ func (s *Server) startHTTPServer() {
}
})

serverMux.HandleFunc("/debug/zip", func(w http.ResponseWriter, r *http.Request) {
router.HandleFunc("/debug/zip", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Disposition", fmt.Sprintf(`attachment; filename="tidb_debug"`+time.Now().Format("20060102150405")+".zip"))

// dump goroutine/heap/mutex
Expand Down Expand Up @@ -423,7 +420,7 @@ func (s *Server) startHTTPServer() {

// failpoint is enabled only for tests so we can add some http APIs here for tests.
failpoint.Inject("enableTestAPI", func() {
serverMux.HandleFunc("/fail/", func(w http.ResponseWriter, r *http.Request) {
router.HandleFunc("/fail/", func(w http.ResponseWriter, r *http.Request) {
r.URL.Path = strings.TrimPrefix(r.URL.Path, "/fail")
new(failpoint.HttpHandler).ServeHTTP(w, r)
})
Expand Down Expand Up @@ -467,6 +464,9 @@ func (s *Server) startHTTPServer() {
logutil.BgLogger().Error("write HTTP index page failed", zap.Error(err))
}
})

serverMux := http.NewServeMux()
serverMux.Handle("/", router)
s.startStatusServerAndRPCServer(serverMux)
}

Expand Down

0 comments on commit 9855a55

Please sign in to comment.