Skip to content

Commit 109b912

Browse files
temporary commit
1 parent e8c75eb commit 109b912

File tree

4 files changed

+38
-14
lines changed

4 files changed

+38
-14
lines changed

coderd/prebuilds/global_snapshot.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,14 @@ func (s GlobalSnapshot) FilterByPreset(presetID uuid.UUID) (*PresetSnapshot, err
8080
}, nil
8181
}
8282

83+
func (s GlobalSnapshot) IsHardLimited(presetID uuid.UUID) bool {
84+
_, isHardLimited := slice.Find(s.HardLimitedPresets, func(row database.GetPresetsAtFailureLimitRow) bool {
85+
return row.PresetID == presetID
86+
})
87+
88+
return isHardLimited
89+
}
90+
8391
// filterExpiredWorkspaces splits running workspaces into expired and non-expired
8492
// based on the preset's TTL.
8593
// If TTL is missing or zero, all workspaces are considered non-expired.

enterprise/coderd/prebuilds/metricscollector.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -281,15 +281,9 @@ func (k hardLimitedPresetKey) String() string {
281281
}
282282

283283
// nolint:revive // isHardLimited determines if the preset should be reported as hard-limited in Prometheus.
284-
func (mc *MetricsCollector) trackHardLimitedStatus(orgName, templateName, presetName string, isHardLimited bool) {
284+
func (mc *MetricsCollector) trackHardLimitedStatus(isPresetHardLimited map[hardLimitedPresetKey]bool) {
285285
mc.isPresetHardLimitedMu.Lock()
286286
defer mc.isPresetHardLimitedMu.Unlock()
287287

288-
key := hardLimitedPresetKey{orgName: orgName, templateName: templateName, presetName: presetName}
289-
290-
if isHardLimited {
291-
mc.isPresetHardLimited[key] = true
292-
} else {
293-
delete(mc.isPresetHardLimited, key)
294-
}
288+
mc.isPresetHardLimited = isPresetHardLimited
295289
}

enterprise/coderd/prebuilds/reconcile.go

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,30 @@ func (c *StoreReconciler) ReconcileAll(ctx context.Context) error {
256256
if err != nil {
257257
return xerrors.Errorf("determine current snapshot: %w", err)
258258
}
259+
260+
presetsMap := make(map[hardLimitedPresetKey][]database.GetTemplatePresetsWithPrebuildsRow)
261+
for _, preset := range snapshot.Presets {
262+
key := hardLimitedPresetKey{
263+
orgName: preset.OrganizationName,
264+
templateName: preset.TemplateName,
265+
presetName: preset.Name,
266+
}
267+
268+
presetsMap[key] = append(presetsMap[key], preset)
269+
}
270+
271+
isPresetHardLimited := make(map[hardLimitedPresetKey]bool)
272+
for key, presets := range presetsMap {
273+
for _, preset := range presets {
274+
if preset.UsingActiveVersion && !preset.Deleted {
275+
isPresetHardLimited[key] = snapshot.IsHardLimited(preset.ID)
276+
break
277+
}
278+
}
279+
}
280+
281+
c.metrics.trackHardLimitedStatus(isPresetHardLimited)
282+
259283
if len(snapshot.Presets) == 0 {
260284
logger.Debug(ctx, "no templates found with prebuilds configured")
261285
return nil
@@ -375,9 +399,9 @@ func (c *StoreReconciler) ReconcilePreset(ctx context.Context, ps prebuilds.Pres
375399
// then deletes the template and never creates another with the same name,
376400
// the old preset will continue to be reported as hard-limited —
377401
// even though it’s deleted. This will persist until `coderd` is restarted.
378-
if ps.Preset.UsingActiveVersion && !ps.Preset.Deleted {
379-
c.metrics.trackHardLimitedStatus(ps.Preset.OrganizationName, ps.Preset.TemplateName, ps.Preset.Name, ps.IsHardLimited)
380-
}
402+
//if ps.Preset.UsingActiveVersion && !ps.Preset.Deleted {
403+
// c.metrics.trackHardLimitedStatus(ps.Preset.OrganizationName, ps.Preset.TemplateName, ps.Preset.Name, ps.IsHardLimited)
404+
//}
381405

382406
// If the preset reached the hard failure limit for the first time during this iteration:
383407
// - Mark it as hard-limited in the database

enterprise/coderd/prebuilds/reconcile_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,9 +1043,7 @@ func TestHardLimitedPresetShouldNotBlockDeletion(t *testing.T) {
10431043
"preset_name": preset.Name,
10441044
"org_name": org.Name,
10451045
})
1046-
require.NotNil(t, metric)
1047-
require.NotNil(t, metric.GetGauge())
1048-
require.EqualValues(t, 1, metric.GetGauge().GetValue())
1046+
require.Nil(t, metric)
10491047
})
10501048
}
10511049
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy