mirror of
https://github.com/coder/coder.git
synced 2026-06-03 04:58:23 +00:00
chore: add more pprof labels for various go routines (#19243)
- ReplicaSync - Notifications - MetricsAggregator - DBPurge
This commit is contained in:
@@ -12,6 +12,7 @@ import (
|
||||
"github.com/coder/coder/v2/coderd/database"
|
||||
"github.com/coder/coder/v2/coderd/database/dbauthz"
|
||||
"github.com/coder/coder/v2/coderd/database/dbtime"
|
||||
"github.com/coder/coder/v2/coderd/pproflabel"
|
||||
"github.com/coder/quartz"
|
||||
)
|
||||
|
||||
@@ -38,7 +39,7 @@ func New(ctx context.Context, logger slog.Logger, db database.Store, clk quartz.
|
||||
|
||||
// Start the ticker with the initial delay.
|
||||
ticker := clk.NewTicker(delay)
|
||||
doTick := func(start time.Time) {
|
||||
doTick := func(ctx context.Context, start time.Time) {
|
||||
defer ticker.Reset(delay)
|
||||
// Start a transaction to grab advisory lock, we don't want to run
|
||||
// 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.
|
||||
}
|
||||
}
|
||||
|
||||
go func() {
|
||||
pproflabel.Go(ctx, pproflabel.Service(pproflabel.ServiceDBPurge), func(ctx context.Context) {
|
||||
defer close(closed)
|
||||
defer ticker.Stop()
|
||||
// Force an initial tick.
|
||||
doTick(dbtime.Time(clk.Now()).UTC())
|
||||
doTick(ctx, dbtime.Time(clk.Now()).UTC())
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return
|
||||
case tick := <-ticker.C:
|
||||
ticker.Stop()
|
||||
doTick(dbtime.Time(tick).UTC())
|
||||
doTick(ctx, dbtime.Time(tick).UTC())
|
||||
}
|
||||
}
|
||||
}()
|
||||
})
|
||||
return &instance{
|
||||
cancel: cancelFunc,
|
||||
closed: closed,
|
||||
|
||||
Reference in New Issue
Block a user