mirror of
https://github.com/slackhq/nebula.git
synced 2025-11-11 00:03:58 +01:00
Cleanup code
Signed-off-by: Tim Vaillancourt <tim@timvaillancourt.com>
This commit is contained in:
parent
70779b26ad
commit
af958676b8
10
http.go
10
http.go
@ -9,7 +9,9 @@ import (
|
||||
"github.com/slackhq/nebula/config"
|
||||
)
|
||||
|
||||
func startHttp(l *logrus.Logger, c *config.C, statsHandler statsHandlerFunc, listen string) (f func(), err error) {
|
||||
// startHttp returns a function to start an http server with pprof support and optionally, a provided stats
|
||||
// http handler.
|
||||
func startHttp(l *logrus.Logger, c *config.C, listen string, statsHandler statsHandlerFunc) (func(), error) {
|
||||
if listen == "" {
|
||||
return nil, nil
|
||||
}
|
||||
@ -22,13 +24,11 @@ func startHttp(l *logrus.Logger, c *config.C, statsHandler statsHandlerFunc, lis
|
||||
}
|
||||
}
|
||||
|
||||
f = func() {
|
||||
return func() {
|
||||
l.Infof("Go pprof handler listening on %s at /debug/pprof", listen)
|
||||
if statsHandler != nil {
|
||||
http.Handle(statsPath, statsHandler(listen, statsPath))
|
||||
}
|
||||
l.Fatal(http.ListenAndServe(listen, nil))
|
||||
}
|
||||
|
||||
return f, err
|
||||
}, nil
|
||||
}
|
||||
|
||||
2
main.go
2
main.go
@ -338,7 +338,7 @@ func Main(c *config.C, configTest bool, buildVersion string, logger *logrus.Logg
|
||||
return nil, util.NewContextualError("Failed to start stats emitter", nil, err)
|
||||
}
|
||||
|
||||
httpStart, err := startHttp(l, c, statsHTTPHandler, httpListen)
|
||||
httpStart, err := startHttp(l, c, httpListen, statsHTTPHandler)
|
||||
if err != nil {
|
||||
return nil, util.NewContextualError("Failed to start http server", nil, err)
|
||||
}
|
||||
|
||||
6
stats.go
6
stats.go
@ -107,13 +107,13 @@ func startPrometheusStats(l *logrus.Logger, i time.Duration, c *config.C, listen
|
||||
pr.MustRegister(g)
|
||||
g.Set(1)
|
||||
|
||||
var f statsHandlerFunc
|
||||
var startHandler statsHandlerFunc
|
||||
if !configTest {
|
||||
f = func(listen, path string) http.Handler {
|
||||
startHandler = func(listen, path string) http.Handler {
|
||||
l.Infof("Prometheus stats listening on %s at %s", listen, path)
|
||||
return promhttp.HandlerFor(pr, promhttp.HandlerOpts{ErrorLog: l})
|
||||
}
|
||||
}
|
||||
|
||||
return f, nil
|
||||
return startHandler, nil
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user