Documentation ¶
Index ¶
- func ActivityBumpWorkspace(ctx context.Context, log slog.Logger, db database.Store, workspaceID uuid.UUID, ...)
- func WatchWorkspaceAgentMetadataChannel(id uuid.UUID) string
- func WithAPIVersion(ctx context.Context, version string) context.Context
- type API
- type AppsAPI
- type LifecycleAPI
- type LogsAPI
- type ManifestAPI
- type MetadataAPI
- type Options
- type ServiceBannerAPI
- type StatsAPI
- type StatsBatcher
- type WorkspaceAgentMetadataChannelPayload
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:
- Autostart is set to 9am.
- User works all day, and leaves a terminal open to the workspace overnight.
- The open terminal continually bumps the workspace deadline.
- 9am the next day, the activity bump pushes to 10am.
- 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.
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.
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 }
func (*AppsAPI) BatchUpdateAppHealths ¶
func (a *AppsAPI) BatchUpdateAppHealths(ctx context.Context, req *agentproto.BatchUpdateAppHealthRequest) (*agentproto.BatchUpdateAppHealthResponse, 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 (a *LifecycleAPI) UpdateLifecycle(ctx context.Context, req *agentproto.UpdateLifecycleRequest) (*agentproto.Lifecycle, error)
func (*LifecycleAPI) UpdateStartup ¶
func (a *LifecycleAPI) UpdateStartup(ctx context.Context, req *agentproto.UpdateStartupRequest) (*agentproto.Startup, error)
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() }
func (*LogsAPI) BatchCreateLogs ¶
func (a *LogsAPI) BatchCreateLogs(ctx context.Context, req *agentproto.BatchCreateLogsRequest) (*agentproto.BatchCreateLogsResponse, error)
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 ¶
func (a *ManifestAPI) GetManifest(ctx context.Context, _ *agentproto.GetManifestRequest) (*agentproto.Manifest, error)
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() }
func (*MetadataAPI) BatchUpdateMetadata ¶
func (a *MetadataAPI) BatchUpdateMetadata(ctx context.Context, req *agentproto.BatchUpdateMetadataRequest) (*agentproto.BatchUpdateMetadataResponse, error)
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 ¶
func (a *ServiceBannerAPI) GetServiceBanner(ctx context.Context, _ *proto.GetServiceBannerRequest) (*proto.ServiceBanner, error)
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 ¶
func (a *StatsAPI) UpdateStats(ctx context.Context, req *agentproto.UpdateStatsRequest) (*agentproto.UpdateStatsResponse, error)