github.com/go-graphite/carbonapi@v0.17.0/cmd/carbonapi/http/init.go (about)

     1  package http
     2  
     3  import (
     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  
    13  func 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+"/metrics/expand/", httputil.TrackConnections(httputil.TimeHandler(enrichContextWithHeaders(headersToPass, headersToLog, ctx.ParseCtx(expandHandler, ctx.HeaderUUIDAPI)), bucketRequestTimes)))
    22  	r.HandleFunc(config.Config.Prefix+"/metrics/expand", httputil.TrackConnections(httputil.TimeHandler(enrichContextWithHeaders(headersToPass, headersToLog, ctx.ParseCtx(expandHandler, ctx.HeaderUUIDAPI)), bucketRequestTimes)))
    23  
    24  	r.HandleFunc(config.Config.Prefix+"/info/", httputil.TrackConnections(httputil.TimeHandler(enrichContextWithHeaders(headersToPass, headersToLog, ctx.ParseCtx(infoHandler, ctx.HeaderUUIDAPI)), bucketRequestTimes)))
    25  	r.HandleFunc(config.Config.Prefix+"/info", httputil.TrackConnections(httputil.TimeHandler(enrichContextWithHeaders(headersToPass, headersToLog, ctx.ParseCtx(infoHandler, ctx.HeaderUUIDAPI)), bucketRequestTimes)))
    26  
    27  	r.HandleFunc(config.Config.Prefix+"/lb_check", lbcheckHandler)
    28  
    29  	r.HandleFunc(config.Config.Prefix+"/version", versionHandler)
    30  	r.HandleFunc(config.Config.Prefix+"/version/", versionHandler)
    31  
    32  	r.HandleFunc(config.Config.Prefix+"/functions", enrichContextWithHeaders(headersToPass, headersToLog, functionsHandler))
    33  	r.HandleFunc(config.Config.Prefix+"/functions/", enrichContextWithHeaders(headersToPass, headersToLog, functionsHandler))
    34  
    35  	r.HandleFunc(config.Config.Prefix+"/tags", enrichContextWithHeaders(headersToPass, headersToLog, tagHandler))
    36  	r.HandleFunc(config.Config.Prefix+"/tags/", enrichContextWithHeaders(headersToPass, headersToLog, tagHandler))
    37  
    38  	r.HandleFunc(config.Config.Prefix+"/_internal/capabilities", enrichContextWithHeaders(headersToPass, headersToLog, capabilityHandler))
    39  	r.HandleFunc(config.Config.Prefix+"/_internal/capabilities/", enrichContextWithHeaders(headersToPass, headersToLog, capabilityHandler))
    40  
    41  	r.HandleFunc(config.Config.Prefix+"/", enrichContextWithHeaders(headersToPass, headersToLog, usageHandler))
    42  
    43  	if config.Config.Expvar.Enabled {
    44  		if config.Config.Expvar.Listen == "" || config.Config.Expvar.Listen == config.Config.Listen {
    45  			r.HandleFunc(config.Config.Prefix+"/debug/vars", expvar.Handler().ServeHTTP)
    46  			if config.Config.Expvar.PProfEnabled {
    47  				r.HandleFunc(config.Config.Prefix+"/debug/pprof/heap", pprof.Index)
    48  				r.HandleFunc(config.Config.Prefix+"/debug/pprof/profile", pprof.Profile)
    49  				r.HandleFunc(config.Config.Prefix+"/debug/pprof/symbol", pprof.Symbol)
    50  				r.HandleFunc(config.Config.Prefix+"/debug/pprof/trace", pprof.Trace)
    51  			}
    52  		}
    53  	}
    54  	return r
    55  }