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