Collect the given StatsReport for later reporting (non-blocking).
(report StatsReport)
| 135 | |
| 136 | // Collect the given StatsReport for later reporting (non-blocking). |
| 137 | func (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, |