mirror of
https://github.com/coder/coder.git
synced 2025-07-15 22:20:27 +00:00
feat: add connection statistics for workspace agents (#6469)
* fix: don't make session counts cumulative This made for some weird tracking... we want the point-in-time number of counts! * Add databasefake query for getting agent stats * Add deployment stats endpoint * The query... works?!? * Fix aggregation query * Select from multiple tables instead * Fix continuous stats * Increase period of stat refreshes * Add workspace counts to deployment stats * fmt * Add a slight bit of responsiveness * Fix template version editor overflow * Add refresh button * Fix font family on button * Fix latest stat being reported * Revert agent conn stats * Fix linting error * Fix tests * Fix gen * Fix migrations * Block on sending stat updates * Add test fixtures * Fix response structure * make gen
This commit is contained in:
@ -5,6 +5,7 @@ import (
|
||||
"crypto/sha256"
|
||||
"database/sql"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net"
|
||||
"testing"
|
||||
@ -437,3 +438,30 @@ func ParameterValue(t testing.TB, db database.Store, seed database.ParameterValu
|
||||
require.NoError(t, err, "insert parameter value")
|
||||
return scheme
|
||||
}
|
||||
|
||||
func WorkspaceAgentStat(t testing.TB, db database.Store, orig database.WorkspaceAgentStat) database.WorkspaceAgentStat {
|
||||
if orig.ConnectionsByProto == nil {
|
||||
orig.ConnectionsByProto = json.RawMessage([]byte("{}"))
|
||||
}
|
||||
scheme, err := db.InsertWorkspaceAgentStat(context.Background(), database.InsertWorkspaceAgentStatParams{
|
||||
ID: takeFirst(orig.ID, uuid.New()),
|
||||
CreatedAt: takeFirst(orig.CreatedAt, database.Now()),
|
||||
UserID: takeFirst(orig.UserID, uuid.New()),
|
||||
TemplateID: takeFirst(orig.TemplateID, uuid.New()),
|
||||
WorkspaceID: takeFirst(orig.WorkspaceID, uuid.New()),
|
||||
AgentID: takeFirst(orig.AgentID, uuid.New()),
|
||||
ConnectionsByProto: orig.ConnectionsByProto,
|
||||
ConnectionCount: takeFirst(orig.ConnectionCount, 0),
|
||||
RxPackets: takeFirst(orig.RxPackets, 0),
|
||||
RxBytes: takeFirst(orig.RxBytes, 0),
|
||||
TxPackets: takeFirst(orig.TxPackets, 0),
|
||||
TxBytes: takeFirst(orig.TxBytes, 0),
|
||||
SessionCountVSCode: takeFirst(orig.SessionCountVSCode, 0),
|
||||
SessionCountJetBrains: takeFirst(orig.SessionCountJetBrains, 0),
|
||||
SessionCountReconnectingPTY: takeFirst(orig.SessionCountReconnectingPTY, 0),
|
||||
SessionCountSSH: takeFirst(orig.SessionCountSSH, 0),
|
||||
ConnectionMedianLatencyMS: takeFirst(orig.ConnectionMedianLatencyMS, 0),
|
||||
})
|
||||
require.NoError(t, err, "insert workspace agent stat")
|
||||
return scheme
|
||||
}
|
||||
|
Reference in New Issue
Block a user