Add /p2p page (#3391)

* add /p2p page

* fix tests
This commit is contained in:
Preston Van Loon
2019-09-03 09:07:40 -07:00
committed by Raul Jordan
parent d23ba8e69d
commit 90b2a880c6
4 changed files with 89 additions and 1 deletions

View File

@@ -24,9 +24,15 @@ type Service struct {
failStatus error
}
// Handler represents a path and handler func to serve on the same port as /metrics, /healthz, /goroutinez, etc.
type Handler struct {
Path string
Handler func(http.ResponseWriter, *http.Request)
}
// NewPrometheusService sets up a new instance for a given address host:port.
// An empty host will match with any IP so an address like ":2121" is perfectly acceptable.
func NewPrometheusService(addr string, svcRegistry *shared.ServiceRegistry) *Service {
func NewPrometheusService(addr string, svcRegistry *shared.ServiceRegistry, additionalHandlers ...Handler) *Service {
s := &Service{svcRegistry: svcRegistry}
mux := http.NewServeMux()
@@ -34,6 +40,11 @@ func NewPrometheusService(addr string, svcRegistry *shared.ServiceRegistry) *Ser
mux.HandleFunc("/healthz", s.healthzHandler)
mux.HandleFunc("/goroutinez", s.goroutinezHandler)
// Register additional handlers.
for _, h := range additionalHandlers {
mux.HandleFunc(h.Path, h.Handler)
}
s.server = &http.Server{Addr: addr, Handler: mux}
return s