Skip to content

Commit a70924a

Browse files
committed
chore: remove agent pprof label, rename server -> system
1 parent 8ba8b4f commit a70924a

File tree

8 files changed

+46
-25
lines changed

8 files changed

+46
-25
lines changed

cli/server.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1460,14 +1460,14 @@ func newProvisionerDaemon(
14601460
tracer := coderAPI.TracerProvider.Tracer(tracing.TracerName)
14611461
terraformClient, terraformServer := drpcsdk.MemTransportPipe()
14621462
wg.Add(1)
1463-
pproflabel.Go(ctx, pproflabel.Service(pproflabel.ServiceTerraformProvisioner), func(ctx context.Context) {
1463+
pproflabel.Go(ctx, pproflabel.Service(pproflabel.SystemTerraformProvisioner), func(ctx context.Context) {
14641464
defer wg.Done()
14651465
<-ctx.Done()
14661466
_ = terraformClient.Close()
14671467
_ = terraformServer.Close()
14681468
})
14691469
wg.Add(1)
1470-
pproflabel.Go(ctx, pproflabel.Service(pproflabel.ServiceTerraformProvisioner), func(ctx context.Context) {
1470+
pproflabel.Go(ctx, pproflabel.Service(pproflabel.SystemTerraformProvisioner), func(ctx context.Context) {
14711471
defer wg.Done()
14721472
defer cancel()
14731473

coderd/autobuild/lifecycle_executor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ func (e *Executor) WithStatsChannel(ch chan<- Stats) *Executor {
108108
// tick from its channel. It will stop when its context is Done, or when
109109
// its channel is closed.
110110
func (e *Executor) Run() {
111-
pproflabel.Go(e.ctx, pproflabel.Service(pproflabel.ServiceLifecycles), func(ctx context.Context) {
111+
pproflabel.Go(e.ctx, pproflabel.Service(pproflabel.SystemLifecycles), func(ctx context.Context) {
112112
for {
113113
select {
114114
case <-ctx.Done():

coderd/coderd.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"net/url"
1515
"path/filepath"
1616
"regexp"
17+
"runtime/pprof"
1718
"strings"
1819
"sync"
1920
"sync/atomic"
@@ -1340,7 +1341,13 @@ func New(options *Options) *API {
13401341
).Get("/connection", api.workspaceAgentConnectionGeneric)
13411342
r.Route("/me", func(r chi.Router) {
13421343
r.Use(workspaceAgentInfo)
1343-
r.Get("/rpc", api.workspaceAgentRPC)
1344+
r.Group(func(r chi.Router) {
1345+
r.Use(
1346+
// Override the request_type for agent rpc traffic.
1347+
httpmw.WithStaticProfilingLabels(pprof.Labels("request_type", "agent_rpc")),
1348+
)
1349+
r.Get("/rpc", api.workspaceAgentRPC)
1350+
})
13441351
r.Patch("/logs", api.patchWorkspaceAgentLogs)
13451352
r.Patch("/app-status", api.patchWorkspaceAgentAppStatus)
13461353
// Deprecated: Required to support legacy agents

coderd/httpmw/pprof.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,22 @@ func WithProfilingLabels(next http.Handler) http.Handler {
2222
requestType = "websocket"
2323
}
2424

25-
pprof.Do(ctx, pproflabel.Service(pproflabel.ServiceHTTPServer, "request_type", requestType), func(ctx context.Context) {
25+
pprof.Do(ctx, pproflabel.Service(pproflabel.SystemHTTPServer, "request_type", requestType), func(ctx context.Context) {
2626
r = r.WithContext(ctx)
2727
next.ServeHTTP(rw, r)
2828
})
2929
})
3030
}
31+
32+
func WithStaticProfilingLabels(labels pprof.LabelSet) func(next http.Handler) http.Handler {
33+
return func(next http.Handler) http.Handler {
34+
return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
35+
ctx := r.Context()
36+
37+
pprof.Do(ctx, labels, func(ctx context.Context) {
38+
r = r.WithContext(ctx)
39+
next.ServeHTTP(rw, r)
40+
})
41+
})
42+
}
43+
}

coderd/pproflabel/pproflabel.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,20 @@ func Go(ctx context.Context, labels pprof.LabelSet, f func(context.Context)) {
1010
go pprof.Do(ctx, labels, f)
1111
}
1212

13+
func Do(ctx context.Context, labels pprof.LabelSet, f func(context.Context)) {
14+
pprof.Do(ctx, labels, f)
15+
}
16+
1317
const (
14-
ServiceTag = "service"
18+
SystemTag = "service"
1519

16-
ServiceHTTPServer = "http-api"
17-
ServiceLifecycles = "lifecycle-executor"
18-
ServiceMetricCollector = "metrics-collector"
19-
ServicePrebuildReconciler = "prebuilds-reconciler"
20-
ServiceTerraformProvisioner = "terraform-provisioner"
20+
SystemHTTPServer = "http-api"
21+
SystemLifecycles = "lifecycle-executor"
22+
SystemMetricCollector = "metrics-collector"
23+
SystemPrebuildReconciler = "prebuilds-reconciler"
24+
SystemTerraformProvisioner = "terraform-provisioner"
2125
)
2226

2327
func Service(name string, pairs ...string) pprof.LabelSet {
24-
return pprof.Labels(append([]string{ServiceTag, name}, pairs...)...)
28+
return pprof.Labels(append([]string{SystemTag, name}, pairs...)...)
2529
}

coderd/prometheusmetrics/insights/metricscollector.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ func (mc *MetricsCollector) Run(ctx context.Context) (func(), error) {
159159
})
160160
}
161161

162-
pproflabel.Go(ctx, pproflabel.Service(pproflabel.ServiceMetricCollector), func(ctx context.Context) {
162+
pproflabel.Go(ctx, pproflabel.Service(pproflabel.SystemMetricCollector), func(ctx context.Context) {
163163
defer close(done)
164164
defer ticker.Stop()
165165
for {

coderd/workspaceagentsrpc.go

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"fmt"
77
"io"
88
"net/http"
9-
"runtime/pprof"
109
"sync"
1110
"sync/atomic"
1211
"time"
@@ -348,16 +347,14 @@ func (m *agentConnectionMonitor) init() {
348347
func (m *agentConnectionMonitor) start(ctx context.Context) {
349348
ctx, m.cancel = context.WithCancel(ctx)
350349
m.wg.Add(2)
351-
go pprof.Do(ctx, pprof.Labels("agent", m.workspaceAgent.ID.String()),
352-
func(ctx context.Context) {
353-
defer m.wg.Done()
354-
m.sendPings(ctx)
355-
})
356-
go pprof.Do(ctx, pprof.Labels("agent", m.workspaceAgent.ID.String()),
357-
func(ctx context.Context) {
358-
defer m.wg.Done()
359-
m.monitor(ctx)
360-
})
350+
go func(ctx context.Context) {
351+
defer m.wg.Done()
352+
m.sendPings(ctx)
353+
}(ctx)
354+
go func(ctx context.Context) {
355+
defer m.wg.Done()
356+
m.monitor(ctx)
357+
}(ctx)
361358
}
362359

363360
func (m *agentConnectionMonitor) monitor(ctx context.Context) {

enterprise/coderd/coderd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -905,7 +905,7 @@ func (api *API) updateEntitlements(ctx context.Context) error {
905905
api.AGPL.PrebuildsReconciler.Store(&reconciler)
906906
// TODO: Should this context be the api.ctx context? To cancel when
907907
// the API (and entire app) is closed via shutdown?
908-
pproflabel.Go(context.Background(), pproflabel.Service(pproflabel.ServicePrebuildReconciler), reconciler.Run)
908+
pproflabel.Go(context.Background(), pproflabel.Service(pproflabel.SystemPrebuildReconciler), reconciler.Run)
909909

910910
api.AGPL.PrebuildsClaimer.Store(&claimer)
911911
}

0 commit comments

Comments
 (0)