Skip to content

refactor: skip reconciliation for some presets #17595

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 1 commit into from
Apr 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions coderd/prebuilds/preset_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ type ReconciliationActions struct {
BackoffUntil time.Time
}

func (ra *ReconciliationActions) IsNoop() bool {
return ra.Create == 0 && len(ra.DeleteIDs) == 0 && ra.BackoffUntil.IsZero()
}

// CalculateState computes the current state of prebuilds for a preset, including:
// - Actual: Number of currently running prebuilds
// - Desired: Number of prebuilds desired as defined in the preset
Expand Down
9 changes: 9 additions & 0 deletions enterprise/coderd/prebuilds/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,15 @@ func (c *StoreReconciler) ReconcilePreset(ctx context.Context, ps prebuilds.Pres
return nil
}

// Nothing has to be done.
if !ps.Preset.UsingActiveVersion && actions.IsNoop() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dannykopping Do we need !ps.Preset.UsingActiveVersion? I think we can skip reconciliation for all presets if actions.IsNoop() == true?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess, yeah, but if the preset is part of an inactive version then we shouldn't be logging anything for that; for active presets which have no operations to perform, that's at least diagnostically useful.

Consider an installation that's been using prebuilds for a while and they have >100 inactive preset versions; that'll log a tonne for no value.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay, let's keep it as it is

Copy link
Contributor Author

@evgeniy-scherbina evgeniy-scherbina Apr 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean here we log with debug level which is probably okay?

// Nothing has to be done.
if !ps.Preset.UsingActiveVersion && actions.IsNoop() {
	logger.Debug(ctx, "skipping reconciliation for preset - nothing has to be done",
		slog.F("template_id", ps.Preset.TemplateID.String()), slog.F("template_name", ps.Preset.TemplateName),
		slog.F("template_version_id", ps.Preset.TemplateVersionID.String()), slog.F("template_version_name", ps.Preset.TemplateVersionName),
		slog.F("preset_id", ps.Preset.ID.String()), slog.F("preset_name", ps.Preset.Name))
	return nil
}

and then exit early without additional logs with info/warn log level

Or you wanted to delete debug log as well?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope we can keep the debug log 👍

logger.Debug(ctx, "skipping reconciliation for preset - nothing has to be done",
slog.F("template_id", ps.Preset.TemplateID.String()), slog.F("template_name", ps.Preset.TemplateName),
slog.F("template_version_id", ps.Preset.TemplateVersionID.String()), slog.F("template_version_name", ps.Preset.TemplateVersionName),
slog.F("preset_id", ps.Preset.ID.String()), slog.F("preset_name", ps.Preset.Name))
return nil
}

// nolint:gocritic // ReconcilePreset needs Prebuilds Orchestrator permissions.
prebuildsCtx := dbauthz.AsPrebuildsOrchestrator(ctx)

Expand Down
Loading