Skip to content

Commit 0a3afed

Browse files
authored
chore: add more pprof labels for various go routines (#19243)
- ReplicaSync - Notifications - MetricsAggregator - DBPurge
1 parent c65996a commit 0a3afed

File tree

5 files changed

+25
-14
lines changed

5 files changed

+25
-14
lines changed

coderd/database/dbpurge/dbpurge.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/coder/coder/v2/coderd/database"
1313
"github.com/coder/coder/v2/coderd/database/dbauthz"
1414
"github.com/coder/coder/v2/coderd/database/dbtime"
15+
"github.com/coder/coder/v2/coderd/pproflabel"
1516
"github.com/coder/quartz"
1617
)
1718

@@ -38,7 +39,7 @@ func New(ctx context.Context, logger slog.Logger, db database.Store, clk quartz.
3839

3940
// Start the ticker with the initial delay.
4041
ticker := clk.NewTicker(delay)
41-
doTick := func(start time.Time) {
42+
doTick := func(ctx context.Context, start time.Time) {
4243
defer ticker.Reset(delay)
4344
// Start a transaction to grab advisory lock, we don't want to run
4445
// multiple purges at the same time (multiple replicas).
@@ -85,21 +86,21 @@ func New(ctx context.Context, logger slog.Logger, db database.Store, clk quartz.
8586
}
8687
}
8788

88-
go func() {
89+
pproflabel.Go(ctx, pproflabel.Service(pproflabel.ServiceDBPurge), func(ctx context.Context) {
8990
defer close(closed)
9091
defer ticker.Stop()
9192
// Force an initial tick.
92-
doTick(dbtime.Time(clk.Now()).UTC())
93+
doTick(ctx, dbtime.Time(clk.Now()).UTC())
9394
for {
9495
select {
9596
case <-ctx.Done():
9697
return
9798
case tick := <-ticker.C:
9899
ticker.Stop()
99-
doTick(dbtime.Time(tick).UTC())
100+
doTick(ctx, dbtime.Time(tick).UTC())
100101
}
101102
}
102-
}()
103+
})
103104
return &instance{
104105
cancel: cancelFunc,
105106
closed: closed,

coderd/notifications/manager.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@ import (
1111
"golang.org/x/xerrors"
1212

1313
"cdr.dev/slog"
14-
"github.com/coder/quartz"
1514

1615
"github.com/coder/coder/v2/coderd/database"
1716
"github.com/coder/coder/v2/coderd/database/pubsub"
1817
"github.com/coder/coder/v2/coderd/notifications/dispatch"
18+
"github.com/coder/coder/v2/coderd/pproflabel"
1919
"github.com/coder/coder/v2/codersdk"
20+
"github.com/coder/quartz"
2021
)
2122

2223
var ErrInvalidDispatchTimeout = xerrors.New("dispatch timeout must be less than lease period")
@@ -145,7 +146,7 @@ func (m *Manager) Run(ctx context.Context) {
145146

146147
m.runOnce.Do(func() {
147148
// Closes when Stop() is called or context is canceled.
148-
go func() {
149+
pproflabel.Go(ctx, pproflabel.Service(pproflabel.ServiceNotifications), func(ctx context.Context) {
149150
err := m.loop(ctx)
150151
if err != nil {
151152
if xerrors.Is(err, ErrManagerAlreadyClosed) {
@@ -154,7 +155,7 @@ func (m *Manager) Run(ctx context.Context) {
154155
m.log.Error(ctx, "notification manager stopped with error", slog.Error(err))
155156
}
156157
}
157-
}()
158+
})
158159
})
159160
}
160161

coderd/pproflabel/pproflabel.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,17 @@ const (
2121

2222
ServiceHTTPServer = "http-api"
2323
ServiceLifecycles = "lifecycle-executor"
24-
ServiceMetricCollector = "metrics-collector"
2524
ServicePrebuildReconciler = "prebuilds-reconciler"
2625
ServiceTerraformProvisioner = "terraform-provisioner"
26+
ServiceDBPurge = "db-purge"
27+
ServiceNotifications = "notifications"
28+
ServiceReplicaSync = "replica-sync"
29+
// ServiceMetricCollector collects metrics from insights in the database and
30+
// exports them in a prometheus collector format.
31+
ServiceMetricCollector = "metrics-collector"
32+
// ServiceAgentMetricAggregator merges agent metrics and exports them in a
33+
// prometheus collector format.
34+
ServiceAgentMetricAggregator = "agent-metrics-aggregator"
2735

2836
RequestTypeTag = "coder_request_type"
2937
)

coderd/prometheusmetrics/aggregator.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ import (
1111
"github.com/prometheus/common/model"
1212
"golang.org/x/xerrors"
1313

14-
"github.com/coder/coder/v2/coderd/agentmetrics"
15-
1614
"cdr.dev/slog"
1715

1816
agentproto "github.com/coder/coder/v2/agent/proto"
17+
"github.com/coder/coder/v2/coderd/agentmetrics"
18+
"github.com/coder/coder/v2/coderd/pproflabel"
1919
)
2020

2121
const (
@@ -298,7 +298,7 @@ func (ma *MetricsAggregator) Run(ctx context.Context) func() {
298298
done := make(chan struct{})
299299

300300
cleanupTicker := time.NewTicker(ma.metricsCleanupInterval)
301-
go func() {
301+
pproflabel.Go(ctx, pproflabel.Service(pproflabel.ServiceAgentMetricAggregator), func(ctx context.Context) {
302302
defer close(done)
303303
defer cleanupTicker.Stop()
304304

@@ -395,7 +395,7 @@ func (ma *MetricsAggregator) Run(ctx context.Context) func() {
395395
return
396396
}
397397
}
398-
}()
398+
})
399399
return func() {
400400
cancelFunc()
401401
<-done

enterprise/replicasync/replicasync.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"github.com/coder/coder/v2/coderd/database/dbauthz"
2424
"github.com/coder/coder/v2/coderd/database/dbtime"
2525
"github.com/coder/coder/v2/coderd/database/pubsub"
26+
"github.com/coder/coder/v2/coderd/pproflabel"
2627
)
2728

2829
var PubsubEvent = "replica"
@@ -104,7 +105,7 @@ func New(ctx context.Context, logger slog.Logger, db database.Store, ps pubsub.P
104105
return nil, xerrors.Errorf("subscribe: %w", err)
105106
}
106107
manager.closeWait.Add(1)
107-
go manager.loop(ctx)
108+
pproflabel.Go(ctx, pproflabel.Service(pproflabel.ServiceReplicaSync), manager.loop)
108109
return manager, nil
109110
}
110111

0 commit comments

Comments
 (0)