abstractions

package
v0.0.0-...-f65cf3b Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2024 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const IgnoreScalingEventInterval = 10 * time.Second

Variables

This section is empty.

Functions

func ConfigureContainerRequestMounts

func ConfigureContainerRequestMounts(stubObjectId string, workspace *types.Workspace, config types.StubConfigV1, stubId string) ([]types.Mount, error)

func ConfigureContainerRequestSecrets

func ConfigureContainerRequestSecrets(
	workspace *types.Workspace,
	stubConfig types.StubConfigV1,
) ([]string, error)

Types

type AutoscaledInstance

type AutoscaledInstance struct {
	Ctx                      context.Context
	AppConfig                types.AppConfig
	CancelFunc               context.CancelFunc
	Name                     string
	Rdb                      *common.RedisClient
	Lock                     *common.RedisLock
	IsActive                 bool
	FailedContainerThreshold int

	// DB objects
	Workspace  *types.Workspace
	Stub       *types.StubWithRelated
	StubConfig *types.StubConfigV1
	Object     *types.Object
	Token      *types.Token

	// Scheduling
	Scheduler          *scheduler.Scheduler
	ContainerEventChan chan types.ContainerEvent
	Containers         map[string]bool
	ScaleEventChan     chan int
	EntryPoint         []string
	Autoscaler         IAutoscaler

	// Repositories
	ContainerRepo repository.ContainerRepository
	BackendRepo   repository.BackendRepository
	TaskRepo      repository.TaskRepository

	// Keys
	InstanceLockKey string

	// Callbacks
	StartContainersFunc func(containersToRun int) error
	StopContainersFunc  func(containersToStop int) error
}

func (*AutoscaledInstance) ConsumeContainerEvent

func (i *AutoscaledInstance) ConsumeContainerEvent(event types.ContainerEvent)

func (*AutoscaledInstance) ConsumeScaleResult

func (i *AutoscaledInstance) ConsumeScaleResult(result *AutoscalerResult)

func (*AutoscaledInstance) HandleScalingEvent

func (i *AutoscaledInstance) HandleScalingEvent(desiredContainers int) error

func (*AutoscaledInstance) Monitor

func (i *AutoscaledInstance) Monitor() error

func (*AutoscaledInstance) Reload

func (i *AutoscaledInstance) Reload() error

Reload updates state that should be changed on the instance. If a stub has a deployment associated with it, we update the IsActive field.

func (*AutoscaledInstance) State

func (*AutoscaledInstance) WaitForContainer

func (i *AutoscaledInstance) WaitForContainer(ctx context.Context, duration time.Duration) (*types.ContainerState, error)

type AutoscaledInstanceConfig

type AutoscaledInstanceConfig struct {
	Name                string
	AppConfig           types.AppConfig
	Workspace           *types.Workspace
	Stub                *types.StubWithRelated
	StubConfig          *types.StubConfigV1
	Object              *types.Object
	Token               *types.Token
	Scheduler           *scheduler.Scheduler
	Rdb                 *common.RedisClient
	InstanceLockKey     string
	ContainerRepo       repository.ContainerRepository
	BackendRepo         repository.BackendRepository
	TaskRepo            repository.TaskRepository
	StartContainersFunc func(containersToRun int) error
	StopContainersFunc  func(containersToStop int) error
}

type AutoscaledInstanceState

type AutoscaledInstanceState struct {
	RunningContainers  int
	PendingContainers  int
	StoppingContainers int
	FailedContainers   int
}

type Autoscaler

type Autoscaler[I IAutoscaledInstance, S AutoscalerSample] struct {
	// contains filtered or unexported fields
}

func NewAutoscaler

func NewAutoscaler[I IAutoscaledInstance, S AutoscalerSample](instance I, sampleFunc func(I) (S, error), scaleFunc func(I, S) *AutoscalerResult) *Autoscaler[I, S]

func (*Autoscaler[I, S]) Start

func (as *Autoscaler[I, S]) Start(ctx context.Context)

Start the autoscaler

type AutoscalerResult

type AutoscalerResult struct {
	DesiredContainers int
	ResultValid       bool
}

type AutoscalerSample

type AutoscalerSample interface{}

type ContainerEventManager

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

func NewContainerEventManager

func NewContainerEventManager(containerPrefix string, keyEventManager *common.KeyEventManager, instanceFactory func(stubId string, options ...func(IAutoscaledInstance)) (IAutoscaledInstance, error)) (*ContainerEventManager, error)

func (*ContainerEventManager) Listen

func (em *ContainerEventManager) Listen(ctx context.Context)

type IAutoscaledInstance

type IAutoscaledInstance interface {
	ConsumeScaleResult(*AutoscalerResult)
	ConsumeContainerEvent(types.ContainerEvent)
}

type IAutoscaler

type IAutoscaler interface {
	Start(ctx context.Context)
}

type LogStream

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

func NewLogStream

func NewLogStream(opts LogStreamOpts) (*LogStream, error)

func (*LogStream) Stream

func (l *LogStream) Stream(ctx context.Context, authInfo *auth.AuthInfo, containerId string) error

type LogStreamOpts

type LogStreamOpts struct {
	SendCallback    func(o common.OutputMsg) error
	ExitCallback    func(exitCode int32) error
	ContainerRepo   repository.ContainerRepository
	Tailscale       *network.Tailscale
	Config          types.AppConfig
	KeyEventManager *common.KeyEventManager
}

type RingBuffer

type RingBuffer[T any] struct {
	// contains filtered or unexported fields
}

func NewRingBuffer

func NewRingBuffer[T any](size int) *RingBuffer[T]

func (*RingBuffer[T]) Len

func (rb *RingBuffer[T]) Len() int

func (*RingBuffer[T]) Pop

func (rb *RingBuffer[T]) Pop() (T, bool)

Pop retrieves and removes the oldest request from the buffer

func (*RingBuffer[T]) Push

func (rb *RingBuffer[T]) Push(request T, priority bool)

Push adds a new request to the buffer. If priority is true, it gets inserted at the front of the buffer

Jump to

Keyboard shortcuts

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