mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
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:
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user