@@ -147,6 +147,9 @@ var _ = Describe("manger.Manager", func() {
147147 ReadinessEndpointName : "/readyz" ,
148148 LivenessEndpointName : "/livez" ,
149149 },
150+ Pprof : v1alpha1.ControllerPprof {
151+ BindAddress : ":6080" ,
152+ },
150153 Webhook : v1alpha1.ControllerWebhook {
151154 Port : & port ,
152155 Host : "localhost" ,
@@ -171,6 +174,7 @@ var _ = Describe("manger.Manager", func() {
171174 Expect (m .HealthProbeBindAddress ).To (Equal ("6060" ))
172175 Expect (m .ReadinessEndpointName ).To (Equal ("/readyz" ))
173176 Expect (m .LivenessEndpointName ).To (Equal ("/livez" ))
177+ Expect (m .PprofBindAddress ).To (Equal (":6080" ))
174178 Expect (m .Port ).To (Equal (port ))
175179 Expect (m .Host ).To (Equal ("localhost" ))
176180 Expect (m .CertDir ).To (Equal ("/certs" ))
@@ -203,6 +207,9 @@ var _ = Describe("manger.Manager", func() {
203207 ReadinessEndpointName : "/readyz" ,
204208 LivenessEndpointName : "/livez" ,
205209 },
210+ Pprof : v1alpha1.ControllerPprof {
211+ BindAddress : ":6080" ,
212+ },
206213 Webhook : v1alpha1.ControllerWebhook {
207214 Port : & port ,
208215 Host : "localhost" ,
@@ -225,6 +232,7 @@ var _ = Describe("manger.Manager", func() {
225232 HealthProbeBindAddress : "5000" ,
226233 ReadinessEndpointName : "/readiness" ,
227234 LivenessEndpointName : "/liveness" ,
235+ PprofBindAddress : ":6000" ,
228236 Port : 8080 ,
229237 Host : "example.com" ,
230238 CertDir : "/pki" ,
@@ -244,6 +252,7 @@ var _ = Describe("manger.Manager", func() {
244252 Expect (m .HealthProbeBindAddress ).To (Equal ("5000" ))
245253 Expect (m .ReadinessEndpointName ).To (Equal ("/readiness" ))
246254 Expect (m .LivenessEndpointName ).To (Equal ("/liveness" ))
255+ Expect (m .PprofBindAddress ).To (Equal (":6000" ))
247256 Expect (m .Port ).To (Equal (8080 ))
248257 Expect (m .Host ).To (Equal ("example.com" ))
249258 Expect (m .CertDir ).To (Equal ("/pki" ))
@@ -282,6 +291,7 @@ var _ = Describe("manger.Manager", func() {
282291 LeaderElectionID : "test-leader-election-id-2" ,
283292 HealthProbeBindAddress : "0" ,
284293 MetricsBindAddress : "0" ,
294+ PprofBindAddress : "0" ,
285295 })
286296 Expect (err ).To (BeNil ())
287297
@@ -327,6 +337,7 @@ var _ = Describe("manger.Manager", func() {
327337 LeaderElectionID : "test-leader-election-id-3" ,
328338 HealthProbeBindAddress : "0" ,
329339 MetricsBindAddress : "0" ,
340+ PprofBindAddress : "0" ,
330341 })
331342 Expect (err ).To (BeNil ())
332343
@@ -361,6 +372,7 @@ var _ = Describe("manger.Manager", func() {
361372 },
362373 HealthProbeBindAddress : "0" ,
363374 MetricsBindAddress : "0" ,
375+ PprofBindAddress : "0" ,
364376 })
365377 Expect (err ).ToNot (HaveOccurred ())
366378 Expect (m1 ).ToNot (BeNil ())
@@ -381,6 +393,7 @@ var _ = Describe("manger.Manager", func() {
381393 },
382394 HealthProbeBindAddress : "0" ,
383395 MetricsBindAddress : "0" ,
396+ PprofBindAddress : "0" ,
384397 })
385398 Expect (err ).ToNot (HaveOccurred ())
386399 Expect (m2 ).ToNot (BeNil ())
@@ -1395,6 +1408,94 @@ var _ = Describe("manger.Manager", func() {
13951408 })
13961409 })
13971410
1411+ Context ("should start serving pprof" , func () {
1412+ var listener net.Listener
1413+ var opts Options
1414+
1415+ BeforeEach (func () {
1416+ listener = nil
1417+ opts = Options {
1418+ newPprofListener : func (addr string ) (net.Listener , error ) {
1419+ var err error
1420+ listener , err = defaultPprofListener (addr )
1421+ return listener , err
1422+ },
1423+ }
1424+ })
1425+
1426+ AfterEach (func () {
1427+ if listener != nil {
1428+ listener .Close ()
1429+ }
1430+ })
1431+
1432+ It ("should stop serving pprof when stop is called" , func () {
1433+ opts .PprofBindAddress = ":0"
1434+ m , err := New (cfg , opts )
1435+ Expect (err ).NotTo (HaveOccurred ())
1436+
1437+ ctx , cancel := context .WithCancel (context .Background ())
1438+ go func () {
1439+ defer GinkgoRecover ()
1440+ Expect (m .Start (ctx )).NotTo (HaveOccurred ())
1441+ }()
1442+ <- m .Elected ()
1443+
1444+ // Check the pprof started
1445+ endpoint := fmt .Sprintf ("http://%s" , listener .Addr ().String ())
1446+ _ , err = http .Get (endpoint )
1447+ Expect (err ).NotTo (HaveOccurred ())
1448+
1449+ // Shutdown the server
1450+ cancel ()
1451+
1452+ // Expect the pprof server to shutdown
1453+ Eventually (func () error {
1454+ _ , err = http .Get (endpoint )
1455+ return err
1456+ }).ShouldNot (Succeed ())
1457+ })
1458+
1459+ It ("should serve pprof endpoints" , func () {
1460+ opts .PprofBindAddress = ":0"
1461+ m , err := New (cfg , opts )
1462+ Expect (err ).NotTo (HaveOccurred ())
1463+
1464+ ctx , cancel := context .WithCancel (context .Background ())
1465+ defer cancel ()
1466+ go func () {
1467+ defer GinkgoRecover ()
1468+ Expect (m .Start (ctx )).NotTo (HaveOccurred ())
1469+ }()
1470+ <- m .Elected ()
1471+
1472+ pprofIndexEndpoint := fmt .Sprintf ("http://%s/debug/pprof/" , listener .Addr ().String ())
1473+ resp , err := http .Get (pprofIndexEndpoint )
1474+ Expect (err ).NotTo (HaveOccurred ())
1475+ Expect (resp .StatusCode ).To (Equal (200 ))
1476+
1477+ pprofCmdlineEndpoint := fmt .Sprintf ("http://%s/debug/pprof/cmdline" , listener .Addr ().String ())
1478+ resp , err = http .Get (pprofCmdlineEndpoint )
1479+ Expect (err ).NotTo (HaveOccurred ())
1480+ Expect (resp .StatusCode ).To (Equal (200 ))
1481+
1482+ pprofProfileEndpoint := fmt .Sprintf ("http://%s/debug/pprof/profile" , listener .Addr ().String ())
1483+ resp , err = http .Get (pprofProfileEndpoint )
1484+ Expect (err ).NotTo (HaveOccurred ())
1485+ Expect (resp .StatusCode ).To (Equal (200 ))
1486+
1487+ pprofSymbolEndpoint := fmt .Sprintf ("http://%s/debug/pprof/symbol" , listener .Addr ().String ())
1488+ resp , err = http .Get (pprofSymbolEndpoint )
1489+ Expect (err ).NotTo (HaveOccurred ())
1490+ Expect (resp .StatusCode ).To (Equal (200 ))
1491+
1492+ pprofTraceEndpoint := fmt .Sprintf ("http://%s/debug/pprof/trace" , listener .Addr ().String ())
1493+ resp , err = http .Get (pprofTraceEndpoint )
1494+ Expect (err ).NotTo (HaveOccurred ())
1495+ Expect (resp .StatusCode ).To (Equal (200 ))
1496+ })
1497+ })
1498+
13981499 Describe ("Add" , func () {
13991500 It ("should immediately start the Component if the Manager has already Started another Component" ,
14001501 func () {
0 commit comments