Skip to content

Commit

Permalink
add missing file
Browse files Browse the repository at this point in the history
Signed-off-by: Tim Vaillancourt <[email protected]>
  • Loading branch information
timvaillancourt committed Jul 6, 2023
1 parent b94e9a9 commit 80ce4af
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions http.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package nebula

import (
"fmt"
"log"
"net/http"
_ "net/http/pprof"

"github.com/sirupsen/logrus"
"github.com/slackhq/nebula/config"
)

func startHttp(l *logrus.Logger, c *config.C, buildVersion string, configTest bool) (func(), error) {
listen := c.GetString("http.listen", "")
if listen == "" {
// TODO: remove this in future releases. Fallback to stats.listen for
// backwards-compatibility if http.listen is undef.
if statsListen := c.GetString("stats.listen", ""); statsListen != "" {
listen = statsListen
} else {
return nil, fmt.Errorf("http.listen should not be empty")
}
}

statsPath := c.GetString("stats.path", "")
if statsPath == "" {
return nil, fmt.Errorf("stats.path should not be empty")
}

var startFn func()
if !configTest {
statsHandler, err := startStats(l, c, buildVersion, configTest)
if err != nil {
return nil, err
}

startFn = func() {
if statsHandler != nil {
l.Infof("Prometheus stats listening on %s at %s", listen, statsPath)
http.Handle(statsPath, statsHandler)
}
l.Infof("Pprof profiling listening on %s at /debug/pprof", listen)
log.Fatal(http.ListenAndServe(listen, nil))
}
}

return startFn, nil
}

0 comments on commit 80ce4af

Please sign in to comment.