Skip to content

Commit e42a083

Browse files
fix: skip deleted templates on metrics collector level
1 parent 9ba369d commit e42a083

File tree

2 files changed

+4
-25
lines changed

2 files changed

+4
-25
lines changed

enterprise/coderd/prebuilds/metricscollector.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,10 @@ func (mc *MetricsCollector) Collect(metricsCh chan<- prometheus.Metric) {
157157
continue
158158
}
159159

160+
if preset.Deleted {
161+
continue
162+
}
163+
160164
presetSnapshot, err := currentState.snapshot.FilterByPreset(preset.ID)
161165
if err != nil {
162166
mc.logger.Error(context.Background(), "failed to filter by preset", slog.Error(err))

enterprise/coderd/prebuilds/metricscollector_test.go

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -164,31 +164,6 @@ func TestMetricsCollector(t *testing.T) {
164164
templateDeleted: []bool{false},
165165
eligible: []bool{false},
166166
},
167-
{
168-
name: "deleted templates never desire prebuilds",
169-
transitions: allTransitions,
170-
jobStatuses: allJobStatuses,
171-
initiatorIDs: []uuid.UUID{agplprebuilds.SystemUserID},
172-
ownerIDs: []uuid.UUID{agplprebuilds.SystemUserID, uuid.New()},
173-
metrics: []metricCheck{
174-
{prebuilds.MetricDesiredGauge, ptr.To(0.0), false},
175-
},
176-
templateDeleted: []bool{true},
177-
eligible: []bool{false},
178-
},
179-
{
180-
name: "running prebuilds for deleted templates are still counted, so that they can be deleted",
181-
transitions: []database.WorkspaceTransition{database.WorkspaceTransitionStart},
182-
jobStatuses: []database.ProvisionerJobStatus{database.ProvisionerJobStatusSucceeded},
183-
initiatorIDs: []uuid.UUID{agplprebuilds.SystemUserID},
184-
ownerIDs: []uuid.UUID{agplprebuilds.SystemUserID},
185-
metrics: []metricCheck{
186-
{prebuilds.MetricRunningGauge, ptr.To(1.0), false},
187-
{prebuilds.MetricEligibleGauge, ptr.To(0.0), false},
188-
},
189-
templateDeleted: []bool{true},
190-
eligible: []bool{false},
191-
},
192167
}
193168
for _, test := range tests {
194169
test := test // capture for parallel

0 commit comments

Comments
 (0)