diff --git a/.wordlist.txt b/.wordlist.txt index 24d9309..246e667 100644 --- a/.wordlist.txt +++ b/.wordlist.txt @@ -128,6 +128,7 @@ pluginConfiguration podName postgres postgresql +pprof primaryUpdateStrategy rbac rc diff --git a/internal/cmd/instance/main.go b/internal/cmd/instance/main.go index da73385..bc4060f 100644 --- a/internal/cmd/instance/main.go +++ b/internal/cmd/instance/main.go @@ -52,6 +52,12 @@ func NewCmd() *cobra.Command { }, } + cmd.Flags().Bool("pprof-server", + false, + "If true it will start a pprof debug http server on localhost:6061. Defaults to false.", + ) + _ = viper.BindPFlag("pprof-server", cmd.Flags().Lookup("pprof-server")) + _ = viper.BindEnv("namespace", "NAMESPACE") _ = viper.BindEnv("cluster-name", "CLUSTER_NAME") _ = viper.BindEnv("pod-name", "POD_NAME") diff --git a/internal/cnpgi/instance/manager.go b/internal/cnpgi/instance/manager.go index 450eade..d87940a 100644 --- a/internal/cnpgi/instance/manager.go +++ b/internal/cnpgi/instance/manager.go @@ -52,7 +52,8 @@ func Start(ctx context.Context) error { namespace := viper.GetString("namespace") controllerOptions := ctrl.Options{ - Scheme: scheme, + PprofBindAddress: getPprofServerAddress(), + Scheme: scheme, Client: client.Options{ // Important: the caching options below are used by // controller-runtime only. @@ -148,3 +149,11 @@ func generateScheme(ctx context.Context) *runtime.Scheme { return result } + +func getPprofServerAddress() string { + if viper.GetBool("pprof-server") { + return "0.0.0.0:6061" + } + + return "" +} diff --git a/web/docs/misc.md b/web/docs/misc.md index 168ff29..acad83c 100644 --- a/web/docs/misc.md +++ b/web/docs/misc.md @@ -74,3 +74,23 @@ spec: For a complete list of supported options, refer to the [official Barman Cloud documentation](https://docs.pgbarman.org/release/latest/). + +## Enable the pprof debug server for the sidecar + +You can enable the instance sidecar's pprof debug HTTP server by adding the `--pprof-server` flag to the container's +arguments via `.spec.instanceSidecarConfiguration.additionalContainerArgs` in the `ObjectStore` resource. + +This starts a pprof server on port 6061 inside the Pod. + +### Example + +```yaml +apiVersion: barmancloud.cnpg.io/v1 +kind: ObjectStore +metadata: + name: my-store +spec: + instanceSidecarConfiguration: + additionalContainerArgs: + - "--pprof-server" +```