Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to enable profiling on the master daemon processes. #5438

Merged
merged 1 commit into from
Mar 13, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmd/integration/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ func startComponents(manifestURL string) (apiServerURL string) {
EtcdHelper: helper,
KubeletClient: fakeKubeletClient{},
EnableLogsSupport: false,
EnableProfiling: true,
APIPrefix: "/api",
Authorizer: apiserver.NewAlwaysAllowAuthorizer(),
AdmissionControl: admit.NewAlwaysAdmit(),
Expand Down
3 changes: 3 additions & 0 deletions cmd/kube-apiserver/app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ type APIServer struct {
KubeletConfig client.KubeletConfig
ClusterName string
SyncPodStatus bool
EnableProfiling bool
}

// NewAPIServer creates a new APIServer object with default parameters
Expand Down Expand Up @@ -152,6 +153,7 @@ func (s *APIServer) AddFlags(fs *pflag.FlagSet) {
fs.Var(&s.RuntimeConfig, "runtime_config", "A set of key=value pairs that describe runtime configuration that may be passed to the apiserver.")
client.BindKubeletClientConfigFlags(fs, &s.KubeletConfig)
fs.StringVar(&s.ClusterName, "cluster_name", s.ClusterName, "The instance prefix for the cluster")
fs.BoolVar(&s.EnableProfiling, "profiling", false, "Enable profiling via web interface host:port/debug/pprof/")
}

// TODO: Longer term we should read this from some config store, rather than a flag.
Expand Down Expand Up @@ -236,6 +238,7 @@ func (s *APIServer) Run(_ []string) error {
EnableLogsSupport: s.EnableLogsSupport,
EnableUISupport: true,
EnableSwaggerSupport: true,
EnableProfiling: s.EnableProfiling,
EnableIndex: true,
APIPrefix: s.APIPrefix,
CorsAllowedOriginList: s.CorsAllowedOriginList,
Expand Down
15 changes: 13 additions & 2 deletions cmd/kube-controller-manager/app/controllermanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ package app
import (
"net"
"net/http"
"net/http/pprof"
"strconv"
"time"

Expand Down Expand Up @@ -61,7 +62,8 @@ type CMServer struct {
NodeMilliCPU int64
NodeMemory resource.Quantity

KubeletConfig client.KubeletConfig
KubeletConfig client.KubeletConfig
EnableProfiling bool
}

// NewCMServer creates a new CMServer with a default config.
Expand Down Expand Up @@ -108,6 +110,7 @@ func (s *CMServer) AddFlags(fs *pflag.FlagSet) {
fs.Int64Var(&s.NodeMilliCPU, "node_milli_cpu", s.NodeMilliCPU, "The amount of MilliCPU provisioned on each node")
fs.Var(resource.NewQuantityFlagValue(&s.NodeMemory), "node_memory", "The amount of memory (in bytes) provisioned on each node")
client.BindKubeletClientConfigFlags(fs, &s.KubeletConfig)
fs.BoolVar(&s.EnableProfiling, "profiling", false, "Enable profiling via web interface host:port/debug/pprof/")
}

func (s *CMServer) verifyMinionFlags() {
Expand Down Expand Up @@ -138,7 +141,15 @@ func (s *CMServer) Run(_ []string) error {
glog.Fatalf("Invalid API configuration: %v", err)
}

go http.ListenAndServe(net.JoinHostPort(s.Address.String(), strconv.Itoa(s.Port)), nil)
go func() {
if s.EnableProfiling {
mux := http.NewServeMux()
mux.HandleFunc("/debug/pprof/", pprof.Index)
mux.HandleFunc("/debug/pprof/profile", pprof.Profile)
mux.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
}
http.ListenAndServe(net.JoinHostPort(s.Address.String(), strconv.Itoa(s.Port)), nil)
}()

endpoints := service.NewEndpointController(kubeClient)
go util.Forever(func() { endpoints.SyncServiceEndpoints() }, time.Second*10)
Expand Down
2 changes: 2 additions & 0 deletions cmd/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ var (
nodeMilliCPU = flag.Int64("node_milli_cpu", 1000, "The amount of MilliCPU provisioned on each node")
nodeMemory = flag.Int64("node_memory", 3*1024*1024*1024, "The amount of memory (in bytes) provisioned on each node")
masterServiceNamespace = flag.String("master_service_namespace", api.NamespaceDefault, "The namespace from which the kubernetes master services should be injected into pods")
enableProfiling = flag.Bool("profiling", false, "Enable profiling via web interface host:port/debug/pprof/")
)

type delegateHandler struct {
Expand Down Expand Up @@ -92,6 +93,7 @@ func runApiServer(cl *client.Client, etcdClient tools.EtcdClient, addr net.IP, p
},
EnableLogsSupport: false,
EnableSwaggerSupport: true,
EnableProfiling: *enableProfiling,
APIPrefix: "/api",
Authorizer: apiserver.NewAlwaysAllowAuthorizer(),

Expand Down
11 changes: 9 additions & 2 deletions pkg/master/master.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"fmt"
"net"
"net/http"
"net/http/pprof"
"net/url"
rt "runtime"
"strconv"
Expand Down Expand Up @@ -80,6 +81,7 @@ type Config struct {
EnableV1Beta3 bool
// allow downstream consumers to disable the index route
EnableIndex bool
EnableProfiling bool
APIPrefix string
CorsAllowedOriginList util.StringList
Authenticator authenticator.Request
Expand Down Expand Up @@ -132,6 +134,7 @@ type Master struct {
enableLogsSupport bool
enableUISupport bool
enableSwaggerSupport bool
enableProfiling bool
apiPrefix string
corsAllowedOriginList util.StringList
authenticator authenticator.Request
Expand Down Expand Up @@ -286,6 +289,7 @@ func New(c *Config) *Master {
enableLogsSupport: c.EnableLogsSupport,
enableUISupport: c.EnableUISupport,
enableSwaggerSupport: c.EnableSwaggerSupport,
enableProfiling: c.EnableProfiling,
apiPrefix: c.APIPrefix,
corsAllowedOriginList: c.CorsAllowedOriginList,
authenticator: c.Authenticator,
Expand Down Expand Up @@ -454,8 +458,11 @@ func (m *Master) init(c *Config) {
ui.InstallSupport(m.muxHelper, m.enableSwaggerSupport)
}

// TODO: install runtime/pprof handler
// See github.com/emicklei/go-restful/blob/master/examples/restful-cpuprofiler-service.go
if c.EnableProfiling {
m.mux.HandleFunc("/debug/pprof/", pprof.Index)
m.mux.HandleFunc("/debug/pprof/profile", pprof.Profile)
m.mux.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
}

handler := http.Handler(m.mux.(*http.ServeMux))

Expand Down
13 changes: 12 additions & 1 deletion plugin/cmd/kube-scheduler/app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"io/ioutil"
"net"
"net/http"
"net/http/pprof"
"os"
"strconv"

Expand All @@ -47,6 +48,7 @@ type SchedulerServer struct {
ClientConfig client.Config
AlgorithmProvider string
PolicyConfigFile string
EnableProfiling bool
}

// NewSchedulerServer creates a new SchedulerServer with default parameters
Expand All @@ -66,6 +68,7 @@ func (s *SchedulerServer) AddFlags(fs *pflag.FlagSet) {
client.BindClientConfigFlags(fs, &s.ClientConfig)
fs.StringVar(&s.AlgorithmProvider, "algorithm_provider", s.AlgorithmProvider, "The scheduling algorithm provider to use")
fs.StringVar(&s.PolicyConfigFile, "policy_config_file", s.PolicyConfigFile, "File with scheduler policy configuration")
fs.BoolVar(&s.EnableProfiling, "profiling", false, "Enable profiling via web interface host:port/debug/pprof/")
}

// Run runs the specified SchedulerServer. This should never exit.
Expand All @@ -77,7 +80,15 @@ func (s *SchedulerServer) Run(_ []string) error {

record.StartRecording(kubeClient.Events(""))

go http.ListenAndServe(net.JoinHostPort(s.Address.String(), strconv.Itoa(s.Port)), nil)
go func() {
if s.EnableProfiling {
mux := http.NewServeMux()
mux.HandleFunc("/debug/pprof/", pprof.Index)
mux.HandleFunc("/debug/pprof/profile", pprof.Profile)
mux.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
}
http.ListenAndServe(net.JoinHostPort(s.Address.String(), strconv.Itoa(s.Port)), nil)
}()

configFactory := factory.NewConfigFactory(kubeClient)
config, err := s.createConfig(configFactory)
Expand Down
1 change: 1 addition & 0 deletions test/integration/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ func TestClient(t *testing.T) {
EtcdHelper: helper,
KubeletClient: client.FakeKubeletClient{},
EnableLogsSupport: false,
EnableProfiling: true,
EnableUISupport: false,
APIPrefix: "/api",
Authorizer: apiserver.NewAlwaysAllowAuthorizer(),
Expand Down