Thanks to visit codestin.com
Credit goes to pkg.go.dev

prebuilds

package
v2.24.0 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2025 License: AGPL-3.0 Imports: 30 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"
	MetricPresetHardLimitedGauge    = namespace + "preset_hard_limited"
	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 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 NewStoreMembershipReconciler(store database.Store, clock quartz.Clock) StoreMembershipReconciler

func (StoreMembershipReconciler) ReconcileAll added in v2.24.0

ReconcileAll compares the current membership of a user to the membership required in order to create prebuilt workspaces. If the user in question is not yet a member of an organization that needs prebuilt workspaces, ReconcileAll will create the membership required.

This method does not have an opinion on transaction or lock management. These responsibilities are left to the caller.

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,
) *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