Update to option enable profiling on the master daemon processes.

--profiling=true , default is false
This commit is contained in:
Timothy St. Clair 2015-03-13 10:44:11 -05:00
parent 53b25a7890
commit 7eebf674d4
7 changed files with 41 additions and 5 deletions

View File

@ -179,6 +179,7 @@ func startComponents(manifestURL string) (apiServerURL string) {
EtcdHelper: helper, EtcdHelper: helper,
KubeletClient: fakeKubeletClient{}, KubeletClient: fakeKubeletClient{},
EnableLogsSupport: false, EnableLogsSupport: false,
EnableProfiling: true,
APIPrefix: "/api", APIPrefix: "/api",
Authorizer: apiserver.NewAlwaysAllowAuthorizer(), Authorizer: apiserver.NewAlwaysAllowAuthorizer(),
AdmissionControl: admit.NewAlwaysAdmit(), AdmissionControl: admit.NewAlwaysAdmit(),

View File

@ -74,6 +74,7 @@ type APIServer struct {
KubeletConfig client.KubeletConfig KubeletConfig client.KubeletConfig
ClusterName string ClusterName string
SyncPodStatus bool SyncPodStatus bool
EnableProfiling bool
} }
// NewAPIServer creates a new APIServer object with default parameters // NewAPIServer creates a new APIServer object with default parameters
@ -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.") 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) client.BindKubeletClientConfigFlags(fs, &s.KubeletConfig)
fs.StringVar(&s.ClusterName, "cluster_name", s.ClusterName, "The instance prefix for the cluster") 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. // TODO: Longer term we should read this from some config store, rather than a flag.
@ -236,6 +238,7 @@ func (s *APIServer) Run(_ []string) error {
EnableLogsSupport: s.EnableLogsSupport, EnableLogsSupport: s.EnableLogsSupport,
EnableUISupport: true, EnableUISupport: true,
EnableSwaggerSupport: true, EnableSwaggerSupport: true,
EnableProfiling: s.EnableProfiling,
EnableIndex: true, EnableIndex: true,
APIPrefix: s.APIPrefix, APIPrefix: s.APIPrefix,
CorsAllowedOriginList: s.CorsAllowedOriginList, CorsAllowedOriginList: s.CorsAllowedOriginList,

View File

@ -22,6 +22,7 @@ package app
import ( import (
"net" "net"
"net/http" "net/http"
"net/http/pprof"
"strconv" "strconv"
"time" "time"
@ -62,6 +63,7 @@ type CMServer struct {
NodeMemory resource.Quantity NodeMemory resource.Quantity
KubeletConfig client.KubeletConfig KubeletConfig client.KubeletConfig
EnableProfiling bool
} }
// NewCMServer creates a new CMServer with a default config. // NewCMServer creates a new CMServer with a default config.
@ -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.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") fs.Var(resource.NewQuantityFlagValue(&s.NodeMemory), "node_memory", "The amount of memory (in bytes) provisioned on each node")
client.BindKubeletClientConfigFlags(fs, &s.KubeletConfig) client.BindKubeletClientConfigFlags(fs, &s.KubeletConfig)
fs.BoolVar(&s.EnableProfiling, "profiling", false, "Enable profiling via web interface host:port/debug/pprof/")
} }
func (s *CMServer) verifyMinionFlags() { func (s *CMServer) verifyMinionFlags() {
@ -138,7 +141,15 @@ func (s *CMServer) Run(_ []string) error {
glog.Fatalf("Invalid API configuration: %v", err) 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) endpoints := service.NewEndpointController(kubeClient)
go util.Forever(func() { endpoints.SyncServiceEndpoints() }, time.Second*10) go util.Forever(func() { endpoints.SyncServiceEndpoints() }, time.Second*10)

View File

@ -59,6 +59,7 @@ var (
nodeMilliCPU = flag.Int64("node_milli_cpu", 1000, "The amount of MilliCPU provisioned on each node") 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") 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") 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 { type delegateHandler struct {
@ -92,6 +93,7 @@ func runApiServer(cl *client.Client, etcdClient tools.EtcdClient, addr net.IP, p
}, },
EnableLogsSupport: false, EnableLogsSupport: false,
EnableSwaggerSupport: true, EnableSwaggerSupport: true,
EnableProfiling: *enableProfiling,
APIPrefix: "/api", APIPrefix: "/api",
Authorizer: apiserver.NewAlwaysAllowAuthorizer(), Authorizer: apiserver.NewAlwaysAllowAuthorizer(),

View File

@ -21,6 +21,7 @@ import (
"fmt" "fmt"
"net" "net"
"net/http" "net/http"
"net/http/pprof"
"net/url" "net/url"
rt "runtime" rt "runtime"
"strconv" "strconv"
@ -80,6 +81,7 @@ type Config struct {
EnableV1Beta3 bool EnableV1Beta3 bool
// allow downstream consumers to disable the index route // allow downstream consumers to disable the index route
EnableIndex bool EnableIndex bool
EnableProfiling bool
APIPrefix string APIPrefix string
CorsAllowedOriginList util.StringList CorsAllowedOriginList util.StringList
Authenticator authenticator.Request Authenticator authenticator.Request
@ -132,6 +134,7 @@ type Master struct {
enableLogsSupport bool enableLogsSupport bool
enableUISupport bool enableUISupport bool
enableSwaggerSupport bool enableSwaggerSupport bool
enableProfiling bool
apiPrefix string apiPrefix string
corsAllowedOriginList util.StringList corsAllowedOriginList util.StringList
authenticator authenticator.Request authenticator authenticator.Request
@ -286,6 +289,7 @@ func New(c *Config) *Master {
enableLogsSupport: c.EnableLogsSupport, enableLogsSupport: c.EnableLogsSupport,
enableUISupport: c.EnableUISupport, enableUISupport: c.EnableUISupport,
enableSwaggerSupport: c.EnableSwaggerSupport, enableSwaggerSupport: c.EnableSwaggerSupport,
enableProfiling: c.EnableProfiling,
apiPrefix: c.APIPrefix, apiPrefix: c.APIPrefix,
corsAllowedOriginList: c.CorsAllowedOriginList, corsAllowedOriginList: c.CorsAllowedOriginList,
authenticator: c.Authenticator, authenticator: c.Authenticator,
@ -454,8 +458,11 @@ func (m *Master) init(c *Config) {
ui.InstallSupport(m.muxHelper, m.enableSwaggerSupport) ui.InstallSupport(m.muxHelper, m.enableSwaggerSupport)
} }
// TODO: install runtime/pprof handler if c.EnableProfiling {
// See github.com/emicklei/go-restful/blob/master/examples/restful-cpuprofiler-service.go 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)) handler := http.Handler(m.mux.(*http.ServeMux))

View File

@ -22,6 +22,7 @@ import (
"io/ioutil" "io/ioutil"
"net" "net"
"net/http" "net/http"
"net/http/pprof"
"os" "os"
"strconv" "strconv"
@ -47,6 +48,7 @@ type SchedulerServer struct {
ClientConfig client.Config ClientConfig client.Config
AlgorithmProvider string AlgorithmProvider string
PolicyConfigFile string PolicyConfigFile string
EnableProfiling bool
} }
// NewSchedulerServer creates a new SchedulerServer with default parameters // NewSchedulerServer creates a new SchedulerServer with default parameters
@ -66,6 +68,7 @@ func (s *SchedulerServer) AddFlags(fs *pflag.FlagSet) {
client.BindClientConfigFlags(fs, &s.ClientConfig) client.BindClientConfigFlags(fs, &s.ClientConfig)
fs.StringVar(&s.AlgorithmProvider, "algorithm_provider", s.AlgorithmProvider, "The scheduling algorithm provider to use") 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.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. // Run runs the specified SchedulerServer. This should never exit.
@ -77,7 +80,15 @@ func (s *SchedulerServer) Run(_ []string) error {
record.StartRecording(kubeClient.Events("")) 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) configFactory := factory.NewConfigFactory(kubeClient)
config, err := s.createConfig(configFactory) config, err := s.createConfig(configFactory)

View File

@ -54,6 +54,7 @@ func TestClient(t *testing.T) {
EtcdHelper: helper, EtcdHelper: helper,
KubeletClient: client.FakeKubeletClient{}, KubeletClient: client.FakeKubeletClient{},
EnableLogsSupport: false, EnableLogsSupport: false,
EnableProfiling: true,
EnableUISupport: false, EnableUISupport: false,
APIPrefix: "/api", APIPrefix: "/api",
Authorizer: apiserver.NewAlwaysAllowAuthorizer(), Authorizer: apiserver.NewAlwaysAllowAuthorizer(),