Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
502aa52
agent: add ConnStats
ammario Aug 29, 2022
3893045
agent: add StatsReporter
ammario Aug 29, 2022
c03ad90
Frontend tests pass
ammario Sep 1, 2022
1bd9cec
Split DAUChart into its own file
ammario Sep 1, 2022
e46329b
Get FE tests passing with real data!
ammario Sep 1, 2022
d472b13
Test frontend
ammario Sep 1, 2022
e0295e0
Fix compilation error
ammario Sep 1, 2022
2f1a423
Rename ConnStats to StatsConn
ammario Sep 1, 2022
0a50cc9
continues instead of returns
ammario Sep 1, 2022
7feab5e
Fix some test failures
ammario Sep 1, 2022
a4d2cf7
Redo tests
ammario Sep 1, 2022
52c9d10
Address review comments
ammario Sep 1, 2022
3f9901e
REVAMP — backend tests work
ammario Sep 1, 2022
7840509
Black triangle
ammario Sep 1, 2022
39170cf
Consolidate template state machines
ammario Sep 1, 2022
eb373d6
Move workspaceagent endpoint
ammario Sep 1, 2022
a3d87b8
Address most review comments
ammario Sep 1, 2022
31ba0c6
Improve contrast in chart
ammario Sep 1, 2022
5b906c1
Add more agent tests
ammario Sep 1, 2022
49d9386
Fix JS ci
ammario Sep 1, 2022
b14a077
A bunch of minor touch ups
ammario Sep 1, 2022
8da24c4
Stabilize protoc
ammario Sep 1, 2022
00ec953
Merge remote-tracking branch 'origin/main' into metrics
ammario Sep 1, 2022
4940319
Update lockfile
ammario Sep 1, 2022
22b2028
Address comments + attempt to fix protoc
ammario Sep 1, 2022
0157365
fixup! Address comments + attempt to fix protoc
ammario Sep 1, 2022
b166cdd
Try to fix protoc...
ammario Sep 1, 2022
4201998
PROTO!
ammario Sep 1, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
REVAMP — backend tests work
  • Loading branch information
ammario committed Sep 1, 2022
commit 3f9901ec157daabeb812d995ae0cbe57f8828448
8 changes: 1 addition & 7 deletions coderd/coderd.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ func New(options *Options) *API {
apiKeyMiddleware,
httpmw.ExtractTemplateParam(options.Database),
)

r.Get("/daus", api.templateDAUs)
r.Get("/", api.template)
r.Delete("/", api.deleteTemplate)
r.Patch("/", api.patchTemplateMeta)
Expand Down Expand Up @@ -374,12 +374,6 @@ func New(options *Options) *API {
r.Use(httpmw.ExtractWorkspaceAgent(options.Database))
r.Get("/report-agent-stats", api.workspaceAgentReportStats)
})
r.Group(func(r chi.Router) {
r.Use(
apiKeyMiddleware,
)
r.Get("/daus", api.metricsDAUs)
})
})
r.Route("/workspaceagents", func(r chi.Router) {
r.Post("/azure-instance-identity", api.postWorkspaceAuthAzureInstanceIdentity)
Expand Down
13 changes: 9 additions & 4 deletions coderd/database/databasefake/databasefake.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func (q *fakeQuerier) AcquireProvisionerJob(_ context.Context, arg database.Acqu
}
return database.ProvisionerJob{}, sql.ErrNoRows
}
func (_ *fakeQuerier) DeleteOldAgentStats(_ context.Context) error {
func (*fakeQuerier) DeleteOldAgentStats(_ context.Context) error {
// no-op
return nil
}
Expand All @@ -153,18 +153,23 @@ func (q *fakeQuerier) InsertAgentStat(_ context.Context, p database.InsertAgentS
AgentID: p.AgentID,
UserID: p.UserID,
Payload: p.Payload,
TemplateID: p.TemplateID,
}
q.agentStats = append(q.agentStats, stat)
return stat, nil
}

func (q *fakeQuerier) GetDAUsFromAgentStats(_ context.Context) ([]database.GetDAUsFromAgentStatsRow, error) {
func (q *fakeQuerier) GetTemplateDAUs(_ context.Context, templateID uuid.UUID) ([]database.GetTemplateDAUsRow, error) {
q.mutex.Lock()
defer q.mutex.Unlock()

counts := make(map[time.Time]map[string]struct{})

for _, as := range q.agentStats {
if as.TemplateID != templateID {
continue
}

date := as.CreatedAt.Truncate(time.Hour * 24)
dateEntry := counts[date]
if dateEntry == nil {
Expand All @@ -180,9 +185,9 @@ func (q *fakeQuerier) GetDAUsFromAgentStats(_ context.Context) ([]database.GetDA
return countKeys[i].Before(countKeys[j])
})

var rs []database.GetDAUsFromAgentStatsRow
var rs []database.GetTemplateDAUsRow
for _, key := range countKeys {
rs = append(rs, database.GetDAUsFromAgentStatsRow{
rs = append(rs, database.GetTemplateDAUsRow{
Date: key,
Daus: int64(len(counts[key])),
})
Expand Down
1 change: 1 addition & 0 deletions coderd/database/dump.sql

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions coderd/database/migrations/000042_agent_stats.up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ CREATE TABLE agent_stats (
user_id uuid NOT NULL,
agent_id uuid NOT NULL,
workspace_id uuid NOT NULL,
template_id uuid NOT NULL,
payload jsonb NOT NULL
);

Expand Down
1 change: 1 addition & 0 deletions coderd/database/models.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion coderd/database/querier.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 12 additions & 7 deletions coderd/database/queries.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions coderd/database/queries/agentstats.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,20 @@ INSERT INTO
created_at,
user_id,
workspace_id,
template_id,
agent_id,
payload
)
VALUES
($1, $2, $3, $4, $5, $6) RETURNING *;
($1, $2, $3, $4, $5, $6, $7) RETURNING *;

-- name: GetDAUsFromAgentStats :many
-- name: GetTemplateDAUs :many
select
(created_at at TIME ZONE 'UTC')::date as date,
count(distinct(user_id)) as daus
from
agent_stats
where template_id = $1
group by
date
order by
Expand Down
14 changes: 1 addition & 13 deletions coderd/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,9 @@ import (
"github.com/coder/coder/coderd/database"
"github.com/coder/coder/coderd/httpapi"
"github.com/coder/coder/coderd/httpmw"
"github.com/coder/coder/coderd/rbac"
"github.com/coder/coder/codersdk"
)

func (api *API) metricsDAUs(rw http.ResponseWriter, r *http.Request) {
if !api.Authorize(r, rbac.ActionRead, rbac.ResourceUser) {
httpapi.Forbidden(rw)
return
}
resp := api.metricsCache.DAUs()
if resp.Entries == nil {
resp.Entries = []codersdk.DAUEntry{}
}
httpapi.Write(rw, http.StatusOK, resp)
}

func (api *API) workspaceAgentReportStats(rw http.ResponseWriter, r *http.Request) {
api.websocketWaitMutex.Lock()
api.websocketWaitGroup.Add(1)
Expand Down Expand Up @@ -130,6 +117,7 @@ func (api *API) workspaceAgentReportStats(rw http.ResponseWriter, r *http.Reques
AgentID: workspaceAgent.ID,
WorkspaceID: build.WorkspaceID,
UserID: workspace.OwnerID,
TemplateID: workspace.TemplateID,
Payload: json.RawMessage(repJSON),
})
if err != nil {
Expand Down
117 changes: 0 additions & 117 deletions coderd/metrics_test.go

This file was deleted.

Loading