1
0
mirror of https://github.com/jhillyerd/inbucket.git synced 2025-12-17 09:37:02 +00:00

web: Optionally mount /debug/pprof for #120

- web: eliminate use of http.DefaultServeMux
This commit is contained in:
James Hillyerd
2018-10-20 16:16:09 -07:00
parent 5e8f00fe0b
commit 98745b3bb9
4 changed files with 29 additions and 2 deletions

View File

@@ -10,6 +10,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
### Added ### Added
- Use Go 1.11 modules for reproducible builds. - Use Go 1.11 modules for reproducible builds.
- SMTP TLS support (thanks kingforaday.) - SMTP TLS support (thanks kingforaday.)
- `INBUCKET_WEB_PPROF` configuration option for performance profiling.
### Changed ### Changed
- Docker build now uses Go 1.11 and Alpine 3.8 - Docker build now uses Go 1.11 and Alpine 3.8

View File

@@ -35,6 +35,7 @@ variables it supports:
INBUCKET_WEB_COOKIEAUTHKEY Session cipher key (text) INBUCKET_WEB_COOKIEAUTHKEY Session cipher key (text)
INBUCKET_WEB_MONITORVISIBLE true Show monitor tab in UI? INBUCKET_WEB_MONITORVISIBLE true Show monitor tab in UI?
INBUCKET_WEB_MONITORHISTORY 30 Monitor remembered messages INBUCKET_WEB_MONITORHISTORY 30 Monitor remembered messages
INBUCKET_WEB_PPROF false Expose profiling tools on /debug/pprof
INBUCKET_STORAGE_TYPE memory Storage impl: file or memory INBUCKET_STORAGE_TYPE memory Storage impl: file or memory
INBUCKET_STORAGE_PARAMS Storage impl parameters, see docs. INBUCKET_STORAGE_PARAMS Storage impl parameters, see docs.
INBUCKET_STORAGE_RETENTIONPERIOD 24h Duration to retain messages INBUCKET_STORAGE_RETENTIONPERIOD 24h Duration to retain messages
@@ -377,6 +378,20 @@ them.
- Default: `30` - Default: `30`
- Values: Integer greater than or equal to 0 - Values: Integer greater than or equal to 0
### Performance Profiling & Debug Tools
`INBUCKET_WEB_PPROF`
If true, Go's pprof package will be installed to the `/debug/pprof` URI. This
exposes detailed memory and CPU performance data for debugging Inbucket. If you
enable this option, please make sure it is not exposed to the public internet,
as its use can significantly impact performance.
For example usage, see https://golang.org/pkg/net/http/pprof/
- Default: `false`
- Values: `true` or `false`
## Storage ## Storage

View File

@@ -100,6 +100,7 @@ type Web struct {
CookieAuthKey string `desc:"Session cipher key (text)"` CookieAuthKey string `desc:"Session cipher key (text)"`
MonitorVisible bool `required:"true" default:"true" desc:"Show monitor tab in UI?"` MonitorVisible bool `required:"true" default:"true" desc:"Show monitor tab in UI?"`
MonitorHistory int `required:"true" default:"30" desc:"Monitor remembered messages"` MonitorHistory int `required:"true" default:"30" desc:"Monitor remembered messages"`
PProf bool `required:"true" default:"false" desc:"Expose profiling tools on /debug/pprof"`
} }
// Storage contains the mail store configuration. // Storage contains the mail store configuration.

View File

@@ -6,6 +6,7 @@ import (
"expvar" "expvar"
"net" "net"
"net/http" "net/http"
"net/http/pprof"
"path/filepath" "path/filepath"
"time" "time"
@@ -70,7 +71,16 @@ func Initialize(
Msg("Web UI content mapped") Msg("Web UI content mapped")
Router.PathPrefix("/public/").Handler(http.StripPrefix("/public/", Router.PathPrefix("/public/").Handler(http.StripPrefix("/public/",
http.FileServer(http.Dir(staticPath)))) http.FileServer(http.Dir(staticPath))))
http.Handle("/", Router) Router.Handle("/debug/vars", expvar.Handler())
if conf.Web.PProf {
Router.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
Router.HandleFunc("/debug/pprof/profile", pprof.Profile)
Router.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
Router.HandleFunc("/debug/pprof/trace", pprof.Trace)
Router.PathPrefix("/debug/pprof/").HandlerFunc(pprof.Index)
log.Warn().Str("module", "web").Str("phase", "startup").
Msg("Go pprof tools installed to /debug/pprof")
}
// Session cookie setup // Session cookie setup
if conf.Web.CookieAuthKey == "" { if conf.Web.CookieAuthKey == "" {
@@ -88,7 +98,7 @@ func Initialize(
func Start(ctx context.Context) { func Start(ctx context.Context) {
server = &http.Server{ server = &http.Server{
Addr: rootConfig.Web.Addr, Addr: rootConfig.Web.Addr,
Handler: nil, Handler: Router,
ReadTimeout: 60 * time.Second, ReadTimeout: 60 * time.Second,
WriteTimeout: 60 * time.Second, WriteTimeout: 60 * time.Second,
} }