prebuilds

package
v2.22.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 15, 2025 License: AGPL-3.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
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"
	MetricLastUpdatedGauge          = namespace + "metrics_last_updated"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type EnterpriseClaimer

type EnterpriseClaimer struct {
	// contains filtered or unexported fields
}

func NewEnterpriseClaimer

func NewEnterpriseClaimer(store database.Store) *EnterpriseClaimer

func (EnterpriseClaimer) Claim

func (c EnterpriseClaimer) Claim(
	ctx context.Context,
	userID uuid.UUID,
	name string,
	presetID uuid.UUID,
) (*uuid.UUID, error)

func (EnterpriseClaimer) Initiator

func (EnterpriseClaimer) Initiator() uuid.UUID

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

func (mc *MetricsCollector) UpdateState(ctx context.Context, timeout time.Duration) error

UpdateState builds the current metrics state.

type StoreReconciler

type StoreReconciler struct {
	// contains filtered or unexported fields
}

func NewStoreReconciler

func NewStoreReconciler(store database.Store,
	ps pubsub.Pubsub,
	cfg codersdk.PrebuildsConfig,
	logger slog.Logger,
	clock quartz.Clock,
	registerer prometheus.Registerer,
	notifEnq notifications.Enqueuer,
) *StoreReconciler

func (*StoreReconciler) CalculateActions

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) error

ReconcileAll will attempt to resolve the desired vs actual state of all templates which have presets with prebuilds configured.

NOTE:

This function will kick of n provisioner jobs, based on the calculated state modifications.

These provisioning jobs are fire-and-forget. We DO NOT wait for the prebuilt workspaces to complete their provisioning. As a consequence, it's possible that another reconciliation run will occur, which will mean that multiple preset versions could be reconciling at once. This may mean some temporary over-provisioning, but the reconciliation loop will bring these resources back into their desired numbers in an EVENTUALLY-consistent way.

For example: we could decide to provision 1 new instance in this reconciliation. While that workspace is being provisioned, another template version is created which means this same preset will be reconciled again, leading to another workspace being provisioned. Two workspace builds will be occurring simultaneously for the same preset, but once both jobs have completed the reconciliation loop will notice the extraneous instance and delete it.

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)

func (*StoreReconciler) TrackResourceReplacement

func (c *StoreReconciler) TrackResourceReplacement(ctx context.Context, workspaceID, buildID uuid.UUID, replacements []*sdkproto.ResourceReplacement)

func (*StoreReconciler) WithReconciliationLock

func (c *StoreReconciler) WithReconciliationLock(
	ctx context.Context,
	logger slog.Logger,
	fn func(ctx context.Context, db database.Store) error,
) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL