Skip to content

Commit aafd29e

Browse files
committed
add template_name label to workspace agent stats
1 parent 753f1a6 commit aafd29e

File tree

12 files changed

+74
-36
lines changed

12 files changed

+74
-36
lines changed

coderd/coderd.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import (
4040
"github.com/coder/coder/v2/coderd/healthcheck/derphealth"
4141

4242
"cdr.dev/slog"
43+
4344
"github.com/coder/coder/v2/buildinfo"
4445
"github.com/coder/coder/v2/cli/clibase"
4546
"github.com/coder/coder/v2/coderd/audit"
@@ -168,7 +169,7 @@ type Options struct {
168169

169170
HTTPClient *http.Client
170171

171-
UpdateAgentMetrics func(ctx context.Context, username, workspaceName, agentName string, metrics []agentsdk.AgentMetric)
172+
UpdateAgentMetrics func(ctx context.Context, username, workspaceName, agentName, templateName string, metrics []agentsdk.AgentMetric)
172173
StatsBatcher *batchstats.Batcher
173174

174175
WorkspaceAppsStatsCollectorOptions workspaceapps.StatsCollectorOptions

coderd/database/dbauthz/dbauthz.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"github.com/open-policy-agent/opa/topdown"
1717

1818
"cdr.dev/slog"
19+
1920
"github.com/coder/coder/v2/coderd/database"
2021
"github.com/coder/coder/v2/coderd/database/dbtime"
2122
"github.com/coder/coder/v2/coderd/httpapi/httpapiconstraints"
@@ -1923,7 +1924,7 @@ func (q *querier) GetWorkspaceBuildsCreatedAfter(ctx context.Context, createdAt
19231924
return q.db.GetWorkspaceBuildsCreatedAfter(ctx, createdAt)
19241925
}
19251926

1926-
func (q *querier) GetWorkspaceByAgentID(ctx context.Context, agentID uuid.UUID) (database.Workspace, error) {
1927+
func (q *querier) GetWorkspaceByAgentID(ctx context.Context, agentID uuid.UUID) (database.GetWorkspaceByAgentIDRow, error) {
19271928
return fetch(q.log, q.auth, q.db.GetWorkspaceByAgentID)(ctx, agentID)
19281929
}
19291930

coderd/database/dbmem/dbmem.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4296,11 +4296,24 @@ func (q *FakeQuerier) GetWorkspaceBuildsCreatedAfter(_ context.Context, after ti
42964296
return workspaceBuilds, nil
42974297
}
42984298

4299-
func (q *FakeQuerier) GetWorkspaceByAgentID(ctx context.Context, agentID uuid.UUID) (database.Workspace, error) {
4299+
func (q *FakeQuerier) GetWorkspaceByAgentID(ctx context.Context, agentID uuid.UUID) (database.GetWorkspaceByAgentIDRow, error) {
43004300
q.mutex.RLock()
43014301
defer q.mutex.RUnlock()
43024302

4303-
return q.getWorkspaceByAgentIDNoLock(ctx, agentID)
4303+
w, err := q.getWorkspaceByAgentIDNoLock(ctx, agentID)
4304+
if err != nil {
4305+
return database.GetWorkspaceByAgentIDRow{}, err
4306+
}
4307+
4308+
tpl, err := q.getTemplateByIDNoLock(ctx, w.TemplateID)
4309+
if err != nil {
4310+
return database.GetWorkspaceByAgentIDRow{}, err
4311+
}
4312+
4313+
return database.GetWorkspaceByAgentIDRow{
4314+
Workspace: w,
4315+
TemplateName: tpl.Name,
4316+
}, nil
43044317
}
43054318

43064319
func (q *FakeQuerier) GetWorkspaceByID(ctx context.Context, id uuid.UUID) (database.Workspace, error) {

coderd/database/dbmetrics/dbmetrics.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/dbmock/dbmock.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/modelmethods.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,10 @@ func (g Group) RBACObject() rbac.Object {
148148
InOrg(g.OrganizationID)
149149
}
150150

151+
func (w GetWorkspaceByAgentIDRow) RBACObject() rbac.Object {
152+
return w.Workspace.RBACObject()
153+
}
154+
151155
func (w Workspace) RBACObject() rbac.Object {
152156
return rbac.ResourceWorkspace.WithID(w.ID).
153157
InOrg(w.OrganizationID).

coderd/database/models.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/querier.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries.sql.go

Lines changed: 27 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries/workspaces.sql

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,12 @@ WHERE
4646

4747
-- name: GetWorkspaceByAgentID :one
4848
SELECT
49-
*
49+
sqlc.embed(workspaces),
50+
templates.name as template_name
5051
FROM
5152
workspaces
53+
INNER JOIN
54+
templates ON workspaces.template_id = templates.id
5255
WHERE
5356
workspaces.id = (
5457
SELECT

0 commit comments

Comments
 (0)