Skip to content

Commit 3a03b30

Browse files
authored
website: allow pprof (#248)
website pprof
1 parent ecf223d commit 3a03b30

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

services/website/website.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55
"bytes"
66
"errors"
77
"net/http"
8+
_ "net/http/pprof"
9+
"os"
810
"strconv"
911
"sync"
1012
"text/template"
@@ -24,7 +26,10 @@ import (
2426
uberatomic "go.uber.org/atomic"
2527
)
2628

27-
var ErrServerAlreadyStarted = errors.New("server was already started")
29+
var (
30+
ErrServerAlreadyStarted = errors.New("server was already started")
31+
EnablePprof = os.Getenv("PPROF") == "1"
32+
)
2833

2934
type WebserverOpts struct {
3035
ListenAddress string
@@ -144,6 +149,11 @@ func (srv *Webserver) StartServer() (err error) {
144149
func (srv *Webserver) getRouter() http.Handler {
145150
r := mux.NewRouter()
146151
r.HandleFunc("/", srv.handleRoot).Methods(http.MethodGet)
152+
if EnablePprof {
153+
srv.log.Info("pprof API enabled")
154+
r.PathPrefix("/debug/pprof/").Handler(http.DefaultServeMux)
155+
}
156+
147157
loggedRouter := httplogger.LoggingMiddlewareLogrus(srv.log, r)
148158
withGz := gziphandler.GzipHandler(loggedRouter)
149159
return withGz

0 commit comments

Comments
 (0)