From c4830aa4e017c5c892b1da8b6fcb06e9c0b2d348 Mon Sep 17 00:00:00 2001 From: Murali Reddy Date: Tue, 12 Dec 2017 12:06:38 +0530 Subject: [PATCH] enable Pprof with option --enable-pprof (#245) * rename to connectExternalBGPPeers * enable pprof for debug purpose --- app/controllers/network_routes_controller.go | 4 ++-- app/options/options.go | 3 +++ kube-router.go | 10 +++++++++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/app/controllers/network_routes_controller.go b/app/controllers/network_routes_controller.go index cc780434cf..be104a6239 100644 --- a/app/controllers/network_routes_controller.go +++ b/app/controllers/network_routes_controller.go @@ -514,7 +514,7 @@ func newGlobalPeers(ips []net.IP, asns []uint32, passwords []string) ( return peers, nil } -func connectToPeers(server *gobgp.BgpServer, peerConfigs []*config.NeighborConfig, bgpGracefulRestart bool, peerMultihopTtl uint8) error { +func connectToExternalBGPPeers(server *gobgp.BgpServer, peerConfigs []*config.NeighborConfig, bgpGracefulRestart bool, peerMultihopTtl uint8) error { for _, peerConfig := range peerConfigs { n := &config.Neighbor{ Config: *peerConfig, @@ -1332,7 +1332,7 @@ func (nrc *NetworkRoutingController) startBgpServer() error { } if len(nrc.globalPeerRouters) != 0 { - err := connectToPeers(nrc.bgpServer, nrc.globalPeerRouters, nrc.bgpGracefulRestart, nrc.peerMultihopTtl) + err := connectToExternalBGPPeers(nrc.bgpServer, nrc.globalPeerRouters, nrc.bgpGracefulRestart, nrc.peerMultihopTtl) if err != nil { nrc.bgpServer.Stop() return fmt.Errorf("Failed to peer with Global Peer Router(s): %s", diff --git a/app/options/options.go b/app/options/options.go index 0814ff5687..22ab2f7efd 100755 --- a/app/options/options.go +++ b/app/options/options.go @@ -36,6 +36,7 @@ type KubeRouterConfig struct { NodePortBindOnAllIp bool EnableOverlay bool PeerPasswords []string + EnablePprof bool // FullMeshPassword string } @@ -106,6 +107,8 @@ func (s *KubeRouterConfig) AddFlags(fs *pflag.FlagSet) { "When set to false no tunneling is used and routing infrastrcture is expected to route traffic for pod-to-pod networking across nodes in different subnets") fs.StringSliceVar(&s.PeerPasswords, "peer-router-passwords", s.PeerPasswords, "Password for authenticating against the BGP peer defined with \"--peer-router-ips\".") + fs.BoolVar(&s.EnablePprof, "enable-pprof", false, + "Enables pprof for debugging performance and memory leak issues.") // fs.StringVar(&s.FullMeshPassword, "nodes-full-mesh-password", s.FullMeshPassword, // "Password that cluster-node BGP servers will use to authenticate one another when \"--nodes-full-mesh\" is set.") } diff --git a/kube-router.go b/kube-router.go index 0330270cfb..90c5e4a5f6 100644 --- a/kube-router.go +++ b/kube-router.go @@ -1,10 +1,12 @@ package main import ( + "flag" "fmt" + "net/http" "os" - "flag" + _ "net/http/pprof" "github.com/cloudnativelabs/kube-router/app" "github.com/cloudnativelabs/kube-router/app/options" @@ -44,6 +46,12 @@ func main() { os.Exit(1) } + if config.EnablePprof { + go func() { + fmt.Fprintf(os.Stdout, http.ListenAndServe("0.0.0.0:6060", nil).Error()) + }() + } + err = kubeRouter.Run() if err != nil { fmt.Fprintf(os.Stderr, "Failed to run kube-router: %v\n", err)