@@ -58,6 +58,7 @@ import (
58
58
"golang.org/x/oauth2"
59
59
"google.golang.org/grpc"
60
60
"google.golang.org/grpc/credentials/insecure"
61
+ "google.golang.org/grpc/metadata"
61
62
"google.golang.org/grpc/reflection"
62
63
)
63
64
@@ -275,7 +276,7 @@ func (o *serverOption) runE(cmd *cobra.Command, args []string) (err error) {
275
276
promhttp .HandlerFor (reg , promhttp.HandlerOpts {Registry : reg }).ServeHTTP (w , r )
276
277
})
277
278
278
- debugHandler (mux )
279
+ debugHandler (mux , remoteServer )
279
280
o .httpServer .WithHandler (mux )
280
281
log .Printf ("HTTP server listening at %v" , httplis .Addr ())
281
282
log .Printf ("Server is running." )
@@ -346,9 +347,32 @@ func frontEndHandlerWithLocation(consolePath string) func(w http.ResponseWriter,
346
347
}
347
348
}
348
349
349
- func debugHandler (mux * runtime.ServeMux ) {
350
+ func debugHandler (mux * runtime.ServeMux , remoteServer server. RunnerServer ) {
350
351
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 {
352
376
case "cmdline" :
353
377
pprof .Cmdline (w , r )
354
378
case "profile" :
0 commit comments