Skip to content

Commit 4fe61fd

Browse files
committed
feat: add pprof
This patch adds the pprof server feature to the instance sidecar container Signed-off-by: Armando Ruocco <[email protected]>
1 parent 549e1ae commit 4fe61fd

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

internal/cmd/instance/main.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ func NewCmd() *cobra.Command {
3333
},
3434
}
3535

36+
cmd.Flags().Bool("pprof-server",
37+
false,
38+
"If true it will start a pprof debug http server on localhost:6061. Defaults to false.",
39+
)
40+
_ = viper.BindPFlag("pprof-server", cmd.Flags().Lookup("pprof-server"))
41+
3642
_ = viper.BindEnv("namespace", "NAMESPACE")
3743
_ = viper.BindEnv("cluster-name", "CLUSTER_NAME")
3844
_ = viper.BindEnv("pod-name", "POD_NAME")

internal/cnpgi/instance/manager.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ func Start(ctx context.Context) error {
3333
namespace := viper.GetString("namespace")
3434

3535
controllerOptions := ctrl.Options{
36-
Scheme: scheme,
36+
PprofBindAddress: getPprofServerAddress(),
37+
Scheme: scheme,
3738
Client: client.Options{
3839
// Important: the caching options below are used by
3940
// controller-runtime only.
@@ -129,3 +130,11 @@ func generateScheme(ctx context.Context) *runtime.Scheme {
129130

130131
return result
131132
}
133+
134+
func getPprofServerAddress() string {
135+
if viper.GetBool("pprof-server") {
136+
return "0.0.0.0:6061"
137+
}
138+
139+
return ""
140+
}

0 commit comments

Comments
 (0)