Skip to content

Commit 56f67a7

Browse files
committed
add label for websocket vs http
1 parent cb1ec21 commit 56f67a7

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

coderd/httpmw/pprof.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,15 @@ import (
1414
func WithProfilingLabels(next http.Handler) http.Handler {
1515
return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
1616
ctx := r.Context()
17-
pprof.Do(ctx, pproflabel.Service(pproflabel.ServiceHTTPServer), func(ctx context.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, "request_type", requestType), func(ctx context.Context) {
1826
r = r.WithContext(ctx)
1927
next.ServeHTTP(rw, r)
2028
})

coderd/pproflabel/pproflabel.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@ func Go(ctx context.Context, labels pprof.LabelSet, f func(context.Context)) {
1111
}
1212

1313
const (
14+
ServiceTag = "service"
15+
16+
ServiceHTTPServer = "http-api"
17+
ServiceLifecycles = "lifecycle-executor"
18+
ServiceMetricCollector = "metrics-collector"
19+
ServicePrebuildReconciler = "prebuilds-reconciler"
1420
ServiceTerraformProvisioner = "terraform-provisioner"
15-
ServiceMetricCollector = "metric-collector"
16-
ServiceLifecycles = "lifecycles"
17-
ServiceHTTPServer = "http-server"
18-
ServicePrebuildReconciler = "prebuild-reconciler"
1921
)
2022

21-
func Service(name string) pprof.LabelSet {
22-
return pprof.Labels("service", name)
23+
func Service(name string, pairs ...string) pprof.LabelSet {
24+
return pprof.Labels(append([]string{ServiceTag, name}, pairs...)...)
2325
}

enterprise/coderd/coderd.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -903,7 +903,8 @@ func (api *API) updateEntitlements(ctx context.Context) error {
903903
}
904904

905905
api.AGPL.PrebuildsReconciler.Store(&reconciler)
906-
// TODO: Should this context be the app context?
906+
// TODO: Should this context be the api.ctx context? To cancel when
907+
// the API (and entire app) is closed via shutdown?
907908
pproflabel.Go(context.Background(), pproflabel.Service(pproflabel.ServicePrebuildReconciler), reconciler.Run)
908909

909910
api.AGPL.PrebuildsClaimer.Store(&claimer)

0 commit comments

Comments
 (0)