feat: add pprof

This patch adds the pprof server feature to the instance sidecar container

Signed-off-by: Armando Ruocco <armando.ruocco@enterprisedb.com>
This commit is contained in:
Armando Ruocco 2025-09-18 17:24:56 +02:00 committed by Marco Nenciarini
parent 77aa6e04ff
commit 3ace7f2836
No known key found for this signature in database
GPG Key ID: 589F03F01BA55038
4 changed files with 37 additions and 1 deletions

View File

@ -123,6 +123,7 @@ pluginConfiguration
podName
postgres
postgresql
pprof
primaryUpdateStrategy
rbac
rc

View File

@ -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")

View File

@ -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 ""
}

View File

@ -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"
```