Skip to content

chore: rename service -> coder_service, remove agent_id label #19241

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 7, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
chore: remove agent pprof label, rename server -> system
  • Loading branch information
Emyrk committed Aug 7, 2025
commit a70924aa71ecbe77ab818419ef9876a0a9965897
4 changes: 2 additions & 2 deletions cli/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1460,14 +1460,14 @@ func newProvisionerDaemon(
tracer := coderAPI.TracerProvider.Tracer(tracing.TracerName)
terraformClient, terraformServer := drpcsdk.MemTransportPipe()
wg.Add(1)
pproflabel.Go(ctx, pproflabel.Service(pproflabel.ServiceTerraformProvisioner), func(ctx context.Context) {
pproflabel.Go(ctx, pproflabel.Service(pproflabel.SystemTerraformProvisioner), func(ctx context.Context) {
defer wg.Done()
<-ctx.Done()
_ = terraformClient.Close()
_ = terraformServer.Close()
})
wg.Add(1)
pproflabel.Go(ctx, pproflabel.Service(pproflabel.ServiceTerraformProvisioner), func(ctx context.Context) {
pproflabel.Go(ctx, pproflabel.Service(pproflabel.SystemTerraformProvisioner), func(ctx context.Context) {
defer wg.Done()
defer cancel()

Expand Down
2 changes: 1 addition & 1 deletion coderd/autobuild/lifecycle_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func (e *Executor) WithStatsChannel(ch chan<- Stats) *Executor {
// tick from its channel. It will stop when its context is Done, or when
// its channel is closed.
func (e *Executor) Run() {
pproflabel.Go(e.ctx, pproflabel.Service(pproflabel.ServiceLifecycles), func(ctx context.Context) {
pproflabel.Go(e.ctx, pproflabel.Service(pproflabel.SystemLifecycles), func(ctx context.Context) {
for {
select {
case <-ctx.Done():
Expand Down
9 changes: 8 additions & 1 deletion coderd/coderd.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"net/url"
"path/filepath"
"regexp"
"runtime/pprof"
"strings"
"sync"
"sync/atomic"
Expand Down Expand Up @@ -1340,7 +1341,13 @@ func New(options *Options) *API {
).Get("/connection", api.workspaceAgentConnectionGeneric)
r.Route("/me", func(r chi.Router) {
r.Use(workspaceAgentInfo)
r.Get("/rpc", api.workspaceAgentRPC)
r.Group(func(r chi.Router) {
r.Use(
// Override the request_type for agent rpc traffic.
httpmw.WithStaticProfilingLabels(pprof.Labels("request_type", "agent_rpc")),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was pprof'd before, so doing this has the agent stuff in it's own group still.

)
r.Get("/rpc", api.workspaceAgentRPC)
})
r.Patch("/logs", api.patchWorkspaceAgentLogs)
r.Patch("/app-status", api.patchWorkspaceAgentAppStatus)
// Deprecated: Required to support legacy agents
Expand Down
15 changes: 14 additions & 1 deletion coderd/httpmw/pprof.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,22 @@ func WithProfilingLabels(next http.Handler) http.Handler {
requestType = "websocket"
}

pprof.Do(ctx, pproflabel.Service(pproflabel.ServiceHTTPServer, "request_type", requestType), func(ctx context.Context) {
pprof.Do(ctx, pproflabel.Service(pproflabel.SystemHTTPServer, "request_type", requestType), func(ctx context.Context) {
r = r.WithContext(ctx)
next.ServeHTTP(rw, r)
})
})
}

func WithStaticProfilingLabels(labels pprof.LabelSet) func(next http.Handler) http.Handler {
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
ctx := r.Context()

pprof.Do(ctx, labels, func(ctx context.Context) {
r = r.WithContext(ctx)
next.ServeHTTP(rw, r)
})
})
}
}
18 changes: 11 additions & 7 deletions coderd/pproflabel/pproflabel.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,20 @@ func Go(ctx context.Context, labels pprof.LabelSet, f func(context.Context)) {
go pprof.Do(ctx, labels, f)
}

func Do(ctx context.Context, labels pprof.LabelSet, f func(context.Context)) {
pprof.Do(ctx, labels, f)
}

const (
ServiceTag = "service"
SystemTag = "service"

ServiceHTTPServer = "http-api"
ServiceLifecycles = "lifecycle-executor"
ServiceMetricCollector = "metrics-collector"
ServicePrebuildReconciler = "prebuilds-reconciler"
ServiceTerraformProvisioner = "terraform-provisioner"
SystemHTTPServer = "http-api"
SystemLifecycles = "lifecycle-executor"
SystemMetricCollector = "metrics-collector"
SystemPrebuildReconciler = "prebuilds-reconciler"
SystemTerraformProvisioner = "terraform-provisioner"
)

func Service(name string, pairs ...string) pprof.LabelSet {
return pprof.Labels(append([]string{ServiceTag, name}, pairs...)...)
return pprof.Labels(append([]string{SystemTag, name}, pairs...)...)
}
2 changes: 1 addition & 1 deletion coderd/prometheusmetrics/insights/metricscollector.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func (mc *MetricsCollector) Run(ctx context.Context) (func(), error) {
})
}

pproflabel.Go(ctx, pproflabel.Service(pproflabel.ServiceMetricCollector), func(ctx context.Context) {
pproflabel.Go(ctx, pproflabel.Service(pproflabel.SystemMetricCollector), func(ctx context.Context) {
defer close(done)
defer ticker.Stop()
for {
Expand Down
19 changes: 8 additions & 11 deletions coderd/workspaceagentsrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"fmt"
"io"
"net/http"
"runtime/pprof"
"sync"
"sync/atomic"
"time"
Expand Down Expand Up @@ -348,16 +347,14 @@ func (m *agentConnectionMonitor) init() {
func (m *agentConnectionMonitor) start(ctx context.Context) {
ctx, m.cancel = context.WithCancel(ctx)
m.wg.Add(2)
go pprof.Do(ctx, pprof.Labels("agent", m.workspaceAgent.ID.String()),
func(ctx context.Context) {
defer m.wg.Done()
m.sendPings(ctx)
})
go pprof.Do(ctx, pprof.Labels("agent", m.workspaceAgent.ID.String()),
func(ctx context.Context) {
defer m.wg.Done()
m.monitor(ctx)
})
go func(ctx context.Context) {
defer m.wg.Done()
m.sendPings(ctx)
}(ctx)
go func(ctx context.Context) {
defer m.wg.Done()
m.monitor(ctx)
}(ctx)
}

func (m *agentConnectionMonitor) monitor(ctx context.Context) {
Expand Down
2 changes: 1 addition & 1 deletion enterprise/coderd/coderd.go
Original file line number Diff line number Diff line change
Expand Up @@ -905,7 +905,7 @@ func (api *API) updateEntitlements(ctx context.Context) error {
api.AGPL.PrebuildsReconciler.Store(&reconciler)
// TODO: Should this context be the api.ctx context? To cancel when
// the API (and entire app) is closed via shutdown?
pproflabel.Go(context.Background(), pproflabel.Service(pproflabel.ServicePrebuildReconciler), reconciler.Run)
pproflabel.Go(context.Background(), pproflabel.Service(pproflabel.SystemPrebuildReconciler), reconciler.Run)

api.AGPL.PrebuildsClaimer.Store(&claimer)
}
Expand Down
Loading