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

Skip to content

fix: exclude deleted templates from metrics collection #17839

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
May 15, 2025
Prev Previous commit
Next Next commit
fix: skip deleted templates on metrics collector level
  • Loading branch information
evgeniy-scherbina committed May 14, 2025
commit e42a08312b48d906c6439c253713b456772e5ca1
4 changes: 4 additions & 0 deletions enterprise/coderd/prebuilds/metricscollector.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@ func (mc *MetricsCollector) Collect(metricsCh chan<- prometheus.Metric) {
continue
}

if preset.Deleted {
continue
}

presetSnapshot, err := currentState.snapshot.FilterByPreset(preset.ID)
if err != nil {
mc.logger.Error(context.Background(), "failed to filter by preset", slog.Error(err))
Expand Down
25 changes: 0 additions & 25 deletions enterprise/coderd/prebuilds/metricscollector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,31 +164,6 @@ func TestMetricsCollector(t *testing.T) {
templateDeleted: []bool{false},
eligible: []bool{false},
},
{
name: "deleted templates never desire prebuilds",
transitions: allTransitions,
jobStatuses: allJobStatuses,
initiatorIDs: []uuid.UUID{agplprebuilds.SystemUserID},
ownerIDs: []uuid.UUID{agplprebuilds.SystemUserID, uuid.New()},
metrics: []metricCheck{
{prebuilds.MetricDesiredGauge, ptr.To(0.0), false},
},
templateDeleted: []bool{true},
eligible: []bool{false},
},
{
name: "running prebuilds for deleted templates are still counted, so that they can be deleted",
transitions: []database.WorkspaceTransition{database.WorkspaceTransitionStart},
jobStatuses: []database.ProvisionerJobStatus{database.ProvisionerJobStatusSucceeded},
initiatorIDs: []uuid.UUID{agplprebuilds.SystemUserID},
ownerIDs: []uuid.UUID{agplprebuilds.SystemUserID},
metrics: []metricCheck{
{prebuilds.MetricRunningGauge, ptr.To(1.0), false},
{prebuilds.MetricEligibleGauge, ptr.To(0.0), false},
},
templateDeleted: []bool{true},
eligible: []bool{false},
},
}
for _, test := range tests {
test := test // capture for parallel
Expand Down
Loading