Skip to content

Commit 70f6249

Browse files
committed
pass now to rollup
1 parent 7e2ec9f commit 70f6249

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

coderd/workspaceapps/stats.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ func (sc *StatsCollector) Collect(report StatsReport) {
216216
// rollup performs stats rollup for sessions that fall within the
217217
// configured rollup window. For sessions longer than the window,
218218
// we report them individually.
219-
func (sc *StatsCollector) rollup() []StatsReport {
219+
func (sc *StatsCollector) rollup(now time.Time) []StatsReport {
220220
sc.mu.Lock()
221221
defer sc.mu.Unlock()
222222

@@ -259,7 +259,7 @@ func (sc *StatsCollector) rollup() []StatsReport {
259259
rollupChanged = true
260260
continue
261261
}
262-
if stat.SessionEndedAt.IsZero() && sc.opts.Now().Sub(stat.SessionStartedAt) <= sc.opts.RollupWindow {
262+
if stat.SessionEndedAt.IsZero() && now.Sub(stat.SessionStartedAt) <= sc.opts.RollupWindow {
263263
// This is an incomplete session, wait and see if it'll be rolled up or not.
264264
newGroup = append(newGroup, stat)
265265
continue
@@ -272,7 +272,7 @@ func (sc *StatsCollector) rollup() []StatsReport {
272272
// Report an end time for incomplete sessions, it will
273273
// be updated later. This ensures that data in the DB
274274
// will have an end time even if the service is stopped.
275-
r.SessionEndedAt = sc.opts.Now().UTC() // Use UTC like database.Now().
275+
r.SessionEndedAt = now.UTC() // Use UTC like database.Now().
276276
}
277277
report = append(report, r) // Report it (ended or incomplete).
278278
if stat.SessionEndedAt.IsZero() {
@@ -288,7 +288,7 @@ func (sc *StatsCollector) rollup() []StatsReport {
288288

289289
// Keep the group around until the next rollup window has passed
290290
// in case data was collected late.
291-
if len(newGroup) == 1 && rolledUp.SessionEndedAt.Add(sc.opts.RollupWindow).Before(sc.opts.Now()) {
291+
if len(newGroup) == 1 && rolledUp.SessionEndedAt.Add(sc.opts.RollupWindow).Before(now) {
292292
delete(sc.groupedStats, g)
293293
}
294294
}
@@ -321,7 +321,8 @@ func (sc *StatsCollector) flush(ctx context.Context) (err error) {
321321
sc.backlog = nil
322322
}
323323

324-
stats := sc.rollup()
324+
now := sc.opts.Now()
325+
stats := sc.rollup(now)
325326
if len(stats) == 0 {
326327
return nil
327328
}

0 commit comments

Comments
 (0)