agentapi

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: 39 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ActivityBumpWorkspace

func ActivityBumpWorkspace(ctx context.Context, log slog.Logger, db database.Store, workspaceID uuid.UUID, nextAutostart time.Time)

ActivityBumpWorkspace automatically bumps the workspace's auto-off timer if it is set to expire soon. The deadline will be bumped by 1 hour*. If the bump crosses over an autostart time, the workspace will be bumped by the workspace ttl instead.

If nextAutostart is the zero value or in the past, the workspace will be bumped by 1 hour. It handles the edge case in the example:

  1. Autostart is set to 9am.
  2. User works all day, and leaves a terminal open to the workspace overnight.
  3. The open terminal continually bumps the workspace deadline.
  4. 9am the next day, the activity bump pushes to 10am.
  5. If the user goes inactive for 1 hour during the day, the workspace will now stop, because it has been extended by 1 hour durations. Despite the TTL being set to 8hrs from the autostart time.

So the issue is that when the workspace is bumped across an autostart deadline, we should treat the workspace as being "started" again and extend the deadline by the autostart time + workspace ttl instead.

The issue still remains with build_max_deadline. We need to respect the original maximum deadline, so that will need to be handled separately. A way to avoid this is to configure the max deadline to something that will not span more than 1 day. This will force the workspace to restart and reset the deadline each morning when it autostarts.

func WatchWorkspaceAgentMetadataChannel

func WatchWorkspaceAgentMetadataChannel(id uuid.UUID) string

func WithAPIVersion added in v2.8.0

func WithAPIVersion(ctx context.Context, version string) context.Context

Types

type API

type API struct {
	*ManifestAPI
	*ServiceBannerAPI
	*StatsAPI
	*LifecycleAPI
	*AppsAPI
	*MetadataAPI
	*LogsAPI
	*tailnet.DRPCService
	// contains filtered or unexported fields
}

API implements the DRPC agent API interface from agent/proto. This struct is instantiated once per agent connection and kept alive for the duration of the session.

func New

func New(opts Options) *API

func (*API) Serve

func (a *API) Serve(ctx context.Context, l net.Listener) error

func (*API) Server

func (a *API) Server(ctx context.Context) (*drpcserver.Server, error)

type AppsAPI

type AppsAPI struct {
	AgentFn                  func(context.Context) (database.WorkspaceAgent, error)
	Database                 database.Store
	Log                      slog.Logger
	PublishWorkspaceUpdateFn func(context.Context, *database.WorkspaceAgent) error
}

type LifecycleAPI

type LifecycleAPI struct {
	AgentFn                  func(context.Context) (database.WorkspaceAgent, error)
	WorkspaceIDFn            func(context.Context, *database.WorkspaceAgent) (uuid.UUID, error)
	Database                 database.Store
	Log                      slog.Logger
	PublishWorkspaceUpdateFn func(context.Context, *database.WorkspaceAgent) error

	TimeNowFn func() time.Time // defaults to dbtime.Now()
}

func (*LifecycleAPI) UpdateLifecycle

func (*LifecycleAPI) UpdateStartup

type LogsAPI

type LogsAPI struct {
	AgentFn                           func(context.Context) (database.WorkspaceAgent, error)
	Database                          database.Store
	Log                               slog.Logger
	PublishWorkspaceUpdateFn          func(context.Context, *database.WorkspaceAgent) error
	PublishWorkspaceAgentLogsUpdateFn func(ctx context.Context, workspaceAgentID uuid.UUID, msg agentsdk.LogsNotifyMessage)

	TimeNowFn func() time.Time // defaults to dbtime.Now()
}

type ManifestAPI

type ManifestAPI struct {
	AccessURL                *url.URL
	AppHostname              string
	ExternalAuthConfigs      []*externalauth.Config
	DisableDirectConnections bool
	DerpForceWebSockets      bool

	AgentFn       func(context.Context) (database.WorkspaceAgent, error)
	WorkspaceIDFn func(context.Context, *database.WorkspaceAgent) (uuid.UUID, error)
	Database      database.Store
	DerpMapFn     func() *tailcfg.DERPMap
}

func (*ManifestAPI) GetManifest

type MetadataAPI

type MetadataAPI struct {
	AgentFn  func(context.Context) (database.WorkspaceAgent, error)
	Database database.Store
	Pubsub   pubsub.Pubsub
	Log      slog.Logger

	TimeNowFn func() time.Time // defaults to dbtime.Now()
}

type Options

type Options struct {
	AgentID uuid.UUID

	Ctx                               context.Context
	Log                               slog.Logger
	Database                          database.Store
	Pubsub                            pubsub.Pubsub
	DerpMapFn                         func() *tailcfg.DERPMap
	TailnetCoordinator                *atomic.Pointer[tailnet.Coordinator]
	TemplateScheduleStore             *atomic.Pointer[schedule.TemplateScheduleStore]
	StatsBatcher                      StatsBatcher
	AppearanceFetcher                 *atomic.Pointer[appearance.Fetcher]
	PublishWorkspaceUpdateFn          func(ctx context.Context, workspaceID uuid.UUID)
	PublishWorkspaceAgentLogsUpdateFn func(ctx context.Context, workspaceAgentID uuid.UUID, msg agentsdk.LogsNotifyMessage)

	AccessURL                 *url.URL
	AppHostname               string
	AgentStatsRefreshInterval time.Duration
	DisableDirectConnections  bool
	DerpForceWebSockets       bool
	DerpMapUpdateFrequency    time.Duration
	ExternalAuthConfigs       []*externalauth.Config

	// Optional:
	// WorkspaceID avoids a future lookup to find the workspace ID by setting
	// the cache in advance.
	WorkspaceID          uuid.UUID
	UpdateAgentMetricsFn func(ctx context.Context, labels prometheusmetrics.AgentMetricLabels, metrics []*agentproto.Stats_Metric)
}

type ServiceBannerAPI

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

func (*ServiceBannerAPI) GetServiceBanner

type StatsAPI

type StatsAPI struct {
	AgentFn                   func(context.Context) (database.WorkspaceAgent, error)
	Database                  database.Store
	Pubsub                    pubsub.Pubsub
	Log                       slog.Logger
	StatsBatcher              StatsBatcher
	TemplateScheduleStore     *atomic.Pointer[schedule.TemplateScheduleStore]
	AgentStatsRefreshInterval time.Duration
	UpdateAgentMetricsFn      func(ctx context.Context, labels prometheusmetrics.AgentMetricLabels, metrics []*agentproto.Stats_Metric)

	TimeNowFn func() time.Time // defaults to dbtime.Now()
}

func (*StatsAPI) UpdateStats

type StatsBatcher added in v2.8.0

type StatsBatcher interface {
	Add(now time.Time, agentID uuid.UUID, templateID uuid.UUID, userID uuid.UUID, workspaceID uuid.UUID, st *agentproto.Stats) error
}

type WorkspaceAgentMetadataChannelPayload

type WorkspaceAgentMetadataChannelPayload struct {
	CollectedAt time.Time `json:"collected_at"`
	Keys        []string  `json:"keys"`
}

Jump to

Keyboard shortcuts

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