WithProfilingLabels adds a pprof label to all http request handlers. This is primarily used to determine if load is coming from background jobs, or from http traffic.
(next http.Handler)
| 12 | // primarily used to determine if load is coming from background jobs, or from |
| 13 | // http traffic. |
| 14 | func WithProfilingLabels(next http.Handler) http.Handler { |
| 15 | return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) { |
| 16 | ctx := r.Context() |
| 17 | |
| 18 | // Label to differentiate between http and websocket requests. Websocket requests |
| 19 | // are assumed to be long-lived and more resource consuming. |
| 20 | requestType := "http" |
| 21 | if r.Header.Get("Upgrade") == "websocket" { |
| 22 | requestType = "websocket" |
| 23 | } |
| 24 | |
| 25 | pprof.Do(ctx, pproflabel.Service(pproflabel.ServiceHTTPServer, pproflabel.RequestTypeTag, requestType), func(ctx context.Context) { |
| 26 | r = r.WithContext(ctx) |
| 27 | next.ServeHTTP(rw, r) |
| 28 | }) |
| 29 | }) |
| 30 | } |
| 31 | |
| 32 | func WithStaticProfilingLabels(labels pprof.LabelSet) func(next http.Handler) http.Handler { |
| 33 | return func(next http.Handler) http.Handler { |