This repository has been archived by the owner on Jan 20, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable pprof/debug endpoints by default
Makes sure that debug endpoints are always available, which will aid in debugging demon issues. Wraps debug endpoints in the middleware chain so the can be blocked by authz. Signed-off-by: Brian Goff <cpuguy83@gmail.com>
- Loading branch information
Showing
5 changed files
with
76 additions
and
65 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package debug | ||
|
||
import ( | ||
"expvar" | ||
"net/http" | ||
"net/http/pprof" | ||
|
||
"github.com/docker/docker/api/server/httputils" | ||
"github.com/docker/docker/api/server/router" | ||
"golang.org/x/net/context" | ||
) | ||
|
||
// NewRouter creates a new debug router | ||
// The debug router holds endpoints for debug the daemon, such as those for pprof. | ||
func NewRouter() router.Router { | ||
r := &debugRouter{} | ||
r.initRoutes() | ||
return r | ||
} | ||
|
||
type debugRouter struct { | ||
routes []router.Route | ||
} | ||
|
||
func (r *debugRouter) initRoutes() { | ||
r.routes = []router.Route{ | ||
router.NewGetRoute("/vars", frameworkAdaptHandler(expvar.Handler())), | ||
router.NewGetRoute("/pprof/", frameworkAdaptHandlerFunc(pprof.Index)), | ||
router.NewGetRoute("/pprof/cmdline", frameworkAdaptHandlerFunc(pprof.Cmdline)), | ||
router.NewGetRoute("/pprof/profile", frameworkAdaptHandlerFunc(pprof.Profile)), | ||
router.NewGetRoute("/pprof/symbol", frameworkAdaptHandlerFunc(pprof.Symbol)), | ||
router.NewGetRoute("/pprof/trace", frameworkAdaptHandlerFunc(pprof.Trace)), | ||
router.NewGetRoute("/pprof/{name}", handlePprof), | ||
} | ||
} | ||
|
||
func (r *debugRouter) Routes() []router.Route { | ||
return r.routes | ||
} | ||
|
||
func frameworkAdaptHandler(handler http.Handler) httputils.APIFunc { | ||
return func(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { | ||
handler.ServeHTTP(w, r) | ||
return nil | ||
} | ||
} | ||
|
||
func frameworkAdaptHandlerFunc(handler http.HandlerFunc) httputils.APIFunc { | ||
return func(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { | ||
handler(w, r) | ||
return nil | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package debug | ||
|
||
import ( | ||
"net/http" | ||
"net/http/pprof" | ||
|
||
"golang.org/x/net/context" | ||
) | ||
|
||
func handlePprof(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { | ||
pprof.Handler(vars["name"]).ServeHTTP(w, r) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters