MCPcopy Index your code
hub / github.com/coder/coder / Collect

Method Collect

coderd/workspaceapps/stats.go:137–157  ·  view source on GitHub ↗

Collect the given StatsReport for later reporting (non-blocking).

(report StatsReport)

Source from the content-addressed store, hash-verified

135
136// Collect the given StatsReport for later reporting (non-blocking).
137func (sc *StatsCollector) Collect(report StatsReport) {
138 sc.mu.Lock()
139 defer sc.mu.Unlock()
140
141 r := &report
142 if _, ok := sc.statsBySessionID[report.SessionID]; !ok {
143 groupKey := r.groupKey(sc.opts.RollupWindow)
144 sc.groupedStats[groupKey] = append(sc.groupedStats[groupKey], r)
145 }
146
147 if r.SessionEndedAt.IsZero() {
148 sc.statsBySessionID[report.SessionID] = r
149 } else {
150 if stat, ok := sc.statsBySessionID[report.SessionID]; ok {
151 // Update in-place.
152 *stat = *r
153 }
154 delete(sc.statsBySessionID, report.SessionID)
155 }
156 sc.opts.Logger.Debug(sc.ctx, "collected workspace app stats", slog.F("report", report))
157}
158
159// rollup performs stats rollup for sessions that fall within the
160// configured rollup window. For sessions longer than the window,

Callers 3

TestStatsCollectorFunction · 0.95
TestStatsCollector_CloseFunction · 0.95

Calls 4

groupKeyMethod · 0.80
LockMethod · 0.45
UnlockMethod · 0.45
IsZeroMethod · 0.45

Tested by 3

TestStatsCollectorFunction · 0.76
TestStatsCollector_CloseFunction · 0.76