-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rename internal http server to instrumentation http server
- Loading branch information
Showing
3 changed files
with
111 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
// Copyright (c) 2019, Janoš Guljaš <[email protected]> | ||
// All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package server | ||
|
||
import ( | ||
"expvar" | ||
"net/http" | ||
"net/http/pprof" | ||
|
||
"github.com/gorilla/handlers" | ||
"github.com/prometheus/client_golang/prometheus/promhttp" | ||
"resenje.org/jsonhttp" | ||
"resenje.org/x/datadump" | ||
|
||
"resenje.org/web" | ||
) | ||
|
||
func newInstrumentationRouter(s *Server, setupFunc func(base, api *http.ServeMux)) http.Handler { | ||
// | ||
// Top level instrumentation router | ||
// | ||
baseRouter := http.NewServeMux() | ||
|
||
// | ||
// Instrumentation router | ||
// | ||
instrumentationRouter := http.NewServeMux() | ||
baseRouter.Handle("/", web.ChainHandlers( | ||
handlers.CompressHandler, | ||
s.textRecoveryHandler, | ||
web.NoCacheHeadersHandler, | ||
web.FinalHandler(instrumentationRouter), | ||
)) | ||
instrumentationRouter.Handle("/", http.HandlerFunc(textNotFoundHandler)) | ||
instrumentationRouter.Handle("/status", http.HandlerFunc(s.statusHandler)) | ||
instrumentationRouter.Handle("/data", datadump.Handler(s.dataDumpServices, s.name+"_"+s.Version(), s.logger)) | ||
|
||
instrumentationRouter.Handle("/debug/pprof/", http.HandlerFunc(pprof.Index)) | ||
instrumentationRouter.Handle("/debug/pprof/cmdline", http.HandlerFunc(pprof.Cmdline)) | ||
instrumentationRouter.Handle("/debug/pprof/profile", http.HandlerFunc(pprof.Profile)) | ||
instrumentationRouter.Handle("/debug/pprof/symbol", http.HandlerFunc(pprof.Symbol)) | ||
instrumentationRouter.Handle("/debug/pprof/trace", http.HandlerFunc(pprof.Trace)) | ||
|
||
instrumentationRouter.Handle("/debug/vars", expvar.Handler()) | ||
|
||
// | ||
// Instrumentation API router | ||
// | ||
instrumentationAPIRouter := http.NewServeMux() | ||
baseRouter.Handle("/api/", web.ChainHandlers( | ||
handlers.CompressHandler, | ||
s.jsonRecoveryHandler, | ||
web.NoCacheHeadersHandler, | ||
web.FinalHandler(instrumentationAPIRouter), | ||
)) | ||
instrumentationAPIRouter.Handle("/api/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
jsonhttp.NotFound(w, nil) | ||
})) | ||
instrumentationAPIRouter.Handle("/api/status", http.HandlerFunc(s.statusAPIHandler)) | ||
if s.maintenanceService != nil { | ||
instrumentationAPIRouter.Handle("/api/maintenance", jsonMethodHandler{ | ||
"GET": http.HandlerFunc(s.maintenanceService.StatusHandler), | ||
"POST": http.HandlerFunc(s.maintenanceService.OnHandler), | ||
"DELETE": http.HandlerFunc(s.maintenanceService.OffHandler), | ||
}) | ||
} | ||
baseRouter.Handle("/metrics", promhttp.InstrumentMetricHandler( | ||
s.metricsRegistry, | ||
promhttp.HandlerFor(s.metricsRegistry, promhttp.HandlerOpts{}), | ||
)) | ||
|
||
if setupFunc != nil { | ||
setupFunc(baseRouter, instrumentationAPIRouter) | ||
} | ||
|
||
// | ||
// Final instrumentation handler | ||
// | ||
return web.ChainHandlers( | ||
func(h http.Handler) http.Handler { | ||
return web.NewSetHeadersHandler(h, map[string]string{ | ||
"Server": s.name + "/" + s.Version(), | ||
}) | ||
}, | ||
web.FinalHandler(baseRouter), | ||
) | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters