Skip to content

Commit

Permalink
Merge pull request #234 from ncdc/pprof
Browse files Browse the repository at this point in the history
Add pprof support to ark server
  • Loading branch information
wwitzel3 committed Dec 5, 2018
2 parents 8955199 + aa9d96f commit 5464b3d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions changelogs/unreleased/234-ncdc
@@ -0,0 +1 @@
Add pprof support to the Ark server
23 changes: 23 additions & 0 deletions pkg/cmd/server/server.go
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

0 comments on commit 5464b3d

Please sign in to comment.