From 71e5cc6eabb4800778093ab664d0672aca59e5e2 Mon Sep 17 00:00:00 2001 From: Stefan Prodan Date: Thu, 8 Feb 2018 13:24:47 +0200 Subject: [PATCH] Register pprof handlers Increase the write timeout to one minute to allow CPU profiling --- pkg/server/server.go | 13 ++++++++++--- pkg/version/version.go | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/pkg/server/server.go b/pkg/server/server.go index 89e63bc..054d3de 100644 --- a/pkg/server/server.go +++ b/pkg/server/server.go @@ -3,7 +3,7 @@ package server import ( "context" "net/http" - _ "net/http/pprof" + "net/http/pprof" "runtime" "sync/atomic" "time" @@ -22,7 +22,7 @@ type Server struct { } func NewServer(options ...func(*Server)) *Server { - s := &Server{mux: http.DefaultServeMux} + s := &Server{mux: http.NewServeMux()} for _, f := range options { f(s) @@ -40,6 +40,13 @@ func NewServer(options ...func(*Server)) *Server { s.mux.HandleFunc("/version", s.version) s.mux.Handle("/metrics", promhttp.Handler()) + // Register pprof handlers + s.mux.HandleFunc("/debug/pprof/", pprof.Index) + s.mux.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline) + s.mux.HandleFunc("/debug/pprof/profile", pprof.Profile) + s.mux.HandleFunc("/debug/pprof/symbol", pprof.Symbol) + s.mux.HandleFunc("/debug/pprof/trace", pprof.Trace) + return s } @@ -55,7 +62,7 @@ func ListenAndServe(port string, timeout time.Duration, stopCh <-chan struct{}) Addr: ":" + port, Handler: inst.Wrap(NewServer()), ReadTimeout: 5 * time.Second, - WriteTimeout: 10 * time.Second, + WriteTimeout: 1 * time.Minute, IdleTimeout: 15 * time.Second, } diff --git a/pkg/version/version.go b/pkg/version/version.go index 54579db..42eb1c3 100644 --- a/pkg/version/version.go +++ b/pkg/version/version.go @@ -1,4 +1,4 @@ package version -var VERSION = "0.0.4" +var VERSION = "0.0.5" var GITCOMMIT = "unknown"