@@ -148,6 +148,9 @@ var _ = Describe("manger.Manager", func() {
148148						ReadinessEndpointName :  "/readyz" ,
149149						LivenessEndpointName :   "/livez" ,
150150					},
151+ 					Profiling : v1alpha1.ControllerProfiling {
152+ 						PprofBindAddress : ":6080" ,
153+ 					},
151154					Webhook : v1alpha1.ControllerWebhook {
152155						Port :    & port ,
153156						Host :    "localhost" ,
@@ -172,6 +175,7 @@ var _ = Describe("manger.Manager", func() {
172175			Expect (m .HealthProbeBindAddress ).To (Equal ("6060" ))
173176			Expect (m .ReadinessEndpointName ).To (Equal ("/readyz" ))
174177			Expect (m .LivenessEndpointName ).To (Equal ("/livez" ))
178+ 			Expect (m .PprofBindAddress ).To (Equal (":6080" ))
175179			Expect (m .Port ).To (Equal (port ))
176180			Expect (m .Host ).To (Equal ("localhost" ))
177181			Expect (m .CertDir ).To (Equal ("/certs" ))
@@ -204,6 +208,9 @@ var _ = Describe("manger.Manager", func() {
204208						ReadinessEndpointName :  "/readyz" ,
205209						LivenessEndpointName :   "/livez" ,
206210					},
211+ 					Profiling : v1alpha1.ControllerProfiling {
212+ 						PprofBindAddress : ":6080" ,
213+ 					},
207214					Webhook : v1alpha1.ControllerWebhook {
208215						Port :    & port ,
209216						Host :    "localhost" ,
@@ -229,6 +236,7 @@ var _ = Describe("manger.Manager", func() {
229236				HealthProbeBindAddress :     "5000" ,
230237				ReadinessEndpointName :      "/readiness" ,
231238				LivenessEndpointName :       "/liveness" ,
239+ 				PprofBindAddress :           ":6000" ,
232240				Port :                       8080 ,
233241				Host :                       "example.com" ,
234242				CertDir :                    "/pki" ,
@@ -249,6 +257,7 @@ var _ = Describe("manger.Manager", func() {
249257			Expect (m .HealthProbeBindAddress ).To (Equal ("5000" ))
250258			Expect (m .ReadinessEndpointName ).To (Equal ("/readiness" ))
251259			Expect (m .LivenessEndpointName ).To (Equal ("/liveness" ))
260+ 			Expect (m .PprofBindAddress ).To (Equal (":6000" ))
252261			Expect (m .Port ).To (Equal (8080 ))
253262			Expect (m .Host ).To (Equal ("example.com" ))
254263			Expect (m .CertDir ).To (Equal ("/pki" ))
@@ -288,6 +297,7 @@ var _ = Describe("manger.Manager", func() {
288297					LeaderElectionID :        "test-leader-election-id-2" ,
289298					HealthProbeBindAddress :  "0" ,
290299					MetricsBindAddress :      "0" ,
300+ 					PprofBindAddress :        "0" ,
291301				})
292302				Expect (err ).To (BeNil ())
293303
@@ -333,6 +343,7 @@ var _ = Describe("manger.Manager", func() {
333343					LeaderElectionID :        "test-leader-election-id-3" ,
334344					HealthProbeBindAddress :  "0" ,
335345					MetricsBindAddress :      "0" ,
346+ 					PprofBindAddress :        "0" ,
336347				})
337348				Expect (err ).To (BeNil ())
338349
@@ -367,6 +378,7 @@ var _ = Describe("manger.Manager", func() {
367378					},
368379					HealthProbeBindAddress : "0" ,
369380					MetricsBindAddress :     "0" ,
381+ 					PprofBindAddress :       "0" ,
370382				})
371383				Expect (err ).ToNot (HaveOccurred ())
372384				Expect (m1 ).ToNot (BeNil ())
@@ -387,6 +399,7 @@ var _ = Describe("manger.Manager", func() {
387399					},
388400					HealthProbeBindAddress : "0" ,
389401					MetricsBindAddress :     "0" ,
402+ 					PprofBindAddress :       "0" ,
390403				})
391404				Expect (err ).ToNot (HaveOccurred ())
392405				Expect (m2 ).ToNot (BeNil ())
@@ -1420,6 +1433,94 @@ var _ = Describe("manger.Manager", func() {
14201433		})
14211434	})
14221435
1436+ 	Context ("should start serving pprof" , func () {
1437+ 		var  listener  net.Listener 
1438+ 		var  opts  Options 
1439+ 
1440+ 		BeforeEach (func () {
1441+ 			listener  =  nil 
1442+ 			opts  =  Options {
1443+ 				newPprofListener : func (addr  string ) (net.Listener , error ) {
1444+ 					var  err  error 
1445+ 					listener , err  =  defaultPprofListener (addr )
1446+ 					return  listener , err 
1447+ 				},
1448+ 			}
1449+ 		})
1450+ 
1451+ 		AfterEach (func () {
1452+ 			if  listener  !=  nil  {
1453+ 				listener .Close ()
1454+ 			}
1455+ 		})
1456+ 
1457+ 		It ("should stop serving pprof when stop is called" , func () {
1458+ 			opts .PprofBindAddress  =  ":0" 
1459+ 			m , err  :=  New (cfg , opts )
1460+ 			Expect (err ).NotTo (HaveOccurred ())
1461+ 
1462+ 			ctx , cancel  :=  context .WithCancel (context .Background ())
1463+ 			go  func () {
1464+ 				defer  GinkgoRecover ()
1465+ 				Expect (m .Start (ctx )).NotTo (HaveOccurred ())
1466+ 			}()
1467+ 			<- m .Elected ()
1468+ 
1469+ 			// Check the pprof started 
1470+ 			endpoint  :=  fmt .Sprintf ("http://%s" , listener .Addr ().String ())
1471+ 			_ , err  =  http .Get (endpoint )
1472+ 			Expect (err ).NotTo (HaveOccurred ())
1473+ 
1474+ 			// Shutdown the server 
1475+ 			cancel ()
1476+ 
1477+ 			// Expect the pprof server to shutdown 
1478+ 			Eventually (func () error  {
1479+ 				_ , err  =  http .Get (endpoint )
1480+ 				return  err 
1481+ 			}).ShouldNot (Succeed ())
1482+ 		})
1483+ 
1484+ 		It ("should serve pprof endpoints" , func () {
1485+ 			opts .PprofBindAddress  =  ":0" 
1486+ 			m , err  :=  New (cfg , opts )
1487+ 			Expect (err ).NotTo (HaveOccurred ())
1488+ 
1489+ 			ctx , cancel  :=  context .WithCancel (context .Background ())
1490+ 			defer  cancel ()
1491+ 			go  func () {
1492+ 				defer  GinkgoRecover ()
1493+ 				Expect (m .Start (ctx )).NotTo (HaveOccurred ())
1494+ 			}()
1495+ 			<- m .Elected ()
1496+ 
1497+ 			pprofIndexEndpoint  :=  fmt .Sprintf ("http://%s/debug/pprof/" , listener .Addr ().String ())
1498+ 			resp , err  :=  http .Get (pprofIndexEndpoint )
1499+ 			Expect (err ).NotTo (HaveOccurred ())
1500+ 			Expect (resp .StatusCode ).To (Equal (200 ))
1501+ 
1502+ 			pprofCmdlineEndpoint  :=  fmt .Sprintf ("http://%s/debug/pprof/cmdline" , listener .Addr ().String ())
1503+ 			resp , err  =  http .Get (pprofCmdlineEndpoint )
1504+ 			Expect (err ).NotTo (HaveOccurred ())
1505+ 			Expect (resp .StatusCode ).To (Equal (200 ))
1506+ 
1507+ 			pprofProfileEndpoint  :=  fmt .Sprintf ("http://%s/debug/pprof/profile" , listener .Addr ().String ())
1508+ 			resp , err  =  http .Get (pprofProfileEndpoint )
1509+ 			Expect (err ).NotTo (HaveOccurred ())
1510+ 			Expect (resp .StatusCode ).To (Equal (200 ))
1511+ 
1512+ 			pprofSymbolEndpoint  :=  fmt .Sprintf ("http://%s/debug/pprof/symbol" , listener .Addr ().String ())
1513+ 			resp , err  =  http .Get (pprofSymbolEndpoint )
1514+ 			Expect (err ).NotTo (HaveOccurred ())
1515+ 			Expect (resp .StatusCode ).To (Equal (200 ))
1516+ 
1517+ 			pprofTraceEndpoint  :=  fmt .Sprintf ("http://%s/debug/pprof/trace" , listener .Addr ().String ())
1518+ 			resp , err  =  http .Get (pprofTraceEndpoint )
1519+ 			Expect (err ).NotTo (HaveOccurred ())
1520+ 			Expect (resp .StatusCode ).To (Equal (200 ))
1521+ 		})
1522+ 	})
1523+ 
14231524	Describe ("Add" , func () {
14241525		It ("should immediately start the Component if the Manager has already Started another Component" ,
14251526			func () {
0 commit comments