mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
chore: switch ssh session stats based on experiment (#13637)
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
package workspacestatstest
|
||||
|
||||
import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
|
||||
agentproto "github.com/coder/coder/v2/agent/proto"
|
||||
"github.com/coder/coder/v2/coderd/workspacestats"
|
||||
)
|
||||
|
||||
type StatsBatcher struct {
|
||||
Mu sync.Mutex
|
||||
|
||||
Called int64
|
||||
LastTime time.Time
|
||||
LastAgentID uuid.UUID
|
||||
LastTemplateID uuid.UUID
|
||||
LastUserID uuid.UUID
|
||||
LastWorkspaceID uuid.UUID
|
||||
LastStats *agentproto.Stats
|
||||
}
|
||||
|
||||
var _ workspacestats.Batcher = &StatsBatcher{}
|
||||
|
||||
func (b *StatsBatcher) Add(now time.Time, agentID uuid.UUID, templateID uuid.UUID, userID uuid.UUID, workspaceID uuid.UUID, st *agentproto.Stats) error {
|
||||
b.Mu.Lock()
|
||||
defer b.Mu.Unlock()
|
||||
b.Called++
|
||||
b.LastTime = now
|
||||
b.LastAgentID = agentID
|
||||
b.LastTemplateID = templateID
|
||||
b.LastUserID = userID
|
||||
b.LastWorkspaceID = workspaceID
|
||||
b.LastStats = st
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user