From 3ace7f283620d3f895328405c280c18a57d8b846 Mon Sep 17 00:00:00 2001 From: Armando Ruocco Date: Thu, 18 Sep 2025 17:24:56 +0200 Subject: [PATCH 1/2] feat: add `pprof` This patch adds the pprof server feature to the instance sidecar container Signed-off-by: Armando Ruocco --- .wordlist.txt | 1 + internal/cmd/instance/main.go | 6 ++++++ internal/cnpgi/instance/manager.go | 11 ++++++++++- web/docs/misc.md | 20 ++++++++++++++++++++ 4 files changed, 37 insertions(+), 1 deletion(-) diff --git a/.wordlist.txt b/.wordlist.txt index fd703f4..6b8b348 100644 --- a/.wordlist.txt +++ b/.wordlist.txt @@ -123,6 +123,7 @@ pluginConfiguration podName postgres postgresql +pprof primaryUpdateStrategy rbac rc diff --git a/internal/cmd/instance/main.go b/internal/cmd/instance/main.go index 95f7124..964c36f 100644 --- a/internal/cmd/instance/main.go +++ b/internal/cmd/instance/main.go @@ -33,6 +33,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 cb7f710..20e672d 100644 --- a/internal/cnpgi/instance/manager.go +++ b/internal/cnpgi/instance/manager.go @@ -33,7 +33,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. @@ -129,3 +130,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 4d3cefc..f8a8dc4 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" +``` From 585814ed679897a1eab9a3a80fe9f3eabce9aa79 Mon Sep 17 00:00:00 2001 From: Armando Ruocco Date: Mon, 22 Sep 2025 11:21:21 +0200 Subject: [PATCH 2/2] feat: migrato to string Signed-off-by: Armando Ruocco --- internal/cmd/instance/main.go | 7 ++++--- internal/cnpgi/instance/manager.go | 10 +--------- web/docs/misc.md | 9 +++++---- 3 files changed, 10 insertions(+), 16 deletions(-) diff --git a/internal/cmd/instance/main.go b/internal/cmd/instance/main.go index 964c36f..c6bb34d 100644 --- a/internal/cmd/instance/main.go +++ b/internal/cmd/instance/main.go @@ -33,9 +33,10 @@ 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.", + cmd.Flags().String("pprof-server", + "", + "The address where pprof server should be exposed, for example: 0.0.0.0:6061. "+ + "Empty string means disabled. Disabled by default", ) _ = viper.BindPFlag("pprof-server", cmd.Flags().Lookup("pprof-server")) diff --git a/internal/cnpgi/instance/manager.go b/internal/cnpgi/instance/manager.go index 20e672d..65bd54b 100644 --- a/internal/cnpgi/instance/manager.go +++ b/internal/cnpgi/instance/manager.go @@ -33,7 +33,7 @@ func Start(ctx context.Context) error { namespace := viper.GetString("namespace") controllerOptions := ctrl.Options{ - PprofBindAddress: getPprofServerAddress(), + PprofBindAddress: viper.GetString("pprof-server"), Scheme: scheme, Client: client.Options{ // Important: the caching options below are used by @@ -130,11 +130,3 @@ 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 f8a8dc4..07304f6 100644 --- a/web/docs/misc.md +++ b/web/docs/misc.md @@ -77,10 +77,11 @@ For a complete list of supported options, refer to the ## 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. +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`. -This starts a pprof server on port 6061 inside the Pod. +Pass a bind address in the form `:` (for example, `0.0.0.0:6061`). +An empty value disables the server (disabled by default). ### Example @@ -92,5 +93,5 @@ metadata: spec: instanceSidecarConfiguration: additionalContainerArgs: - - "--pprof-server" + - "--pprof-server=0.0.0.0:6061" ```