From 102b72e8bf5b3142201a965f83651c8553c8950f Mon Sep 17 00:00:00 2001 From: Murat Kabilov Date: Tue, 25 Jul 2017 17:20:55 +0200 Subject: [PATCH] add pprof --- pkg/controller/controller.go | 5 +++-- pkg/controller/rest-server.go | 20 ++++++++++++++------ pkg/util/config/config.go | 2 +- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/pkg/controller/controller.go b/pkg/controller/controller.go index 5ab0e0fef..c46bf0bc1 100644 --- a/pkg/controller/controller.go +++ b/pkg/controller/controller.go @@ -171,11 +171,12 @@ func (c *Controller) initController() { func (c *Controller) Run(stopCh <-chan struct{}, wg *sync.WaitGroup) { c.initController() - wg.Add(4) + wg.Add(5) go c.runPodInformer(stopCh, wg) go c.runPostgresqlInformer(stopCh, wg) go c.podEventsDispatcher(stopCh, wg) go c.clusterResync(stopCh, wg) + go c.RunAPIServer(stopCh, wg) for i := range c.clusterEventQueues { wg.Add(1) @@ -195,4 +196,4 @@ func (c *Controller) runPostgresqlInformer(stopCh <-chan struct{}, wg *sync.Wait defer wg.Done() c.postgresqlInformer.Run(stopCh) -} \ No newline at end of file +} diff --git a/pkg/controller/rest-server.go b/pkg/controller/rest-server.go index 3f251e562..017a0ae0b 100644 --- a/pkg/controller/rest-server.go +++ b/pkg/controller/rest-server.go @@ -4,17 +4,24 @@ import ( "context" "fmt" "net/http" + "net/http/pprof" "sync" - "time" ) -func (c *Controller) restAPIServer(stopCh <-chan struct{}, wg *sync.WaitGroup) { +func (c *Controller) RunAPIServer(stopCh <-chan struct{}, wg *sync.WaitGroup) { defer wg.Done() - wg.Add(1) + + mux := http.NewServeMux() + + mux.Handle("/debug/pprof/", http.HandlerFunc(pprof.Index)) + mux.Handle("/debug/pprof/cmdline", http.HandlerFunc(pprof.Cmdline)) + mux.Handle("/debug/pprof/profile", http.HandlerFunc(pprof.Profile)) + mux.Handle("/debug/pprof/symbol", http.HandlerFunc(pprof.Symbol)) + mux.Handle("/debug/pprof/trace", http.HandlerFunc(pprof.Trace)) server := http.Server{ - Addr: fmt.Sprintf(":%d", c.opConfig.Port), - Handler: c, + Addr: fmt.Sprintf(":%d", c.opConfig.APIPort), + Handler: mux, } go func() { @@ -26,7 +33,8 @@ func (c *Controller) restAPIServer(stopCh <-chan struct{}, wg *sync.WaitGroup) { c.logger.Infof("listening on %s", server.Addr) <-stopCh - ctx, _ := context.WithTimeout(context.Background(), 5*time.Second) + + ctx, _ := context.WithCancel(context.Background()) server.Shutdown(ctx) } diff --git a/pkg/util/config/config.go b/pkg/util/config/config.go index 39e4d247e..db39a9e59 100644 --- a/pkg/util/config/config.go +++ b/pkg/util/config/config.go @@ -57,7 +57,7 @@ type Config struct { MasterDNSNameFormat stringTemplate `name:"master_dns_name_format" default:"{cluster}.{team}.{hostedzone}"` ReplicaDNSNameFormat stringTemplate `name:"replica_dns_name_format" default:"{cluster}-repl.{team}.{hostedzone}"` Workers uint32 `name:"workers" default:"4"` - Port uint32 `name:"port" default:"80"` + APIPort int `name:"api_port" default:"8080"` } func (c Config) MustMarshal() string {