mirror of
https://github.com/coder/coder.git
synced 2026-09-22 05:05:20 +08:00
fix(coderd): fix logic for reporting prebuilt workspace duration metric (#19641)
## Description When creating a prebuilt workspace, both `flags.IsPrebuild` and `flags.IsFirstBuild` are true. Previously, the logic rejected cases with multiple flags, so `coderd_workspace_creation_duration_seconds` wasn’t updated for prebuilt creations. This is the only valid scenario where two flags can be true. ## Changes * Fix logic to update `coderd_workspace_creation_duration_seconds` metric for prebuilt workspaces. * Add prebuild helper functions to coderdenttest (other prebuild tests can reuse this). * Update workspace's provisionerdmetric tests to include this metric. Follow-up: https://github.com/coder/coder/pull/19503 Related to: https://github.com/coder/coder/issues/19528
This commit is contained in:
@@ -100,25 +100,14 @@ func (m *Metrics) Register(reg prometheus.Registerer) error {
|
||||
return reg.Register(m.workspaceClaimTimings)
|
||||
}
|
||||
|
||||
func (f WorkspaceTimingFlags) count() int {
|
||||
count := 0
|
||||
if f.IsPrebuild {
|
||||
count++
|
||||
}
|
||||
if f.IsClaim {
|
||||
count++
|
||||
}
|
||||
if f.IsFirstBuild {
|
||||
count++
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
// getWorkspaceTimingType returns the type of the workspace build:
|
||||
// - isPrebuild: if the workspace build corresponds to the creation of a prebuilt workspace
|
||||
// - isClaim: if the workspace build corresponds to the claim of a prebuilt workspace
|
||||
// - isWorkspaceFirstBuild: if the workspace build corresponds to the creation of a regular workspace
|
||||
// (not created from the prebuild pool)
|
||||
// getWorkspaceTimingType classifies a workspace build:
|
||||
// - PrebuildCreation: creation of a prebuilt workspace
|
||||
// - PrebuildClaim: claim of an existing prebuilt workspace
|
||||
// - WorkspaceCreation: first build of a regular (non-prebuilt) workspace
|
||||
//
|
||||
// Note: order matters. Creating a prebuilt workspace is also a first build
|
||||
// (IsPrebuild && IsFirstBuild). We check IsPrebuild before IsFirstBuild so
|
||||
// prebuilds take precedence. This is the only case where two flags can be true.
|
||||
func getWorkspaceTimingType(flags WorkspaceTimingFlags) WorkspaceTimingType {
|
||||
switch {
|
||||
case flags.IsPrebuild:
|
||||
@@ -149,14 +138,6 @@ func (m *Metrics) UpdateWorkspaceTimingsMetrics(
|
||||
"isClaim", flags.IsClaim,
|
||||
"isWorkspaceFirstBuild", flags.IsFirstBuild)
|
||||
|
||||
if flags.count() > 1 {
|
||||
m.logger.Warn(ctx, "invalid workspace timing flags",
|
||||
"isPrebuild", flags.IsPrebuild,
|
||||
"isClaim", flags.IsClaim,
|
||||
"isWorkspaceFirstBuild", flags.IsFirstBuild)
|
||||
return
|
||||
}
|
||||
|
||||
workspaceTimingType := getWorkspaceTimingType(flags)
|
||||
switch workspaceTimingType {
|
||||
case WorkspaceCreation:
|
||||
|
||||
Reference in New Issue
Block a user