mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
fix: reimplement reporting of preset-hard-limited metric (#18055)
Addresses concerns raised in https://github.com/coder/coder/pull/18045
This commit is contained in:
@@ -12,11 +12,11 @@ import (
|
||||
|
||||
// GlobalSnapshot represents a full point-in-time snapshot of state relating to prebuilds across all templates.
|
||||
type GlobalSnapshot struct {
|
||||
Presets []database.GetTemplatePresetsWithPrebuildsRow
|
||||
RunningPrebuilds []database.GetRunningPrebuiltWorkspacesRow
|
||||
PrebuildsInProgress []database.CountInProgressPrebuildsRow
|
||||
Backoffs []database.GetPresetsBackoffRow
|
||||
HardLimitedPresets []database.GetPresetsAtFailureLimitRow
|
||||
Presets []database.GetTemplatePresetsWithPrebuildsRow
|
||||
RunningPrebuilds []database.GetRunningPrebuiltWorkspacesRow
|
||||
PrebuildsInProgress []database.CountInProgressPrebuildsRow
|
||||
Backoffs []database.GetPresetsBackoffRow
|
||||
HardLimitedPresetsMap map[uuid.UUID]database.GetPresetsAtFailureLimitRow
|
||||
}
|
||||
|
||||
func NewGlobalSnapshot(
|
||||
@@ -26,12 +26,17 @@ func NewGlobalSnapshot(
|
||||
backoffs []database.GetPresetsBackoffRow,
|
||||
hardLimitedPresets []database.GetPresetsAtFailureLimitRow,
|
||||
) GlobalSnapshot {
|
||||
hardLimitedPresetsMap := make(map[uuid.UUID]database.GetPresetsAtFailureLimitRow, len(hardLimitedPresets))
|
||||
for _, preset := range hardLimitedPresets {
|
||||
hardLimitedPresetsMap[preset.PresetID] = preset
|
||||
}
|
||||
|
||||
return GlobalSnapshot{
|
||||
Presets: presets,
|
||||
RunningPrebuilds: runningPrebuilds,
|
||||
PrebuildsInProgress: prebuildsInProgress,
|
||||
Backoffs: backoffs,
|
||||
HardLimitedPresets: hardLimitedPresets,
|
||||
Presets: presets,
|
||||
RunningPrebuilds: runningPrebuilds,
|
||||
PrebuildsInProgress: prebuildsInProgress,
|
||||
Backoffs: backoffs,
|
||||
HardLimitedPresetsMap: hardLimitedPresetsMap,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,9 +71,7 @@ func (s GlobalSnapshot) FilterByPreset(presetID uuid.UUID) (*PresetSnapshot, err
|
||||
backoffPtr = &backoff
|
||||
}
|
||||
|
||||
_, isHardLimited := slice.Find(s.HardLimitedPresets, func(row database.GetPresetsAtFailureLimitRow) bool {
|
||||
return row.PresetID == preset.ID
|
||||
})
|
||||
_, isHardLimited := s.HardLimitedPresetsMap[preset.ID]
|
||||
|
||||
return &PresetSnapshot{
|
||||
Preset: preset,
|
||||
@@ -80,6 +83,12 @@ func (s GlobalSnapshot) FilterByPreset(presetID uuid.UUID) (*PresetSnapshot, err
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s GlobalSnapshot) IsHardLimited(presetID uuid.UUID) bool {
|
||||
_, isHardLimited := s.HardLimitedPresetsMap[presetID]
|
||||
|
||||
return isHardLimited
|
||||
}
|
||||
|
||||
// filterExpiredWorkspaces splits running workspaces into expired and non-expired
|
||||
// based on the preset's TTL.
|
||||
// If TTL is missing or zero, all workspaces are considered non-expired.
|
||||
|
||||
Reference in New Issue
Block a user