chore: convert agent stats to use a table (#6374)

* chore: convert workspace agent stats from json to table

* chore: convert agent stats to use a table

Backwards compatibility becomes hard when all agent stats are in a JSON blob.
We also want to query this table for new agents that are failing health checks
so we can display it in the UI.

* Fix migration using default values
This commit is contained in:
Kyle Carberry
2023-02-28 13:33:33 -06:00
committed by GitHub
parent 7cf1e20aac
commit 05e449943d
22 changed files with 306 additions and 234 deletions
+1 -1
View File
@@ -145,7 +145,7 @@ func countUniqueUsers(rows []database.GetTemplateDAUsRow) int {
func (c *Cache) refresh(ctx context.Context) error {
//nolint:gocritic // This is a system service.
ctx = dbauthz.AsSystemRestricted(ctx)
err := c.database.DeleteOldAgentStats(ctx)
err := c.database.DeleteOldWorkspaceAgentStats(ctx)
if err != nil {
return xerrors.Errorf("delete old stats: %w", err)
}
+5 -5
View File
@@ -31,7 +31,7 @@ func TestCache_TemplateUsers(t *testing.T) {
)
type args struct {
rows []database.InsertAgentStatParams
rows []database.InsertWorkspaceAgentStatParams
}
type want struct {
entries []codersdk.DAUEntry
@@ -45,7 +45,7 @@ func TestCache_TemplateUsers(t *testing.T) {
{"empty", args{}, want{nil, 0}},
{
"one hole", args{
rows: []database.InsertAgentStatParams{
rows: []database.InsertWorkspaceAgentStatParams{
{
CreatedAt: date(2022, 8, 27),
UserID: zebra,
@@ -75,7 +75,7 @@ func TestCache_TemplateUsers(t *testing.T) {
}, 1},
},
{"no holes", args{
rows: []database.InsertAgentStatParams{
rows: []database.InsertWorkspaceAgentStatParams{
{
CreatedAt: date(2022, 8, 27),
UserID: zebra,
@@ -104,7 +104,7 @@ func TestCache_TemplateUsers(t *testing.T) {
},
}, 1}},
{"holes", args{
rows: []database.InsertAgentStatParams{
rows: []database.InsertWorkspaceAgentStatParams{
{
CreatedAt: date(2022, 1, 1),
UserID: zebra,
@@ -179,7 +179,7 @@ func TestCache_TemplateUsers(t *testing.T) {
for _, row := range tt.args.rows {
row.TemplateID = template.ID
db.InsertAgentStat(context.Background(), row)
db.InsertWorkspaceAgentStat(context.Background(), row)
}
require.Eventuallyf(t, func() bool {