chore: switch ssh session stats based on experiment (#13637)

This commit is contained in:
Garrett Delfosse
2024-06-25 10:58:45 -04:00
committed by GitHub
parent d7eadee4d7
commit fed668b432
14 changed files with 455 additions and 45 deletions
@@ -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
}