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

Commit144d3f3

Browse files
authored
chore: record lifecycle duration metric to prometheus (#15279)
`autobuild_execution_duration_seconds` keeps track of how long autobuildtakes and exposes it via prometheus histogram
1 parentafacb07 commit144d3f3

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

‎cli/server.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1035,7 +1035,7 @@ func (r *RootCmd) Server(newAPI func(context.Context, *coderd.Options) (*coderd.
10351035
autobuildTicker:=time.NewTicker(vals.AutobuildPollInterval.Value())
10361036
deferautobuildTicker.Stop()
10371037
autobuildExecutor:=autobuild.NewExecutor(
1038-
ctx,options.Database,options.Pubsub,coderAPI.TemplateScheduleStore,&coderAPI.Auditor,coderAPI.AccessControlStore,logger,autobuildTicker.C,options.NotificationsEnqueuer)
1038+
ctx,options.Database,options.Pubsub,options.PrometheusRegistry,coderAPI.TemplateScheduleStore,&coderAPI.Auditor,coderAPI.AccessControlStore,logger,autobuildTicker.C,options.NotificationsEnqueuer)
10391039
autobuildExecutor.Run()
10401040

10411041
hangDetectorTicker:=time.NewTicker(vals.JobHangDetectorInterval.Value())

‎coderd/autobuild/lifecycle_executor.go‎

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import (
1010

1111
"github.com/dustin/go-humanize"
1212
"github.com/google/uuid"
13+
"github.com/prometheus/client_golang/prometheus"
14+
"github.com/prometheus/client_golang/prometheus/promauto"
1315
"golang.org/x/sync/errgroup"
1416
"golang.org/x/xerrors"
1517

@@ -39,6 +41,13 @@ type Executor struct {
3941
statsChchan<-Stats
4042
// NotificationsEnqueuer handles enqueueing notifications for delivery by SMTP, webhook, etc.
4143
notificationsEnqueuer notifications.Enqueuer
44+
reg prometheus.Registerer
45+
46+
metricsexecutorMetrics
47+
}
48+
49+
typeexecutorMetricsstruct {
50+
autobuildExecutionDuration prometheus.Histogram
4251
}
4352

4453
// Stats contains information about one run of Executor.
@@ -49,7 +58,8 @@ type Stats struct {
4958
}
5059

5160
// New returns a new wsactions executor.
52-
funcNewExecutor(ctx context.Context,db database.Store,ps pubsub.Pubsub,tss*atomic.Pointer[schedule.TemplateScheduleStore],auditor*atomic.Pointer[audit.Auditor],acs*atomic.Pointer[dbauthz.AccessControlStore],log slog.Logger,tick<-chan time.Time,enqueuer notifications.Enqueuer)*Executor {
61+
funcNewExecutor(ctx context.Context,db database.Store,ps pubsub.Pubsub,reg prometheus.Registerer,tss*atomic.Pointer[schedule.TemplateScheduleStore],auditor*atomic.Pointer[audit.Auditor],acs*atomic.Pointer[dbauthz.AccessControlStore],log slog.Logger,tick<-chan time.Time,enqueuer notifications.Enqueuer)*Executor {
62+
factory:=promauto.With(reg)
5363
le:=&Executor{
5464
//nolint:gocritic // Autostart has a limited set of permissions.
5565
ctx:dbauthz.AsAutostart(ctx),
@@ -61,6 +71,16 @@ func NewExecutor(ctx context.Context, db database.Store, ps pubsub.Pubsub, tss *
6171
auditor:auditor,
6272
accessControlStore:acs,
6373
notificationsEnqueuer:enqueuer,
74+
reg:reg,
75+
metrics:executorMetrics{
76+
autobuildExecutionDuration:factory.NewHistogram(prometheus.HistogramOpts{
77+
Namespace:"coderd",
78+
Subsystem:"lifecycle",
79+
Name:"autobuild_execution_duration_seconds",
80+
Help:"Duration of each autobuild execution.",
81+
Buckets:prometheus.DefBuckets,
82+
}),
83+
},
6484
}
6585
returnle
6686
}
@@ -86,6 +106,7 @@ func (e *Executor) Run() {
86106
return
87107
}
88108
stats:=e.runOnce(t)
109+
e.metrics.autobuildExecutionDuration.Observe(stats.Elapsed.Seconds())
89110
ife.statsCh!=nil {
90111
select {
91112
case<-e.ctx.Done():

‎coderd/coderdtest/coderdtest.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ func NewOptions(t testing.TB, options *Options) (func(http.Handler), context.Can
335335
ctx,
336336
options.Database,
337337
options.Pubsub,
338+
prometheus.NewRegistry(),
338339
&templateScheduleStore,
339340
&auditor,
340341
accessControlStore,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp