Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to enable pprof endpoints #813

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ spec:
value: {{ .Values.manager.dnsBase }}
- name: PARALLEL_RECOVERY_ENABLED
value: "{{ .Values.manager.parallelRecoveryEnabled }}"
- name: PPROF_ENDPOINTS_ENABLED
value: "{{ .Values.manager.pprofEndpointsEnabled }}"
{{- if .Values.manager.extraEnv }}
{{- toYaml .Values.manager.extraEnv | nindent 8 }}
{{- end }}
Expand Down
3 changes: 3 additions & 0 deletions charts/opensearch-operator/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ manager:

# Set this to false to disable the experimental parallel recovery in case you are experiencing problems
parallelRecoveryEnabled: true
# Set this to true to enable the standard go pprof endpoints on port 6060 (https://pkg.go.dev/net/http/pprof)
# Should only be used for debugging purposes
pprofEndpointsEnabled: false

image:
repository: opensearchproject/opensearch-operator
Expand Down
11 changes: 11 additions & 0 deletions docs/userguide/main.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,17 @@ manager:
# value: somevalue
```

### Pprof endpoints

There have been situations reported where the operator is leaking memory. To help diagnose these situations the standard go [pprof](https://pkg.go.dev/net/http/pprof) endpoints can be enabled by adding the following to your `values.yaml`:

```yaml
manager:
pprofEndpointsEnabled: true
```

The access the endpoints you will need to use a port-forward as for security reasons the endpoints are only exposed on localhost inside the pod: `kubectl port-forward deployment/opensearch-operator-controller-manager 6060`. Then from another terminal you can use the [go pprof tool](https://pkg.go.dev/net/http/pprof#hdr-Usage_examples), e.g.: `go tool pprof http://localhost:6060/debug/pprof/heap`.

## Configuring OpenSearch

The main job of the operator is to deploy and manage OpenSearch clusters. As such it offers a wide range of options to configure clusters.
Expand Down
15 changes: 15 additions & 0 deletions opensearch-operator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ import (
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/healthz"
"sigs.k8s.io/controller-runtime/pkg/log/zap"

"net/http"
_ "net/http/pprof"
)

var (
Expand Down Expand Up @@ -87,6 +90,11 @@ func main() {
setupLog.Info("Enabled debug logging via environment variable OPERATOR_DEV_LOGGING")
}
}
pprofEndpoints, err := strconv.ParseBool(os.Getenv("PPROF_ENDPOINTS_ENABLED"))
if err != nil {
// by default to not enable endpoints
pprofEndpoints = false
}

ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts)))

Expand Down Expand Up @@ -188,6 +196,13 @@ func main() {
os.Exit(1)
}

if pprofEndpoints {
go func() {
listenError := http.ListenAndServe("localhost:6060", nil)
setupLog.Error(listenError, "Failed to start pprof endpoint listener")
}()
}

setupLog.Info("Starting manager")
if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil {
setupLog.Error(err, "problem running manager")
Expand Down