Commit 2404e92
authored
CLOUDP-317911 Add pprof integration in operator (#101)
# Summary
pprof can be configured by two new environment variables:
- `MDB_OPERATOR_PPROF_ENABLED` - together with `OPERATOR_ENV` controls
enabling of pprof server. Basically the rule for enabling pprof is
defined in `IsPprofEnabled` function:
https://github.com/mongodb/mongodb-kubernetes/blob/94fc9eac3f36cc7df096e86b5eef8ce9fed02f58/pkg/pprof/pprof.go#L66-L70
- `MDB_OPERATOR_PPROF_PORT` - by default it is set to 10081
It's more than `_ "net/http/pprof"` one liner for a couple of reasons:
- having the possibility to enable pprof for the production environment
is necessary for debugging memory issues and it does not add much
overhead either https://stackoverflow.com/a/64057856. Previously it was
only enabled for dev and local
- exposing by default pprof server in production is a no-go in many
organisations due to sensitive information exposed or just exposing some
port is enough to alert security staff
https://cwe.mitre.org/data/definitions/200.html
standard way of starting pprof by is discouraged for lack of
configurability and security issues
- G114: Use of net/http serve function that has no support for setting
timeouts (gosec)
- G108: Profiling endpoint is automatically exposed on /debug/pprof
(gosec)
```go
import _ "net/http/pprof"
[...]
go func() {
log.Println(http.ListenAndServe("localhost:10081", nil))
}()
```
## Proof of Work
pprof debug page is available at default `localhost:10081` port

Added unit tests that verify `IsPprofEnabled` function. Shutdown is also
working:
```go
2025-05-09T16:32:56.750+0200 INFO pprof/pprof.go:57 Stopping pprof server
2025-05-09T16:32:56.750+0200 INFO controller/controller.go:235 Shutdown signal received, waiting for all workers to finish {"controller": "mongodbuser-controller"}
2025-05-09T16:32:56.750+0200 INFO controller/controller.go:237 All workers finished {"controller": "mongodbmulticluster-controller"}
2025-05-09T16:32:56.750+0200 INFO controller/controller.go:237 All workers finished {"controller": "mongodbreplicaset-controller"}
2025-05-09T16:32:56.750+0200 INFO controller/controller.go:237 All workers finished {"controller": "mongodbstandalone-controller"}
2025-05-09T16:32:56.750+0200 INFO controller/controller.go:237 All workers finished {"controller": "mongodbuser-controller"}
2025-05-09T16:32:56.750+0200 INFO controller/controller.go:237 All workers finished {"controller": "opsmanager-controller"}
2025-05-09T16:32:56.750+0200 INFO controller/controller.go:237 All workers finished {"controller": "mongodbshardedcluster-controller"}
2025-05-09T16:32:56.750+0200 INFO manager/internal.go:537 Stopping and waiting for caches
2025-05-09T16:32:56.750+0200 INFO pprof/pprof.go:52 pprof server stopped
```
## Checklist
- [x] Have you linked a jira ticket and/or is the ticket in the title?
- [ ] Have you checked whether your jira ticket required DOCSP changes?
- [ ] Have you checked for release_note changes?
## Reminder (Please remove this when merging)
- Please try to Approve or Reject Changes the PR, keep PRs in review as
short as possible
- Our Short Guide for PRs:
[Link](https://docs.google.com/document/d/1T93KUtdvONq43vfTfUt8l92uo4e4SEEvFbIEKOxGr44/edit?tab=t.0)
- Remember the following Communication Standards - use comment prefixes
for clarity:
* **blocking**: Must be addressed before approval.
* **follow-up**: Can be addressed in a later PR or ticket.
* **q**: Clarifying question.
* **nit**: Non-blocking suggestions.
* **note**: Side-note, non-actionable. Example: Praise
* --> no prefix is considered a question1 parent 7fa6687 commit 2404e92
4 files changed
+178
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
| 49 | + | |
49 | 50 | | |
50 | 51 | | |
51 | 52 | | |
| |||
277 | 278 | | |
278 | 279 | | |
279 | 280 | | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
280 | 291 | | |
281 | 292 | | |
282 | 293 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
154 | 154 | | |
155 | 155 | | |
156 | 156 | | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
157 | 162 | | |
158 | 163 | | |
159 | 164 | | |
| |||
0 commit comments