@@ -10,6 +10,8 @@ import (
10
10
11
11
"github.com/dustin/go-humanize"
12
12
"github.com/google/uuid"
13
+ "github.com/prometheus/client_golang/prometheus"
14
+ "github.com/prometheus/client_golang/prometheus/promauto"
13
15
"golang.org/x/sync/errgroup"
14
16
"golang.org/x/xerrors"
15
17
@@ -39,6 +41,13 @@ type Executor struct {
39
41
statsCh chan <- Stats
40
42
// NotificationsEnqueuer handles enqueueing notifications for delivery by SMTP, webhook, etc.
41
43
notificationsEnqueuer notifications.Enqueuer
44
+ reg prometheus.Registerer
45
+
46
+ metrics executorMetrics
47
+ }
48
+
49
+ type executorMetrics struct {
50
+ autobuildExecutionDuration prometheus.Histogram
42
51
}
43
52
44
53
// Stats contains information about one run of Executor.
@@ -49,7 +58,8 @@ type Stats struct {
49
58
}
50
59
51
60
// New returns a new wsactions executor.
52
- func NewExecutor (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
+ func NewExecutor (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 )
53
63
le := & Executor {
54
64
//nolint:gocritic // Autostart has a limited set of permissions.
55
65
ctx : dbauthz .AsAutostart (ctx ),
@@ -61,6 +71,16 @@ func NewExecutor(ctx context.Context, db database.Store, ps pubsub.Pubsub, tss *
61
71
auditor : auditor ,
62
72
accessControlStore : acs ,
63
73
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
+ },
64
84
}
65
85
return le
66
86
}
@@ -86,6 +106,7 @@ func (e *Executor) Run() {
86
106
return
87
107
}
88
108
stats := e .runOnce (t )
109
+ e .metrics .autobuildExecutionDuration .Observe (stats .Elapsed .Seconds ())
89
110
if e .statsCh != nil {
90
111
select {
91
112
case <- e .ctx .Done ():
0 commit comments