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 pprof support to ark server #234

Merged
merged 1 commit into from
Dec 5, 2018
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
1 change: 1 addition & 0 deletions changelogs/unreleased/234-ncdc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add pprof support to the Ark server
23 changes: 23 additions & 0 deletions pkg/cmd/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"io/ioutil"
"log"
"net/http"
"net/http/pprof"
"os"
"strings"
"sync"
Expand Down Expand Up @@ -79,6 +80,8 @@ const (
// server's client default qps and burst
defaultClientQPS float32 = 20.0
defaultClientBurst int = 30

defaultProfilerAddress = "localhost:6060"
)

type serverConfig struct {
Expand All @@ -89,6 +92,7 @@ type serverConfig struct {
restoreOnly bool
clientQPS float32
clientBurst int
profilerAddress string
}

func NewCommand() *cobra.Command {
Expand All @@ -105,6 +109,7 @@ func NewCommand() *cobra.Command {
restoreResourcePriorities: defaultRestorePriorities,
clientQPS: defaultClientQPS,
clientBurst: defaultClientBurst,
profilerAddress: defaultProfilerAddress,
}
)

Expand Down Expand Up @@ -162,6 +167,7 @@ func NewCommand() *cobra.Command {
command.Flags().Var(&volumeSnapshotLocations, "default-volume-snapshot-locations", "list of unique volume providers and default volume snapshot location (provider1:location-01,provider2:location-02,...)")
command.Flags().Float32Var(&config.clientQPS, "client-qps", config.clientQPS, "maximum number of requests per second by the server to the Kubernetes API once the burst limit has been reached")
command.Flags().IntVar(&config.clientBurst, "client-burst", config.clientBurst, "maximum number of requests by the server to the Kubernetes API in a short period of time")
command.Flags().StringVar(&config.profilerAddress, "profiler-address", config.profilerAddress, "the address to expose the pprof profiler")

return command
}
Expand Down Expand Up @@ -268,6 +274,10 @@ func (s *server) run() error {

signals.CancelOnShutdown(s.cancelFunc, s.logger)

if s.config.profilerAddress != "" {
go s.runProfiler()
}

// Since s.namespace, which specifies where backups/restores/schedules/etc. should live,
// *could* be different from the namespace where the Ark server pod runs, check to make
// sure it exists, and fail fast if it doesn't.
Expand Down Expand Up @@ -688,6 +698,19 @@ func (s *server) runControllers(defaultVolumeSnapshotLocations map[string]string
return nil
}

func (s *server) runProfiler() {
mux := http.NewServeMux()
mux.HandleFunc("/debug/pprof/", pprof.Index)
mux.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
mux.HandleFunc("/debug/pprof/profile", pprof.Profile)
mux.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
mux.HandleFunc("/debug/pprof/trace", pprof.Trace)

if err := http.ListenAndServe(s.config.profilerAddress, mux); err != nil {
s.logger.WithError(errors.WithStack(err)).Error("error running profiler http server")
}
}

// TODO(1.0): remove
func (s *server) removeDeprecatedGCFinalizer() {
const gcFinalizer = "gc.ark.heptio.com"
Expand Down