workspacestats
packageThis package is not in the latest version of its module.
Details
Validgo.mod file
The Go module system was introduced in Go 1.11 and is the official dependency management solution for Go.
Redistributable license
Redistributable licenses place minimal restrictions on how software can be used, modified, and redistributed.
Tagged version
Modules with tagged versions give importers more predictable builds.
Stable version
When a project reaches major version v1 it is considered stable.
- Learn more about best practices
Repository
Links
Documentation¶
Index¶
- Variables
- func ActivityBumpWorkspace(ctx context.Context, log slog.Logger, db database.Store, workspaceID uuid.UUID, ...)
- func UpdateTemplateWorkspacesLastUsedAt(ctx context.Context, db database.Store, templateID uuid.UUID, ...) error
- type Batcher
- type BatcherOption
- type DBBatcher
- type Reporter
- type ReporterOptions
- type Store
- type TrackerOption
- type UpdateTemplateWorkspacesLastUsedAtFunc
- type UsageTracker
Constants¶
This section is empty.
Variables¶
var DefaultFlushInterval = 60 *time.Second
Functions¶
funcActivityBumpWorkspace¶
func ActivityBumpWorkspace(ctxcontext.Context, logslog.Logger, dbdatabase.Store, workspaceIDuuid.UUID, nextAutostarttime.Time)
ActivityBumpWorkspace automatically bumps the workspace's auto-off timerif 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 bebumped by the workspace ttl instead.
If nextAutostart is the zero value or in the past, the workspacewill 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 willnow stop, because it has been extended by 1 hour durations. Despite the TTLbeing set to 8hrs from the autostart time.
So the issue is that when the workspace is bumped across an autostartdeadline, we should treat the workspace as being "started" again andextend the deadline by the autostart time + workspace ttl instead.
The issue still remains with build_max_deadline. We need to respect the originalmaximum deadline, so that will need to be handled separately.A way to avoid this is to configure the max deadline to something that will notspan more than 1 day. This will force the workspace to restart and reset the deadlineeach morning when it autostarts.
Types¶
typeBatcherOption¶added inv2.13.0
type BatcherOption func(b *DBBatcher)
Option is a functional option for configuring a Batcher.
funcBatcherWithBatchSize¶added inv2.13.0
func BatcherWithBatchSize(sizeint)BatcherOption
BatcherWithBatchSize sets the number of stats to store in a batch.
funcBatcherWithInterval¶added inv2.13.0
func BatcherWithInterval(dtime.Duration)BatcherOption
BatcherWithInterval sets the interval for flushes.
funcBatcherWithLogger¶added inv2.13.0
func BatcherWithLogger(logslog.Logger)BatcherOption
BatcherWithLogger sets the logger to use for logging.
funcBatcherWithStore¶added inv2.13.0
func BatcherWithStore(storedatabase.Store)BatcherOption
BatcherWithStore sets the store to use for storing stats.
typeDBBatcher¶added inv2.13.0
type DBBatcher struct {// contains filtered or unexported fields}
DBBatcher holds a buffer of agent stats and periodically flushes them toits configured store.
funcNewBatcher¶added inv2.13.0
func NewBatcher(ctxcontext.Context, opts ...BatcherOption) (*DBBatcher, func(),error)
NewBatcher creates a new Batcher and starts it.
typeReporter¶
type Reporter struct {// contains filtered or unexported fields}
funcNewReporter¶
func NewReporter(optsReporterOptions) *Reporter
func (*Reporter)ReportAgentStats¶
func (r *Reporter) ReportAgentStats(ctxcontext.Context, nowtime.Time, workspacedatabase.Workspace, workspaceAgentdatabase.WorkspaceAgent, templateNamestring, stats *agentproto.Stats, usagebool)error
nolint:revive // usage is a control flag while we have the experiment
func (*Reporter)ReportAppStats¶
func (r *Reporter) ReportAppStats(ctxcontext.Context, stats []workspaceapps.StatsReport)error
func (*Reporter)TrackUsage¶added inv2.13.0
typeReporterOptions¶
type ReporterOptions struct {Databasedatabase.StoreLoggerslog.LoggerPubsubpubsub.PubsubTemplateScheduleStore *atomic.Pointer[schedule.TemplateScheduleStore]StatsBatcherBatcherUsageTracker *UsageTrackerUpdateAgentMetricsFn func(ctxcontext.Context, labelsprometheusmetrics.AgentMetricLabels, metrics []*agentproto.Stats_Metric)AppStatBatchSizeint}
typeStore¶added inv2.13.0
type Store interface {BatchUpdateWorkspaceLastUsedAt(context.Context,database.BatchUpdateWorkspaceLastUsedAtParams)error}
Store is a subset of database.Store
typeTrackerOption¶added inv2.13.0
type TrackerOption func(*UsageTracker)
funcTrackerWithFlushInterval¶added inv2.13.0
func TrackerWithFlushInterval(dtime.Duration)TrackerOption
TrackerWithFlushInterval allows configuring the flush interval of Tracker.
funcTrackerWithLogger¶added inv2.13.0
func TrackerWithLogger(logslog.Logger)TrackerOption
TrackerWithLogger sets the logger to be used by Tracker.
funcTrackerWithTickFlush¶added inv2.13.0
func TrackerWithTickFlush(tickCh <-chantime.Time, flushCh chanint)TrackerOption
TrackerWithTickFlush allows passing two channels: one that readsa time.Time, and one that returns the number of marked workspacesevery time Tracker flushes.For testing only and will panic if used outside of tests.
typeUsageTracker¶added inv2.13.0
type UsageTracker struct {// contains filtered or unexported fields}
UsageTracker tracks and de-bounces updates to workspace usage activity.It keeps an internal map of workspace IDs that have been used andperiodically flushes this to its configured Store.
funcNewTracker¶added inv2.13.0
func NewTracker(sStore, opts ...TrackerOption) *UsageTracker
NewTracker returns a new Tracker. It is the caller's responsibilityto call Close().
func (*UsageTracker)Add¶added inv2.13.0
func (tr *UsageTracker) Add(workspaceIDuuid.UUID)
Add marks the workspace with the given ID as having been used recently.Tracker will periodically flush this to its configured Store.
func (*UsageTracker)Close¶added inv2.13.0
func (tr *UsageTracker) Close()error
Close stops Tracker and returns once Loop has exited.After calling Close(), Loop must not be called.