Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 11d7ed3

Browse files
committed
chore: address comments
1 parent ea19217 commit 11d7ed3

File tree

4 files changed

+61
-31
lines changed

4 files changed

+61
-31
lines changed

coderd/database/querier.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries.sql.go

Lines changed: 24 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries/workspaces.sql

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -925,21 +925,34 @@ WHERE
925925
id = @id;
926926

927927
-- name: GetRegularWorkspaceCreateMetrics :many
928+
-- Count regular workspaces: only those whose first successful 'start' build
929+
-- was not initiated by the prebuild system user.
930+
WITH first_success_build AS (
931+
-- Earliest successful 'start' build per workspace
932+
SELECT DISTINCT ON (wb.workspace_id)
933+
wb.workspace_id,
934+
wb.template_version_preset_id,
935+
wb.initiator_id
936+
FROM workspace_builds wb
937+
JOIN provisioner_jobs pj ON pj.id = wb.job_id
938+
WHERE
939+
wb.transition = 'start'::workspace_transition
940+
AND pj.job_status = 'succeeded'::provisioner_job_status
941+
ORDER BY wb.workspace_id, wb.build_number, wb.id
942+
)
928943
SELECT
929944
t.name AS template_name,
930945
COALESCE(tvp.name, '') AS preset_name,
931946
o.name AS organization_name,
932947
COUNT(*) AS created_count
933-
FROM workspaces w
934-
INNER JOIN workspace_builds wb ON wb.workspace_id = w.id
935-
AND wb.build_number = 1
936-
AND wb.transition = 'start'::workspace_transition
937-
AND wb.initiator_id != 'c42fdf75-3097-471c-8c33-fb52454d81c0'::uuid -- The system user responsible for prebuilds.
938-
INNER JOIN templates t ON t.id = w.template_id
939-
LEFT JOIN template_version_presets tvp ON tvp.id = wb.template_version_preset_id
940-
INNER JOIN provisioner_jobs pj ON pj.id = wb.job_id
941-
AND pj.job_status = 'succeeded'::provisioner_job_status
942-
INNER JOIN organizations o ON o.id = w.organization_id
943-
WHERE NOT t.deleted
948+
FROM first_success_build fsb
949+
JOIN workspaces w ON w.id = fsb.workspace_id
950+
JOIN templates t ON t.id = w.template_id
951+
LEFT JOIN template_version_presets tvp ON tvp.id = fsb.template_version_preset_id
952+
JOIN organizations o ON o.id = w.organization_id
953+
WHERE
954+
NOT t.deleted
955+
-- Exclude workspaces whose first successful start was the prebuilds system user
956+
AND fsb.initiator_id != 'c42fdf75-3097-471c-8c33-fb52454d81c0'::uuid
944957
GROUP BY t.name, COALESCE(tvp.name, ''), o.name
945958
ORDER BY t.name, preset_name, o.name;

coderd/prometheusmetrics/prometheusmetrics.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ func Workspaces(ctx context.Context, logger slog.Logger, registerer prometheus.R
168168
workspaceCreationTotal := prometheus.NewCounterVec(
169169
prometheus.CounterOpts{
170170
Namespace: "coderd",
171-
Subsystem: "api",
171+
Subsystem: "",
172172
Name: "workspace_creation_total",
173173
Help: "Total regular (non-prebuilt) workspace creations by organization, template, and preset.",
174174
},
@@ -180,7 +180,7 @@ func Workspaces(ctx context.Context, logger slog.Logger, registerer prometheus.R
180180

181181
workspaceCreationTimings := prometheus.NewHistogramVec(prometheus.HistogramOpts{
182182
Namespace: "coderd",
183-
Subsystem: "provisionerd",
183+
Subsystem: "",
184184
Name: "workspace_creation_duration_seconds",
185185
Help: "Time to create a workspace by organization, template, preset, and type (regular or prebuild).",
186186
Buckets: []float64{
@@ -208,18 +208,20 @@ func Workspaces(ctx context.Context, logger slog.Logger, registerer prometheus.R
208208

209209
workspaceClaimTimings := prometheus.NewHistogramVec(prometheus.HistogramOpts{
210210
Namespace: "coderd",
211-
Subsystem: "provisionerd",
212-
Name: "workspace_claim_duration_seconds",
211+
Subsystem: "",
212+
Name: "prebuilt_workspace_claim_duration_seconds",
213213
Help: "Time to claim a prebuilt workspace by organization, template, and preset.",
214214
Buckets: []float64{
215215
1, // 1s
216+
5,
216217
10,
218+
20,
217219
30,
218-
60, // 1min
219-
60 * 5,
220-
60 * 10,
221-
60 * 30, // 30min
222-
60 * 60, // 1hr
220+
60, // 1m
221+
120, // 2m
222+
180, // 3m
223+
240, // 4m
224+
300, // 5m
223225
},
224226
NativeHistogramBucketFactor: 1.1,
225227
// Max number of native buckets kept at once to bound memory.

0 commit comments

Comments
 (0)