Skip to content

Commit bbbe592

Browse files
cmd/opm: serve pprof endpoints by default
There is no substantial runtime cost to serving pprof endpoints, and when things hit the fan and we need to investigate performance in situ, there is no time to restart pods and change flags. Capturing profiles remains opt-in, since those are costly. Signed-off-by: Steve Kuznetsov <[email protected]>
1 parent 36b24a0 commit bbbe592

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

cmd/opm/serve/serve.go

+9-5
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@ type serve struct {
3636
port string
3737
terminationLog string
3838

39-
debug bool
40-
pprofAddr string
39+
debug bool
40+
pprofAddr string
41+
captureProfiles bool
4142

4243
logger *logrus.Entry
4344
}
@@ -80,7 +81,8 @@ will not be reflected in the served content.
8081
cmd.Flags().BoolVar(&s.debug, "debug", false, "enable debug logging")
8182
cmd.Flags().StringVarP(&s.terminationLog, "termination-log", "t", "/dev/termination-log", "path to a container termination log file")
8283
cmd.Flags().StringVarP(&s.port, "port", "p", "50051", "port number to serve on")
83-
cmd.Flags().StringVar(&s.pprofAddr, "pprof-addr", "", "address of startup profiling endpoint (addr:port format)")
84+
cmd.Flags().StringVar(&s.pprofAddr, "pprof-addr", "localhost:6060", "address of startup profiling endpoint (addr:port format)")
85+
cmd.Flags().BoolVar(&s.captureProfiles, "pprof-capture-profiles", false, "capture pprof CPU profiles")
8486
cmd.Flags().StringVar(&s.cacheDir, "cache-dir", "", "if set, sync and persist server cache directory")
8587
cmd.Flags().BoolVar(&s.cacheOnly, "cache-only", false, "sync the serve cache and exit without serving")
8688
cmd.Flags().BoolVar(&s.cacheEnforceIntegrity, "cache-enforce-integrity", false, "exit with error if cache is not present or has been invalidated. (default: true when --cache-dir is set and --cache-only is false, false otherwise), ")
@@ -92,8 +94,10 @@ func (s *serve) run(ctx context.Context) error {
9294
if err := p.startEndpoint(); err != nil {
9395
return fmt.Errorf("could not start pprof endpoint: %v", err)
9496
}
95-
if err := p.startCpuProfileCache(); err != nil {
96-
return fmt.Errorf("could not start CPU profile: %v", err)
97+
if s.captureProfiles {
98+
if err := p.startCpuProfileCache(); err != nil {
99+
return fmt.Errorf("could not start CPU profile: %v", err)
100+
}
97101
}
98102

99103
// Immediately set up termination log

0 commit comments

Comments
 (0)