API Server: Enhanced profiling with godeltaprof (#88939)

This commit is contained in:
Marcus Efraimsson
2024-06-07 19:39:45 +02:00
committed by GitHub
parent 63e9969c1b
commit 4a97ff45fe
2 changed files with 50 additions and 0 deletions

View File

@@ -7,10 +7,12 @@ import (
"net"
"path"
"github.com/grafana/pyroscope-go/godeltaprof/http/pprof"
"github.com/spf13/pflag"
"k8s.io/apimachinery/pkg/runtime/schema"
utilerrors "k8s.io/apimachinery/pkg/util/errors"
genericapiserver "k8s.io/apiserver/pkg/server"
"k8s.io/apiserver/pkg/server/mux"
"k8s.io/client-go/tools/clientcmd"
netutils "k8s.io/utils/net"
@@ -178,5 +180,19 @@ func (o *APIServerOptions) RunAPIServer(config *genericapiserver.RecommendedConf
}
}
if config.EnableProfiling {
deltaProfiling{}.Install(server.Handler.NonGoRestfulMux)
}
return server.PrepareRun().Run(stopCh)
}
// deltaProfiling adds godeltapprof handlers for pprof under /debug/pprof.
type deltaProfiling struct{}
// Install register godeltapprof handlers to the given mux.
func (d deltaProfiling) Install(c *mux.PathRecorderMux) {
c.UnlistedHandleFunc("/debug/pprof/delta_heap", pprof.Heap)
c.UnlistedHandleFunc("/debug/pprof/delta_block", pprof.Block)
c.UnlistedHandleFunc("/debug/pprof/delta_mutex", pprof.Mutex)
}