профиль kubectl с помощью pprof

В исходном коде kubernetes есть блок кода, который обрабатывает часть профилирования, но я не могу получить доступ к конечным точкам:

in kubernetes/pkgs/kubelet/server/stats/server.go

func (s *Server) InstallProfilingHandler(enableProfilingLogHandler bool, enableContentionProfiling bool) {
    s.addMetricsBucketMatcher("debug")
    if !enableProfilingLogHandler {
        s.restfulCont.Handle(pprofBasePath, getHandlerForDisabledEndpoint("profiling endpoint is disabled."))
        return
    }

    handlePprofEndpoint := func(req *restful.Request, resp *restful.Response) {
        name := strings.TrimPrefix(req.Request.URL.Path, pprofBasePath)
        switch name {
        case "profile":
            pprof.Profile(resp, req.Request)
        case "symbol":
            pprof.Symbol(resp, req.Request)
        case "cmdline":
            pprof.Cmdline(resp, req.Request)
        case "trace":
            pprof.Trace(resp, req.Request)
        default:
            pprof.Index(resp, req.Request)
        }
    }

    // Setup pprof handlers.
    ws := new(restful.WebService).Path(pprofBasePath)
    ws.Route(ws.GET("/{subpath:*}").To(handlePprofEndpoint)).Doc("pprof endpoint")
    s.restfulCont.Add(ws)

    if enableContentionProfiling {
        goruntime.SetBlockProfileRate(1)
    }
}

Я не знаю порт, используемый инструментом pprof, но я нашел его с помощью:

controller-0:/home/sysadmin/go/bin# netstat -atlpn | grep kubelet
tcp        0      0 127.0.0.1:10248         0.0.0.0:*               LISTEN      184856/kubelet      
tcp        0      0 192.168.206.2:49720     192.168.206.1:6443      ESTABLISHED 184856/kubelet      
tcp6       0      0 :::10250                :::*                    LISTEN      184856/kubelet 

Затем я попытался

controller-0:/home/sysadmin/go/bin# ./go tool pprof  http://localhost:6443/debug/pprof/mutex
Fetching profile over HTTP from http://localhost:6443/debug/pprof/mutex
http://localhost:6443/debug/pprof/mutex: server response: 400 Bad Request
failed to fetch any source profiles

Есть ли кто-нибудь, кто знает, что я должен попытаться получить доступ к конечным точкам pprof? или как попробовать другой подход к профилированию процесса kubelet?


person Daniel Safta    schedule 11.06.2021    source источник


Ответы (1)


Пытаться:

$ kubectl proxy &
Starting to serve on 127.0.0.1:8001
$ go tool pprof "http://localhost:8001/api/v1/nodes/${NODE}/proxy/debug/pprof/profile"

Когда вы запускаете kubectl proxy, все запросы к http://localhost:8001/api/v1/nodes/${NODE}/proxy/ переходят к kubelet, работающему на ${NODE}. Вы можете добавить любой путь, который вы хотите, и это. Пусть это будет /debug/pprof/profile или debug/pprof/heap или что угодно.

person Matt    schedule 11.06.2021