add a simple healtcheck for metrics endpoint

Signed-off-by: Jakub Sokołowski <jakub@status.im>
This commit is contained in:
Jakub Sokołowski 2019-11-04 15:43:48 +01:00 committed by Jakub
parent e311307061
commit c19f07f9e4
1 changed files with 10 additions and 0 deletions

View File

@ -19,6 +19,7 @@ type Server struct {
func NewMetricsServer(port int, r metrics.Registry) *Server { func NewMetricsServer(port int, r metrics.Registry) *Server {
mux := http.NewServeMux() mux := http.NewServeMux()
mux.Handle("/health", healthHandler())
mux.Handle("/metrics", Handler(r)) mux.Handle("/metrics", Handler(r))
p := Server{ p := Server{
server: &http.Server{ server: &http.Server{
@ -29,6 +30,15 @@ func NewMetricsServer(port int, r metrics.Registry) *Server {
return &p return &p
} }
func healthHandler() http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
_, err := w.Write([]byte("OK"))
if err != nil {
log.Error("health handler error", "err", err)
}
})
}
func Handler(reg metrics.Registry) http.Handler { func Handler(reg metrics.Registry) http.Handler {
// we disable compression because geth doesn't support it // we disable compression because geth doesn't support it
opts := promhttp.HandlerOpts{DisableCompression: true} opts := promhttp.HandlerOpts{DisableCompression: true}