1package http 2 3import ( 4 "expvar" 5 "net/http" 6 "net/http/pprof" 7 8 "github.com/dgryski/httputil" 9 "github.com/go-graphite/carbonapi/cmd/carbonapi/config" 10 "github.com/go-graphite/carbonapi/util/ctx" 11) 12 13func InitHandlers(headersToPass, headersToLog []string) *http.ServeMux { 14 r := http.NewServeMux() 15 r.HandleFunc(config.Config.Prefix+"/render/", httputil.TrackConnections(httputil.TimeHandler(enrichContextWithHeaders(headersToPass, headersToLog, ctx.ParseCtx(renderHandler, ctx.HeaderUUIDAPI)), bucketRequestTimes))) 16 r.HandleFunc(config.Config.Prefix+"/render", httputil.TrackConnections(httputil.TimeHandler(enrichContextWithHeaders(headersToPass, headersToLog, ctx.ParseCtx(renderHandler, ctx.HeaderUUIDAPI)), bucketRequestTimes))) 17 18 r.HandleFunc(config.Config.Prefix+"/metrics/find/", httputil.TrackConnections(httputil.TimeHandler(enrichContextWithHeaders(headersToPass, headersToLog, ctx.ParseCtx(findHandler, ctx.HeaderUUIDAPI)), bucketRequestTimes))) 19 r.HandleFunc(config.Config.Prefix+"/metrics/find", httputil.TrackConnections(httputil.TimeHandler(enrichContextWithHeaders(headersToPass, headersToLog, ctx.ParseCtx(findHandler, ctx.HeaderUUIDAPI)), bucketRequestTimes))) 20 21 r.HandleFunc(config.Config.Prefix+"/info/", httputil.TrackConnections(httputil.TimeHandler(enrichContextWithHeaders(headersToPass, headersToLog, ctx.ParseCtx(infoHandler, ctx.HeaderUUIDAPI)), bucketRequestTimes))) 22 r.HandleFunc(config.Config.Prefix+"/info", httputil.TrackConnections(httputil.TimeHandler(enrichContextWithHeaders(headersToPass, headersToLog, ctx.ParseCtx(infoHandler, ctx.HeaderUUIDAPI)), bucketRequestTimes))) 23 24 r.HandleFunc(config.Config.Prefix+"/lb_check", lbcheckHandler) 25 26 r.HandleFunc(config.Config.Prefix+"/version", versionHandler) 27 r.HandleFunc(config.Config.Prefix+"/version/", versionHandler) 28 29 r.HandleFunc(config.Config.Prefix+"/functions", enrichContextWithHeaders(headersToPass, headersToLog, functionsHandler)) 30 r.HandleFunc(config.Config.Prefix+"/functions/", enrichContextWithHeaders(headersToPass, headersToLog, functionsHandler)) 31 32 r.HandleFunc(config.Config.Prefix+"/tags", enrichContextWithHeaders(headersToPass, headersToLog, tagHandler)) 33 r.HandleFunc(config.Config.Prefix+"/tags/", enrichContextWithHeaders(headersToPass, headersToLog, tagHandler)) 34 35 r.HandleFunc(config.Config.Prefix+"/_internal/capabilities", enrichContextWithHeaders(headersToPass, headersToLog, capabilityHandler)) 36 r.HandleFunc(config.Config.Prefix+"/_internal/capabilities/", enrichContextWithHeaders(headersToPass, headersToLog, capabilityHandler)) 37 38 r.HandleFunc(config.Config.Prefix+"/", enrichContextWithHeaders(headersToPass, headersToLog, usageHandler)) 39 40 if config.Config.Expvar.Enabled { 41 if config.Config.Expvar.Listen == "" || config.Config.Expvar.Listen == config.Config.Listen { 42 r.HandleFunc(config.Config.Prefix+"/debug/vars", expvar.Handler().ServeHTTP) 43 if config.Config.Expvar.PProfEnabled { 44 r.HandleFunc(config.Config.Prefix+"/debug/pprof/heap", pprof.Index) 45 r.HandleFunc(config.Config.Prefix+"/debug/pprof/profile", pprof.Profile) 46 r.HandleFunc(config.Config.Prefix+"/debug/pprof/symbol", pprof.Symbol) 47 r.HandleFunc(config.Config.Prefix+"/debug/pprof/trace", pprof.Trace) 48 } 49 } 50 } 51 return r 52} 53