Skip to content

Commit 1003a3e

Browse files
armruleonardoce
authored andcommitted
feat: add pprof
This patch adds the pprof server feature to the instance sidecar container Signed-off-by: Armando Ruocco <[email protected]>
1 parent 8901cb9 commit 1003a3e

File tree

4 files changed

+37
-1
lines changed

4 files changed

+37
-1
lines changed

.wordlist.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ pluginConfiguration
128128
podName
129129
postgres
130130
postgresql
131+
pprof
131132
primaryUpdateStrategy
132133
rbac
133134
rc

internal/cmd/instance/main.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ func NewCmd() *cobra.Command {
5252
},
5353
}
5454

55+
cmd.Flags().Bool("pprof-server",
56+
false,
57+
"If true it will start a pprof debug http server on localhost:6061. Defaults to false.",
58+
)
59+
_ = viper.BindPFlag("pprof-server", cmd.Flags().Lookup("pprof-server"))
60+
5561
_ = viper.BindEnv("namespace", "NAMESPACE")
5662
_ = viper.BindEnv("cluster-name", "CLUSTER_NAME")
5763
_ = 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
@@ -52,7 +52,8 @@ func Start(ctx context.Context) error {
5252
namespace := viper.GetString("namespace")
5353

5454
controllerOptions := ctrl.Options{
55-
Scheme: scheme,
55+
PprofBindAddress: getPprofServerAddress(),
56+
Scheme: scheme,
5657
Client: client.Options{
5758
// Important: the caching options below are used by
5859
// controller-runtime only.
@@ -148,3 +149,11 @@ func generateScheme(ctx context.Context) *runtime.Scheme {
148149

149150
return result
150151
}
152+
153+
func getPprofServerAddress() string {
154+
if viper.GetBool("pprof-server") {
155+
return "0.0.0.0:6061"
156+
}
157+
158+
return ""
159+
}

web/docs/misc.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,23 @@ spec:
7474
7575
For a complete list of supported options, refer to the
7676
[official Barman Cloud documentation](https://docs.pgbarman.org/release/latest/).
77+
78+
## Enable the pprof debug server for the sidecar
79+
80+
You can enable the instance sidecar's pprof debug HTTP server by adding the `--pprof-server` flag to the container's
81+
arguments via `.spec.instanceSidecarConfiguration.additionalContainerArgs` in the `ObjectStore` resource.
82+
83+
This starts a pprof server on port 6061 inside the Pod.
84+
85+
### Example
86+
87+
```yaml
88+
apiVersion: barmancloud.cnpg.io/v1
89+
kind: ObjectStore
90+
metadata:
91+
name: my-store
92+
spec:
93+
instanceSidecarConfiguration:
94+
additionalContainerArgs:
95+
- "--pprof-server"
96+
```

0 commit comments

Comments
 (0)