Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit34c46c0

Browse files
authored
chore: renameservice ->coder_service, removeagent_id label (#19241)
Pyroscope uses `service` tag for top level distinction. So move our`service` -> `coder_service`
1 parentb8851f0 commit34c46c0

File tree

4 files changed

+40
-14
lines changed

4 files changed

+40
-14
lines changed

‎coderd/coderd.go‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@ import (
1414
"net/url"
1515
"path/filepath"
1616
"regexp"
17+
"runtime/pprof"
1718
"strings"
1819
"sync"
1920
"sync/atomic"
2021
"time"
2122

2223
"github.com/coder/coder/v2/coderd/oauth2provider"
24+
"github.com/coder/coder/v2/coderd/pproflabel"
2325
"github.com/coder/coder/v2/coderd/prebuilds"
2426
"github.com/coder/coder/v2/coderd/wsbuilder"
2527

@@ -1340,7 +1342,13 @@ func New(options *Options) *API {
13401342
).Get("/connection",api.workspaceAgentConnectionGeneric)
13411343
r.Route("/me",func(r chi.Router) {
13421344
r.Use(workspaceAgentInfo)
1343-
r.Get("/rpc",api.workspaceAgentRPC)
1345+
r.Group(func(r chi.Router) {
1346+
r.Use(
1347+
// Override the request_type for agent rpc traffic.
1348+
httpmw.WithStaticProfilingLabels(pprof.Labels(pproflabel.RequestTypeTag,"agent-rpc")),
1349+
)
1350+
r.Get("/rpc",api.workspaceAgentRPC)
1351+
})
13441352
r.Patch("/logs",api.patchWorkspaceAgentLogs)
13451353
r.Patch("/app-status",api.patchWorkspaceAgentAppStatus)
13461354
// 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.ServiceHTTPServer,pproflabel.RequestTypeTag,requestType),func(ctx context.Context) {
2626
r=r.WithContext(ctx)
2727
next.ServeHTTP(rw,r)
2828
})
2929
})
3030
}
31+
32+
funcWithStaticProfilingLabels(labels pprof.LabelSet)func(next http.Handler) http.Handler {
33+
returnfunc(next http.Handler) http.Handler {
34+
returnhttp.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: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,22 @@ func Go(ctx context.Context, labels pprof.LabelSet, f func(context.Context)) {
1010
gopprof.Do(ctx,labels,f)
1111
}
1212

13+
funcDo(ctx context.Context,labels pprof.LabelSet,ffunc(context.Context)) {
14+
pprof.Do(ctx,labels,f)
15+
}
16+
1317
const (
14-
ServiceTag="service"
18+
// ServiceTag should not collide with the pyroscope built-in tag "service".
19+
// Use `coder_` to avoid collisions.
20+
ServiceTag="coder_service"
1521

1622
ServiceHTTPServer="http-api"
1723
ServiceLifecycles="lifecycle-executor"
1824
ServiceMetricCollector="metrics-collector"
1925
ServicePrebuildReconciler="prebuilds-reconciler"
2026
ServiceTerraformProvisioner="terraform-provisioner"
27+
28+
RequestTypeTag="coder_request_type"
2129
)
2230

2331
funcService(namestring,pairs...string) pprof.LabelSet {

‎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-
gopprof.Do(ctx,pprof.Labels("agent",m.workspaceAgent.ID.String()),
352-
func(ctx context.Context) {
353-
deferm.wg.Done()
354-
m.sendPings(ctx)
355-
})
356-
gopprof.Do(ctx,pprof.Labels("agent",m.workspaceAgent.ID.String()),
357-
func(ctx context.Context) {
358-
deferm.wg.Done()
359-
m.monitor(ctx)
360-
})
350+
gofunc(ctx context.Context) {
351+
deferm.wg.Done()
352+
m.sendPings(ctx)
353+
}(ctx)
354+
gofunc(ctx context.Context) {
355+
deferm.wg.Done()
356+
m.monitor(ctx)
357+
}(ctx)
361358
}
362359

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp