From c97633b1f58a81296834113299ea93b5e4a0958c Mon Sep 17 00:00:00 2001 From: gmarek Date: Mon, 14 Nov 2016 17:38:26 +0100 Subject: [PATCH] Add a flag allowing contention profiling of the API server --- hack/verify-flags/known-flags.txt | 1 + pkg/genericapiserver/config.go | 15 +++++++++++---- .../options/server_run_options.go | 4 ++++ 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/hack/verify-flags/known-flags.txt b/hack/verify-flags/known-flags.txt index f15485ab0b1..006d47c98b1 100644 --- a/hack/verify-flags/known-flags.txt +++ b/hack/verify-flags/known-flags.txt @@ -106,6 +106,7 @@ container-port container-runtime container-runtime-endpoint contain-pod-resources +contention-profiling controller-start-interval cors-allowed-origins cpu-cfs-quota diff --git a/pkg/genericapiserver/config.go b/pkg/genericapiserver/config.go index ba313d1a037..098a398c6dc 100644 --- a/pkg/genericapiserver/config.go +++ b/pkg/genericapiserver/config.go @@ -24,6 +24,7 @@ import ( "os" "path" "regexp" + goruntime "runtime" "sort" "strconv" "strings" @@ -78,10 +79,12 @@ type Config struct { // Allows api group versions or specific resources to be conditionally enabled/disabled. APIResourceConfigSource APIResourceConfigSource // allow downstream consumers to disable the index route - EnableIndex bool - EnableProfiling bool - EnableMetrics bool - EnableGarbageCollection bool + EnableIndex bool + EnableProfiling bool + // Requires generic profiling enabled + EnableContentionProfiling bool + EnableMetrics bool + EnableGarbageCollection bool Version *version.Info CorsAllowedOriginList []string @@ -285,6 +288,7 @@ func (c *Config) ApplyOptions(options *options.ServerRunOptions) *Config { c.CorsAllowedOriginList = options.CorsAllowedOriginList c.EnableGarbageCollection = options.EnableGarbageCollection c.EnableProfiling = options.EnableProfiling + c.EnableContentionProfiling = options.EnableContentionProfiling c.EnableSwaggerUI = options.EnableSwaggerUI c.ExternalAddress = options.ExternalHost c.MaxRequestsInFlight = options.MaxRequestsInFlight @@ -462,6 +466,9 @@ func (s *GenericAPIServer) installAPI(c *Config) { } if c.EnableProfiling { routes.Profiling{}.Install(s.HandlerContainer) + if c.EnableContentionProfiling { + goruntime.SetBlockProfileRate(1) + } } if c.EnableMetrics { if c.EnableProfiling { diff --git a/pkg/genericapiserver/options/server_run_options.go b/pkg/genericapiserver/options/server_run_options.go index 2047d914208..fd50bbc80ae 100644 --- a/pkg/genericapiserver/options/server_run_options.go +++ b/pkg/genericapiserver/options/server_run_options.go @@ -83,6 +83,7 @@ type ServerRunOptions struct { AuditLogMaxSize int EnableGarbageCollection bool EnableProfiling bool + EnableContentionProfiling bool EnableSwaggerUI bool EnableWatchCache bool EtcdServersOverrides []string @@ -139,6 +140,7 @@ func NewServerRunOptions() *ServerRunOptions { DeleteCollectionWorkers: 1, EnableGarbageCollection: true, EnableProfiling: true, + EnableContentionProfiling: false, EnableWatchCache: true, InsecureBindAddress: net.ParseIP("127.0.0.1"), InsecurePort: 8080, @@ -347,6 +349,8 @@ func (s *ServerRunOptions) AddUniversalFlags(fs *pflag.FlagSet) { fs.BoolVar(&s.EnableProfiling, "profiling", s.EnableProfiling, "Enable profiling via web interface host:port/debug/pprof/") + fs.BoolVar(&s.EnableContentionProfiling, "contention-profiling", s.EnableContentionProfiling, + "Enable contention profiling. Requires --profiling to be set to work.") fs.BoolVar(&s.EnableSwaggerUI, "enable-swagger-ui", s.EnableSwaggerUI, "Enables swagger ui on the apiserver at /swagger-ui")