@@ -58,6 +58,7 @@ import (
5858 "golang.org/x/oauth2"
5959 "google.golang.org/grpc"
6060 "google.golang.org/grpc/credentials/insecure"
61+ "google.golang.org/grpc/metadata"
6162 "google.golang.org/grpc/reflection"
6263)
6364
@@ -275,7 +276,7 @@ func (o *serverOption) runE(cmd *cobra.Command, args []string) (err error) {
275276 promhttp .HandlerFor (reg , promhttp.HandlerOpts {Registry : reg }).ServeHTTP (w , r )
276277 })
277278
278- debugHandler (mux )
279+ debugHandler (mux , remoteServer )
279280 o .httpServer .WithHandler (mux )
280281 log .Printf ("HTTP server listening at %v" , httplis .Addr ())
281282 log .Printf ("Server is running." )
@@ -346,9 +347,32 @@ func frontEndHandlerWithLocation(consolePath string) func(w http.ResponseWriter,
346347 }
347348}
348349
349- func debugHandler (mux * runtime.ServeMux ) {
350+ func debugHandler (mux * runtime.ServeMux , remoteServer server. RunnerServer ) {
350351 mux .HandlePath (http .MethodGet , "/debug/pprof/{sub}" , func (w http.ResponseWriter , r * http.Request , pathParams map [string ]string ) {
351- switch sub := pathParams ["sub" ]; sub {
352+ sub := pathParams ["sub" ]
353+ extName := r .URL .Query ().Get ("name" )
354+ if extName != "" && remoteServer != nil {
355+ log .Println ("get pprof of extension:" , extName )
356+
357+ ctx := metadata .NewIncomingContext (r .Context (), metadata .New (map [string ]string {
358+ server .HeaderKeyStoreName : extName ,
359+ }))
360+
361+ data , err := remoteServer .PProf (ctx , & server.PProfRequest {
362+ Name : sub ,
363+ })
364+ if err == nil {
365+ w .Header ().Set ("Content-Type" , "application/octet-stream" )
366+ w .Write (data .Data )
367+ } else {
368+ w .WriteHeader (http .StatusBadRequest )
369+ w .Write ([]byte (err .Error ()))
370+ }
371+
372+ return
373+ }
374+
375+ switch sub {
352376 case "cmdline" :
353377 pprof .Cmdline (w , r )
354378 case "profile" :
0 commit comments