Movatterモバイル変換


[0]ホーム

URL:


workspacestats

package
v2.23.1Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2025 License:AGPL-3.0Imports:23Imported by:0

Details

Repository

github.com/coder/coder

Links

Documentation

Index

Constants

This section is empty.

Variables

View Source
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:

  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 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.

funcUpdateTemplateWorkspacesLastUsedAt

func UpdateTemplateWorkspacesLastUsedAt(ctxcontext.Context, dbdatabase.Store, templateIDuuid.UUID, lastUsedAttime.Time)error

Types

typeBatcheradded inv2.13.0

type Batcher interface {Add(nowtime.Time, agentIDuuid.UUID, templateIDuuid.UUID, userIDuuid.UUID, workspaceIDuuid.UUID, st *agentproto.Stats, usagebool)}

typeBatcherOptionadded inv2.13.0

type BatcherOption func(b *DBBatcher)

Option is a functional option for configuring a Batcher.

funcBatcherWithBatchSizeadded inv2.13.0

func BatcherWithBatchSize(sizeint)BatcherOption

BatcherWithBatchSize sets the number of stats to store in a batch.

funcBatcherWithIntervaladded inv2.13.0

func BatcherWithInterval(dtime.Duration)BatcherOption

BatcherWithInterval sets the interval for flushes.

funcBatcherWithLoggeradded inv2.13.0

func BatcherWithLogger(logslog.Logger)BatcherOption

BatcherWithLogger sets the logger to use for logging.

funcBatcherWithStoreadded inv2.13.0

func BatcherWithStore(storedatabase.Store)BatcherOption

BatcherWithStore sets the store to use for storing stats.

typeDBBatcheradded 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.

funcNewBatcheradded inv2.13.0

func NewBatcher(ctxcontext.Context, opts ...BatcherOption) (*DBBatcher, func(),error)

NewBatcher creates a new Batcher and starts it.

func (*DBBatcher)Addadded inv2.13.0

func (b *DBBatcher) Add(nowtime.Time,agentIDuuid.UUID,templateIDuuid.UUID,userIDuuid.UUID,workspaceIDuuid.UUID,st *agentproto.Stats,usagebool,)

Add adds a stat to the batcher for the given workspace and agent.

typeReporter

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

funcNewReporter

func NewReporter(optsReporterOptions) *Reporter

func (*Reporter)Closeadded inv2.13.0

func (r *Reporter) Close()error

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)TrackUsageadded inv2.13.0

func (r *Reporter) TrackUsage(workspaceIDuuid.UUID)

typeReporterOptions

type ReporterOptions struct {Databasedatabase.StoreLoggerslog.LoggerPubsubpubsub.PubsubTemplateScheduleStore *atomic.Pointer[schedule.TemplateScheduleStore]StatsBatcherBatcherUsageTracker          *UsageTrackerUpdateAgentMetricsFn  func(ctxcontext.Context, labelsprometheusmetrics.AgentMetricLabels, metrics []*agentproto.Stats_Metric)AppStatBatchSizeint}

typeStoreadded inv2.13.0

type Store interface {BatchUpdateWorkspaceLastUsedAt(context.Context,database.BatchUpdateWorkspaceLastUsedAtParams)error}

Store is a subset of database.Store

typeTrackerOptionadded inv2.13.0

type TrackerOption func(*UsageTracker)

funcTrackerWithFlushIntervaladded inv2.13.0

func TrackerWithFlushInterval(dtime.Duration)TrackerOption

TrackerWithFlushInterval allows configuring the flush interval of Tracker.

funcTrackerWithLoggeradded inv2.13.0

func TrackerWithLogger(logslog.Logger)TrackerOption

TrackerWithLogger sets the logger to be used by Tracker.

funcTrackerWithTickFlushadded 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.

typeUpdateTemplateWorkspacesLastUsedAtFunc

type UpdateTemplateWorkspacesLastUsedAtFunc func(ctxcontext.Context, dbdatabase.Store, templateIDuuid.UUID, lastUsedAttime.Time)error

typeUsageTrackeradded 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.

funcNewTrackeradded inv2.13.0

func NewTracker(sStore, opts ...TrackerOption) *UsageTracker

NewTracker returns a new Tracker. It is the caller's responsibilityto call Close().

func (*UsageTracker)Addadded 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)Closeadded 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.

Source Files

View all Source files

Directories

PathSynopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f orF : Jump to
y orY : Canonical URL
go.dev uses cookies from Google to deliver and enhance the quality of its services and to analyze traffic.Learn more.

[8]ページ先頭

©2009-2025 Movatter.jp