(t *testing.T)
| 113 | } |
| 114 | |
| 115 | func TestGetDeploymentWorkspaceAgentUsageStats(t *testing.T) { |
| 116 | t.Parallel() |
| 117 | |
| 118 | t.Run("Aggregates", func(t *testing.T) { |
| 119 | t.Parallel() |
| 120 | |
| 121 | db, _ := dbtestutil.NewDB(t) |
| 122 | authz := rbac.NewAuthorizer(prometheus.NewRegistry()) |
| 123 | db = dbauthz.New(db, authz, slogtest.Make(t, &slogtest.Options{}), coderdtest.AccessControlStorePointer()) |
| 124 | ctx := context.Background() |
| 125 | agentID := uuid.New() |
| 126 | // Since the queries exclude the current minute |
| 127 | insertTime := dbtime.Now().Add(-time.Minute) |
| 128 | |
| 129 | // Old stats |
| 130 | dbgen.WorkspaceAgentStat(t, db, database.WorkspaceAgentStat{ |
| 131 | CreatedAt: insertTime.Add(-time.Minute), |
| 132 | AgentID: agentID, |
| 133 | TxBytes: 1, |
| 134 | RxBytes: 1, |
| 135 | ConnectionMedianLatencyMS: 1, |
| 136 | // Should be ignored |
| 137 | SessionCountSSH: 4, |
| 138 | SessionCountVSCode: 3, |
| 139 | }) |
| 140 | dbgen.WorkspaceAgentStat(t, db, database.WorkspaceAgentStat{ |
| 141 | CreatedAt: insertTime.Add(-time.Minute), |
| 142 | AgentID: agentID, |
| 143 | SessionCountVSCode: 1, |
| 144 | Usage: true, |
| 145 | }) |
| 146 | dbgen.WorkspaceAgentStat(t, db, database.WorkspaceAgentStat{ |
| 147 | CreatedAt: insertTime.Add(-time.Minute), |
| 148 | AgentID: agentID, |
| 149 | SessionCountReconnectingPTY: 1, |
| 150 | Usage: true, |
| 151 | }) |
| 152 | |
| 153 | // Latest stats |
| 154 | dbgen.WorkspaceAgentStat(t, db, database.WorkspaceAgentStat{ |
| 155 | CreatedAt: insertTime, |
| 156 | AgentID: agentID, |
| 157 | TxBytes: 1, |
| 158 | RxBytes: 1, |
| 159 | ConnectionMedianLatencyMS: 2, |
| 160 | // Should be ignored |
| 161 | SessionCountSSH: 3, |
| 162 | SessionCountVSCode: 1, |
| 163 | }) |
| 164 | dbgen.WorkspaceAgentStat(t, db, database.WorkspaceAgentStat{ |
| 165 | CreatedAt: insertTime, |
| 166 | AgentID: agentID, |
| 167 | SessionCountVSCode: 1, |
| 168 | Usage: true, |
| 169 | }) |
| 170 | dbgen.WorkspaceAgentStat(t, db, database.WorkspaceAgentStat{ |
| 171 | CreatedAt: insertTime, |
| 172 | AgentID: agentID, |
nothing calls this directly
no test coverage detected