From 981f2397815248e12663b01d6cc6d6d963012c95 Mon Sep 17 00:00:00 2001 From: "hongjian.sun" Date: Mon, 6 Aug 2018 19:35:01 +0800 Subject: [PATCH] fix apiserver pprof redirect bug --- .../src/k8s.io/apiserver/pkg/server/routes/profiling.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/staging/src/k8s.io/apiserver/pkg/server/routes/profiling.go b/staging/src/k8s.io/apiserver/pkg/server/routes/profiling.go index f09a9669571..b57d590f523 100644 --- a/staging/src/k8s.io/apiserver/pkg/server/routes/profiling.go +++ b/staging/src/k8s.io/apiserver/pkg/server/routes/profiling.go @@ -28,9 +28,16 @@ type Profiling struct{} // Install adds the Profiling webservice to the given mux. func (d Profiling) Install(c *mux.PathRecorderMux) { - c.UnlistedHandle("/debug/pprof", http.HandlerFunc(pprof.Index)) + c.UnlistedHandleFunc("/debug/pprof", redirectTo("/debug/pprof/")) c.UnlistedHandlePrefix("/debug/pprof/", http.HandlerFunc(pprof.Index)) c.UnlistedHandleFunc("/debug/pprof/profile", pprof.Profile) c.UnlistedHandleFunc("/debug/pprof/symbol", pprof.Symbol) c.UnlistedHandleFunc("/debug/pprof/trace", pprof.Trace) } + +// redirectTo redirects request to a certain destination. +func redirectTo(to string) func(http.ResponseWriter, *http.Request) { + return func(rw http.ResponseWriter, req *http.Request) { + http.Redirect(rw, req, to, http.StatusFound) + } +}