provisionerdserver

package
v2.10.2 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: AGPL-3.0 Imports: 42 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultAcquireJobLongPollDur is the time the (deprecated) AcquireJob rpc waits to try to obtain a job before
	// canceling and returning an empty job.
	DefaultAcquireJobLongPollDur = time.Second * 5

	// DefaultHeartbeatInterval is the interval at which the provisioner daemon
	// will update its last seen at timestamp in the database.
	DefaultHeartbeatInterval = time.Minute
)

Variables

View Source
var ErrorTagsContainNullByte = xerrors.New("tags cannot contain the null byte (0x00)")

Functions

func InsertWorkspaceResource

func InsertWorkspaceResource(ctx context.Context, db database.Store, jobID uuid.UUID, transition database.WorkspaceTransition, protoResource *sdkproto.Resource, snapshot *telemetry.Snapshot) error

func NewServer added in v2.1.5

func NewServer(
	lifecycleCtx context.Context,
	accessURL *url.URL,
	id uuid.UUID,
	organizationID uuid.UUID,
	logger slog.Logger,
	provisioners []database.ProvisionerType,
	tags Tags,
	db database.Store,
	ps pubsub.Pubsub,
	acquirer *Acquirer,
	tel telemetry.Reporter,
	tracer trace.Tracer,
	quotaCommitter *atomic.Pointer[proto.QuotaCommitter],
	auditor *atomic.Pointer[audit.Auditor],
	templateScheduleStore *atomic.Pointer[schedule.TemplateScheduleStore],
	userQuietHoursScheduleStore *atomic.Pointer[schedule.UserQuietHoursScheduleStore],
	deploymentValues *codersdk.DeploymentValues,
	options Options,
) (proto.DRPCProvisionerDaemonServer, error)

Types

type Acquirer added in v2.2.0

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

Acquirer is shared among multiple routines that need to call database.Store.AcquireProvisionerJob. The callers that acquire jobs are called "acquirees". The goal is to minimize polling the database (i.e. lower our average query rate) and simplify the acquiree's logic by handling retrying the database if a job is not available at the time of the call.

When multiple acquirees share a set of provisioner types and tags, we define them as part of the same "domain". Only one acquiree from each domain may query the database at a time. If the database returns no jobs for that acquiree, the entire domain waits until the Acquirer is notified over the pubsub of a new job acceptable to the domain.

As a backup to pubsub notifications, each domain is allowed to query periodically once every 30s. This ensures jobs are not stuck permanently if the service that created them fails to publish (e.g. a crash).

func NewAcquirer added in v2.2.0

func NewAcquirer(ctx context.Context, logger slog.Logger, store AcquirerStore, ps pubsub.Pubsub,
	opts ...AcquirerOption,
) *Acquirer

func (*Acquirer) AcquireJob added in v2.2.0

func (a *Acquirer) AcquireJob(
	ctx context.Context, organization uuid.UUID, worker uuid.UUID, pt []database.ProvisionerType, tags Tags,
) (
	retJob database.ProvisionerJob, retErr error,
)

AcquireJob acquires a job with one of the given provisioner types and compatible tags from the database. The call blocks until a job is acquired, the context is done, or the database returns an error _other_ than that no jobs are available. If no jobs are available, this method handles retrying as appropriate.

type AcquirerOption added in v2.2.0

type AcquirerOption func(*Acquirer)

func TestingBackupPollDuration added in v2.2.0

func TestingBackupPollDuration(dur time.Duration) AcquirerOption

type AcquirerStore added in v2.2.0

type AcquirerStore interface {
	AcquireProvisionerJob(context.Context, database.AcquireProvisionerJobParams) (database.ProvisionerJob, error)
}

AcquirerStore is the subset of database.Store that the Acquirer needs

type Options added in v2.1.5

type Options struct {
	OIDCConfig          promoauth.OAuth2Config
	ExternalAuthConfigs []*externalauth.Config
	// TimeNowFn is only used in tests
	TimeNowFn func() time.Time

	// AcquireJobLongPollDur is used in tests
	AcquireJobLongPollDur time.Duration

	// HeartbeatInterval is the interval at which the provisioner daemon
	// will update its last seen at timestamp in the database.
	HeartbeatInterval time.Duration

	// HeartbeatFn is the function that will be called at the interval
	// specified by HeartbeatInterval.
	// The default function just calls UpdateProvisionerDaemonLastSeenAt.
	// This is mainly used for testing.
	HeartbeatFn func(context.Context) error
}

type Tags added in v2.2.0

type Tags map[string]string

func (Tags) ToJSON added in v2.2.0

func (t Tags) ToJSON() (json.RawMessage, error)

func (Tags) Valid added in v2.2.0

func (t Tags) Valid() error

type TemplateVersionDryRunJob

type TemplateVersionDryRunJob struct {
	TemplateVersionID   uuid.UUID                          `json:"template_version_id"`
	WorkspaceName       string                             `json:"workspace_name"`
	RichParameterValues []database.WorkspaceBuildParameter `json:"rich_parameter_values"`
}

TemplateVersionDryRunJob is the payload for the "template_version_dry_run" job type.

type TemplateVersionImportJob

type TemplateVersionImportJob struct {
	TemplateVersionID  uuid.UUID                `json:"template_version_id"`
	UserVariableValues []codersdk.VariableValue `json:"user_variable_values"`
}

type WorkspaceProvisionJob

type WorkspaceProvisionJob struct {
	WorkspaceBuildID uuid.UUID `json:"workspace_build_id"`
	DryRun           bool      `json:"dry_run"`
	LogLevel         string    `json:"log_level,omitempty"`
}

WorkspaceProvisionJob is the payload for the "workspace_provision" job type.

Jump to

Keyboard shortcuts

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