Documentation
¶
Index ¶
- Constants
- func SetPrebuildsReconciliationPaused(ctx context.Context, db database.Store, paused bool) error
- type DeprovisionMode
- type EnterpriseClaimer
- type MetricsCollector
- func (mc *MetricsCollector) BackgroundFetch(ctx context.Context, updateInterval, updateTimeout time.Duration)
- func (mc *MetricsCollector) Collect(metricsCh chan<- prometheus.Metric)
- func (*MetricsCollector) Describe(descCh chan<- *prometheus.Desc)
- func (mc *MetricsCollector) UpdateState(ctx context.Context, timeout time.Duration) error
- type Settings
- type StoreMembershipReconciler
- type StoreReconciler
- func (c *StoreReconciler) CalculateActions(ctx context.Context, snapshot prebuilds.PresetSnapshot) ([]*prebuilds.ReconciliationActions, error)
- func (c *StoreReconciler) ForceMetricsUpdate(ctx context.Context) error
- func (c *StoreReconciler) ReconcileAll(ctx context.Context) (stats prebuilds.ReconcileStats, err error)
- func (c *StoreReconciler) ReconcilePreset(ctx context.Context, ps prebuilds.PresetSnapshot) error
- func (c *StoreReconciler) Run(ctx context.Context)
- func (c *StoreReconciler) SnapshotState(ctx context.Context, store database.Store) (*prebuilds.GlobalSnapshot, error)
- func (c *StoreReconciler) Stop(ctx context.Context, cause error)
- func (c *StoreReconciler) TrackResourceReplacement(ctx context.Context, workspaceID, buildID uuid.UUID, ...)
- func (c *StoreReconciler) WithReconciliationLock(ctx context.Context, logger slog.Logger, ...) error
Constants ¶
const ( PrebuiltWorkspacesGroupName = "coderprebuiltworkspaces" PrebuiltWorkspacesGroupDisplayName = "Prebuilt Workspaces" )
const ( MetricCreatedCount = namespace + "created_total" MetricFailedCount = namespace + "failed_total" MetricClaimedCount = namespace + "claimed_total" MetricResourceReplacementsCount = namespace + "resource_replacements_total" MetricDesiredGauge = namespace + "desired" MetricRunningGauge = namespace + "running" MetricEligibleGauge = namespace + "eligible" MetricPresetHardLimitedGauge = namespace + "preset_hard_limited" MetricLastUpdatedGauge = namespace + "metrics_last_updated" MetricReconciliationPausedGauge = namespace + "reconciliation_paused" )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type DeprovisionMode ¶ added in v2.28.0
type DeprovisionMode int
const ( DeprovisionModeNormal DeprovisionMode = iota DeprovisionModeOrphan )
func (DeprovisionMode) String ¶ added in v2.28.0
func (d DeprovisionMode) String() string
type EnterpriseClaimer ¶
type EnterpriseClaimer struct{}
func NewEnterpriseClaimer ¶
func NewEnterpriseClaimer() *EnterpriseClaimer
type MetricsCollector ¶
type MetricsCollector struct {
// contains filtered or unexported fields
}
func NewMetricsCollector ¶
func NewMetricsCollector(db database.Store, logger slog.Logger, snapshotter prebuilds.StateSnapshotter) *MetricsCollector
func (*MetricsCollector) BackgroundFetch ¶
func (mc *MetricsCollector) BackgroundFetch(ctx context.Context, updateInterval, updateTimeout time.Duration)
BackgroundFetch updates the metrics state every given interval.
func (*MetricsCollector) Collect ¶
func (mc *MetricsCollector) Collect(metricsCh chan<- prometheus.Metric)
Collect uses the cached state to set configured metrics. The state is cached because this function can be called multiple times per second and retrieving the current state is an expensive operation.
func (*MetricsCollector) Describe ¶
func (*MetricsCollector) Describe(descCh chan<- *prometheus.Desc)
func (*MetricsCollector) UpdateState ¶
UpdateState builds the current metrics state.
type Settings ¶ added in v2.25.0
type Settings struct {
ReconciliationPaused bool `json:"reconciliation_paused"`
}
type StoreMembershipReconciler ¶ added in v2.24.0
type StoreMembershipReconciler struct {
// contains filtered or unexported fields
}
StoreMembershipReconciler encapsulates the responsibility of ensuring that the prebuilds system user is a member of all organizations for which prebuilt workspaces are requested. This is necessary because our data model requires that such prebuilt workspaces belong to a member of the organization of their eventual claimant.
func NewStoreMembershipReconciler ¶ added in v2.24.0
func (StoreMembershipReconciler) ReconcileAll ¶ added in v2.24.0
func (s StoreMembershipReconciler) ReconcileAll(ctx context.Context, userID uuid.UUID, groupName string) error
ReconcileAll ensures the prebuilds system user has the necessary memberships to create prebuilt workspaces. For each organization with prebuilds configured, it ensures: * The prebuilds user is a member of the organization * A prebuilds group exists with quota allowance 0 (admins should adjust based on needs) * The prebuilds user is a member of that group
Unique constraint violations are safely ignored (concurrent creation). ReconcileAll performs independent write operations without a transaction. Partial failures are handled by subsequent reconciliation cycles.
type StoreReconciler ¶
type StoreReconciler struct {
// contains filtered or unexported fields
}
func NewStoreReconciler ¶
func NewStoreReconciler(store database.Store, ps pubsub.Pubsub, fileCache *files.Cache, cfg codersdk.PrebuildsConfig, logger slog.Logger, clock quartz.Clock, registerer prometheus.Registerer, notifEnq notifications.Enqueuer, buildUsageChecker *atomic.Pointer[wsbuilder.UsageChecker], tracerProvider trace.TracerProvider, maxDBConnections int, workspaceBuilderMetrics *wsbuilder.Metrics, ) *StoreReconciler
func (*StoreReconciler) CalculateActions ¶
func (c *StoreReconciler) CalculateActions(ctx context.Context, snapshot prebuilds.PresetSnapshot) ([]*prebuilds.ReconciliationActions, error)
func (*StoreReconciler) ForceMetricsUpdate ¶
func (c *StoreReconciler) ForceMetricsUpdate(ctx context.Context) error
ForceMetricsUpdate forces the metrics collector, if defined, to update its state (we cache the metrics state to reduce load on the database).
func (*StoreReconciler) ReconcileAll ¶
func (c *StoreReconciler) ReconcileAll(ctx context.Context) (stats prebuilds.ReconcileStats, err error)
ReconcileAll attempts to reconcile the desired vs actual state of all prebuilds for each (organization, template, template version, preset) tuple.
The result is a set of provisioning actions for each preset. These actions are fire-and-forget: the reconciliation loop does not wait for prebuilt workspaces to complete provisioning.
An outer read-only transaction holds an advisory lock ensuring only one replica reconciles at a time. This transaction remains open throughout the entire reconciliation cycle. Goroutines responsible for preset reconciliation use separate, independent write transactions (via c.store). In the rare case of the lock transaction failing mid-reconciliation, goroutines may continue while another replica acquires the lock, potentially causing temporary under/over-provisioning. Since the reconciliation loop is eventually consistent, subsequent cycles will converge to the desired state.
NOTE: Read operations must use db (the lock transaction) while write operations must use c.store.
func (*StoreReconciler) ReconcilePreset ¶
func (c *StoreReconciler) ReconcilePreset(ctx context.Context, ps prebuilds.PresetSnapshot) error
func (*StoreReconciler) Run ¶
func (c *StoreReconciler) Run(ctx context.Context)
func (*StoreReconciler) SnapshotState ¶
func (c *StoreReconciler) SnapshotState(ctx context.Context, store database.Store) (*prebuilds.GlobalSnapshot, error)
SnapshotState captures the current state of all prebuilds across templates.
func (*StoreReconciler) Stop ¶
func (c *StoreReconciler) Stop(ctx context.Context, cause error)
Stop triggers reconciler shutdown and waits for it to complete. The ctx parameter provides a timeout, if cleanup doesn't finish within this timeout, Stop() logs an error and returns.
func (*StoreReconciler) TrackResourceReplacement ¶
func (c *StoreReconciler) TrackResourceReplacement(ctx context.Context, workspaceID, buildID uuid.UUID, replacements []*sdkproto.ResourceReplacement)