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

Commit0a3afed

Browse files
authored
chore: add more pprof labels for various go routines (#19243)
- ReplicaSync- Notifications- MetricsAggregator- DBPurge
1 parentc65996a commit0a3afed

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
deferticker.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-
gofunc() {
89+
pproflabel.Go(ctx,pproflabel.Service(pproflabel.ServiceDBPurge),func(ctx context.Context) {
8990
deferclose(closed)
9091
deferticker.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
casetick:=<-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
varErrInvalidDispatchTimeout=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-
gofunc() {
149+
pproflabel.Go(ctx,pproflabel.Service(pproflabel.ServiceNotifications),func(ctx context.Context) {
149150
err:=m.loop(ctx)
150151
iferr!=nil {
151152
ifxerrors.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(chanstruct{})
299299

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

@@ -395,7 +395,7 @@ func (ma *MetricsAggregator) Run(ctx context.Context) func() {
395395
return
396396
}
397397
}
398-
}()
398+
})
399399
returnfunc() {
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
varPubsubEvent="replica"
@@ -104,7 +105,7 @@ func New(ctx context.Context, logger slog.Logger, db database.Store, ps pubsub.P
104105
returnnil,xerrors.Errorf("subscribe: %w",err)
105106
}
106107
manager.closeWait.Add(1)
107-
gomanager.loop(ctx)
108+
pproflabel.Go(ctx,pproflabel.Service(pproflabel.ServiceReplicaSync),manager.loop)
108109
returnmanager,nil
109110
}
110111

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp