Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

server: register all status routes with mux.Router #51915

Merged
merged 1 commit into from
Mar 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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