@@ -128,7 +128,7 @@ func Users(ctx context.Context, logger slog.Logger, clk quartz.Clock, registerer
128
128
}
129
129
130
130
// Workspaces tracks the total number of workspaces with labels on status.
131
- func Workspaces (ctx context.Context ,logger slog.Logger ,registerer prometheus.Registerer ,db database.Store ,duration time.Duration ) (func (),UpdateWorkspaceTimingMetricsFn , error ) {
131
+ func Workspaces (ctx context.Context ,logger slog.Logger ,registerer prometheus.Registerer ,db database.Store ,duration time.Duration ) (func (),error ) {
132
132
if duration == 0 {
133
133
duration = defaultRefreshRate
134
134
}
@@ -143,7 +143,7 @@ func Workspaces(ctx context.Context, logger slog.Logger, registerer prometheus.R
143
143
Help :"DEPRECATED: use coderd_api_workspace_latest_build instead" ,
144
144
}, []string {"status" })
145
145
if err := registerer .Register (workspaceLatestBuildTotalsDeprecated );err != nil {
146
- return nil ,nil , err
146
+ return nil ,err
147
147
}
148
148
149
149
workspaceLatestBuildTotals := prometheus .NewGaugeVec (prometheus.GaugeOpts {
@@ -153,7 +153,7 @@ func Workspaces(ctx context.Context, logger slog.Logger, registerer prometheus.R
153
153
Help :"The current number of workspace builds by status for all non-deleted workspaces." ,
154
154
}, []string {"status" })
155
155
if err := registerer .Register (workspaceLatestBuildTotals );err != nil {
156
- return nil ,nil , err
156
+ return nil ,err
157
157
}
158
158
159
159
workspaceLatestBuildStatuses := prometheus .NewGaugeVec (prometheus.GaugeOpts {
@@ -162,7 +162,7 @@ func Workspaces(ctx context.Context, logger slog.Logger, registerer prometheus.R
162
162
Help :"The current workspace statuses by template, transition, and owner for all non-deleted workspaces." ,
163
163
}, []string {"status" ,"template_name" ,"template_version" ,"workspace_owner" ,"workspace_transition" })
164
164
if err := registerer .Register (workspaceLatestBuildStatuses );err != nil {
165
- return nil ,nil , err
165
+ return nil ,err
166
166
}
167
167
168
168
workspaceCreationTotal := prometheus .NewCounterVec (
@@ -175,65 +175,7 @@ func Workspaces(ctx context.Context, logger slog.Logger, registerer prometheus.R
175
175
[]string {"organization_name" ,"template_name" ,"preset_name" },
176
176
)
177
177
if err := registerer .Register (workspaceCreationTotal );err != nil {
178
- return nil ,nil ,err
179
- }
180
-
181
- workspaceCreationTimings := prometheus .NewHistogramVec (prometheus.HistogramOpts {
182
- Namespace :"coderd" ,
183
- Subsystem :"" ,
184
- Name :"workspace_creation_duration_seconds" ,
185
- Help :"Time to create a workspace by organization, template, preset, and type (regular or prebuild)." ,
186
- Buckets : []float64 {
187
- 1 ,// 1s
188
- 10 ,
189
- 30 ,
190
- 60 ,// 1min
191
- 60 * 5 ,
192
- 60 * 10 ,
193
- 60 * 30 ,// 30min
194
- 60 * 60 ,// 1hr
195
- },
196
- NativeHistogramBucketFactor :1.1 ,
197
- // Max number of native buckets kept at once to bound memory.
198
- NativeHistogramMaxBucketNumber :100 ,
199
- // Merge/flush small buckets periodically to control churn.
200
- NativeHistogramMinResetDuration :time .Hour ,
201
- // Treat tiny values as zero (helps with noisy near-zero latencies).
202
- NativeHistogramZeroThreshold :0 ,
203
- NativeHistogramMaxZeroThreshold :0 ,
204
- }, []string {"organization_name" ,"template_name" ,"preset_name" ,"type" })
205
- if err := registerer .Register (workspaceCreationTimings );err != nil {
206
- return nil ,nil ,err
207
- }
208
-
209
- workspaceClaimTimings := prometheus .NewHistogramVec (prometheus.HistogramOpts {
210
- Namespace :"coderd" ,
211
- Subsystem :"" ,
212
- Name :"prebuilt_workspace_claim_duration_seconds" ,
213
- Help :"Time to claim a prebuilt workspace by organization, template, and preset." ,
214
- Buckets : []float64 {
215
- 1 ,// 1s
216
- 5 ,
217
- 10 ,
218
- 20 ,
219
- 30 ,
220
- 60 ,// 1m
221
- 120 ,// 2m
222
- 180 ,// 3m
223
- 240 ,// 4m
224
- 300 ,// 5m
225
- },
226
- NativeHistogramBucketFactor :1.1 ,
227
- // Max number of native buckets kept at once to bound memory.
228
- NativeHistogramMaxBucketNumber :100 ,
229
- // Merge/flush small buckets periodically to control churn.
230
- NativeHistogramMinResetDuration :time .Hour ,
231
- // Treat tiny values as zero (helps with noisy near-zero latencies).
232
- NativeHistogramZeroThreshold :0 ,
233
- NativeHistogramMaxZeroThreshold :0 ,
234
- }, []string {"organization_name" ,"template_name" ,"preset_name" })
235
- if err := registerer .Register (workspaceClaimTimings );err != nil {
236
- return nil ,nil ,err
178
+ return nil ,err
237
179
}
238
180
239
181
ctx ,cancelFunc := context .WithCancel (ctx )
@@ -318,71 +260,7 @@ func Workspaces(ctx context.Context, logger slog.Logger, registerer prometheus.R
318
260
return func () {
319
261
cancelFunc ()
320
262
<- done
321
- },updateWorkspaceTimingsMetrics (workspaceCreationTimings ,workspaceClaimTimings ),nil
322
- }
323
-
324
- type WorkspaceTimingType int
325
-
326
- const (
327
- Unsupported WorkspaceTimingType = iota
328
- WorkspaceCreation
329
- PrebuildCreation
330
- PrebuildClaim
331
- )
332
-
333
- const (
334
- workspaceTypeRegular = "regular"
335
- workspaceTypePrebuild = "prebuild"
336
- )
337
-
338
- type UpdateWorkspaceTimingMetricsFn func (
339
- workspaceTimingType WorkspaceTimingType ,
340
- organizationName string ,
341
- templateName string ,
342
- presetName string ,
343
- buildTime float64 ,
344
- )
345
-
346
- func GetTimingType (isPrebuild bool ,isClaim bool ,isWorkspaceFirstBuild bool )WorkspaceTimingType {
347
- switch {
348
- case isPrebuild :
349
- return PrebuildCreation
350
- case isClaim :
351
- return PrebuildClaim
352
- case isWorkspaceFirstBuild :
353
- return WorkspaceCreation
354
- default :
355
- return Unsupported
356
- }
357
- }
358
-
359
- func updateWorkspaceTimingsMetrics (
360
- workspaceCreationTimings * prometheus.HistogramVec ,
361
- workspaceClaimTimings * prometheus.HistogramVec ,
362
- )UpdateWorkspaceTimingMetricsFn {
363
- return func (
364
- workspaceTimingType WorkspaceTimingType ,
365
- organizationName string ,
366
- templateName string ,
367
- presetName string ,
368
- buildTime float64 ,
369
- ) {
370
- switch workspaceTimingType {
371
- case WorkspaceCreation :
372
- // Regular workspace creation (without prebuild pool)
373
- workspaceCreationTimings .
374
- WithLabelValues (organizationName ,templateName ,presetName ,workspaceTypeRegular ).Observe (buildTime )
375
- case PrebuildCreation :
376
- // Prebuilt workspace creation duration
377
- workspaceCreationTimings .
378
- WithLabelValues (organizationName ,templateName ,presetName ,workspaceTypePrebuild ).Observe (buildTime )
379
- case PrebuildClaim :
380
- // Prebuilt workspace claim duration
381
- workspaceClaimTimings .
382
- WithLabelValues (organizationName ,templateName ,presetName ).Observe (buildTime )
383
- default :
384
- }
385
- }
263
+ },nil
386
264
}
387
265
388
266
// Agents tracks the total number of workspaces with labels on status.