(t *testing.T)
| 708 | } |
| 709 | |
| 710 | func TestGetWorkspaceAgentUsageStats(t *testing.T) { |
| 711 | t.Parallel() |
| 712 | |
| 713 | t.Run("Aggregates", func(t *testing.T) { |
| 714 | t.Parallel() |
| 715 | |
| 716 | db, _ := dbtestutil.NewDB(t) |
| 717 | authz := rbac.NewAuthorizer(prometheus.NewRegistry()) |
| 718 | db = dbauthz.New(db, authz, slogtest.Make(t, &slogtest.Options{}), coderdtest.AccessControlStorePointer()) |
| 719 | ctx := context.Background() |
| 720 | // Since the queries exclude the current minute |
| 721 | insertTime := dbtime.Now().Add(-time.Minute) |
| 722 | |
| 723 | agentID1 := uuid.New() |
| 724 | agentID2 := uuid.New() |
| 725 | workspaceID1 := uuid.New() |
| 726 | workspaceID2 := uuid.New() |
| 727 | templateID1 := uuid.New() |
| 728 | templateID2 := uuid.New() |
| 729 | userID1 := uuid.New() |
| 730 | userID2 := uuid.New() |
| 731 | |
| 732 | // Old workspace 1 stats |
| 733 | dbgen.WorkspaceAgentStat(t, db, database.WorkspaceAgentStat{ |
| 734 | CreatedAt: insertTime.Add(-time.Minute), |
| 735 | AgentID: agentID1, |
| 736 | WorkspaceID: workspaceID1, |
| 737 | TemplateID: templateID1, |
| 738 | UserID: userID1, |
| 739 | TxBytes: 1, |
| 740 | RxBytes: 1, |
| 741 | ConnectionMedianLatencyMS: 1, |
| 742 | // Should be ignored |
| 743 | SessionCountVSCode: 3, |
| 744 | SessionCountSSH: 1, |
| 745 | }) |
| 746 | dbgen.WorkspaceAgentStat(t, db, database.WorkspaceAgentStat{ |
| 747 | CreatedAt: insertTime.Add(-time.Minute), |
| 748 | AgentID: agentID1, |
| 749 | WorkspaceID: workspaceID1, |
| 750 | TemplateID: templateID1, |
| 751 | UserID: userID1, |
| 752 | SessionCountVSCode: 1, |
| 753 | Usage: true, |
| 754 | }) |
| 755 | |
| 756 | // Latest workspace 1 stats |
| 757 | dbgen.WorkspaceAgentStat(t, db, database.WorkspaceAgentStat{ |
| 758 | CreatedAt: insertTime, |
| 759 | AgentID: agentID1, |
| 760 | WorkspaceID: workspaceID1, |
| 761 | TemplateID: templateID1, |
| 762 | UserID: userID1, |
| 763 | TxBytes: 2, |
| 764 | RxBytes: 2, |
| 765 | ConnectionMedianLatencyMS: 1, |
| 766 | // Should be ignored |
| 767 | SessionCountVSCode: 3, |
nothing calls this directly
no test coverage detected