@@ -466,6 +466,14 @@ func buildTelemetryServer(registry prometheus.Gatherer, authFilter bool, kubeCon
466466 // Add metricsPath
467467 metricsHandler := promhttp .HandlerFor (registry , promhttp.HandlerOpts {ErrorLog : sLogger })
468468
469+ pprofHandlers := map [string ]http.Handler {
470+ "/debug/pprof/" : http .HandlerFunc (pprof .Index ),
471+ "/debug/pprof/cmdline" : http .HandlerFunc (pprof .Cmdline ),
472+ "/debug/pprof/profile" : http .HandlerFunc (pprof .Profile ),
473+ "/debug/pprof/symbol" : http .HandlerFunc (pprof .Symbol ),
474+ "/debug/pprof/trace" : http .HandlerFunc (pprof .Trace ),
475+ }
476+
469477 // Add Authentication/Authorization via Kubernetes API
470478 if authFilter {
471479 client , err := rest .HTTPClientFor (kubeConfig )
@@ -482,9 +490,23 @@ func buildTelemetryServer(registry prometheus.Gatherer, authFilter bool, kubeCon
482490 if err != nil {
483491 klog .ErrorS (err , "failed to apply metrics filter" )
484492 }
493+
494+ for path , h := range pprofHandlers {
495+ protected , err := metricsFilter (klog .Background (), h )
496+ if err != nil {
497+ klog .ErrorS (err , "failed to apply auth filter to pprof handler" , "path" , path )
498+ delete (pprofHandlers , path )
499+ continue
500+ }
501+ pprofHandlers [path ] = protected
502+ }
485503 }
486504 mux .Handle (metricsPath , metricsHandler )
487505
506+ for path , h := range pprofHandlers {
507+ mux .Handle (path , h )
508+ }
509+
488510 // Add readyzPath
489511 mux .Handle (readyzPath , http .HandlerFunc (func (w http.ResponseWriter , _ * http.Request ) {
490512 count , err := util .GatherAndCount (registry )
@@ -537,13 +559,6 @@ func handleClusterDelegationForProber(client kubernetes.Interface, probeType str
537559func buildMetricsServer (m * metricshandler.MetricsHandler , durationObserver prometheus.ObserverVec , client kubernetes.Interface , authFilter bool , kubeConfig * rest.Config ) * http.ServeMux {
538560 mux := http .NewServeMux ()
539561
540- // TODO: This doesn't belong into serveMetrics
541- mux .Handle ("/debug/pprof/" , http .HandlerFunc (pprof .Index ))
542- mux .Handle ("/debug/pprof/cmdline" , http .HandlerFunc (pprof .Cmdline ))
543- mux .Handle ("/debug/pprof/profile" , http .HandlerFunc (pprof .Profile ))
544- mux .Handle ("/debug/pprof/symbol" , http .HandlerFunc (pprof .Symbol ))
545- mux .Handle ("/debug/pprof/trace" , http .HandlerFunc (pprof .Trace ))
546-
547562 // Add metricsPath
548563 metricsHandler := promhttp .InstrumentHandlerDuration (durationObserver , m )
549564
0 commit comments