MCPcopy Index your code
hub / github.com/coder/coder / WithProfilingLabels

Function WithProfilingLabels

coderd/httpmw/pprof.go:14–30  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

12// primarily used to determine if load is coming from background jobs, or from
13// http traffic.
14func 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
32func WithStaticProfilingLabels(labels pprof.LabelSet) func(next http.Handler) http.Handler {
33 return func(next http.Handler) http.Handler {

Callers

nothing calls this directly

Calls 6

ServiceFunction · 0.92
WithContextMethod · 0.80
ContextMethod · 0.65
GetMethod · 0.65
DoMethod · 0.65
ServeHTTPMethod · 0.45

Tested by

no test coverage detected