Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit24f3445

Browse files
authored
chore: track workspace resource monitors in telemetry (#16776)
Addressescoder/nexus#195. Specifically, justthe "tracking templates" requirement:> ## Tracking in templates> To enable resource alerts, a user must add the resource_monitoringblock to a template's coder_agent resource. We'd like to track ifcustomers have any resource monitoring enabled on a per-deploymentbasis. Even better, we could identify which templates are using resourcemonitoring.
1 parentdfcd93b commit24f3445

File tree

10 files changed

+285
-22
lines changed

10 files changed

+285
-22
lines changed

‎coderd/database/dbauthz/dbauthz.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1438,6 +1438,17 @@ func (q *querier) FetchMemoryResourceMonitorsByAgentID(ctx context.Context, agen
14381438
returnq.db.FetchMemoryResourceMonitorsByAgentID(ctx,agentID)
14391439
}
14401440

1441+
func (q*querier)FetchMemoryResourceMonitorsUpdatedAfter(ctx context.Context,updatedAt time.Time) ([]database.WorkspaceAgentMemoryResourceMonitor,error) {
1442+
// Ideally, we would return a list of monitors that the user has access to. However, that check would need to
1443+
// be implemented similarly to GetWorkspaces, which is more complex than what we're doing here. Since this query
1444+
// was introduced for telemetry, we perform a simpler check.
1445+
iferr:=q.authorizeContext(ctx,policy.ActionRead,rbac.ResourceWorkspaceAgentResourceMonitor);err!=nil {
1446+
returnnil,err
1447+
}
1448+
1449+
returnq.db.FetchMemoryResourceMonitorsUpdatedAfter(ctx,updatedAt)
1450+
}
1451+
14411452
func (q*querier)FetchNewMessageMetadata(ctx context.Context,arg database.FetchNewMessageMetadataParams) (database.FetchNewMessageMetadataRow,error) {
14421453
iferr:=q.authorizeContext(ctx,policy.ActionRead,rbac.ResourceNotificationMessage);err!=nil {
14431454
return database.FetchNewMessageMetadataRow{},err
@@ -1459,6 +1470,17 @@ func (q *querier) FetchVolumesResourceMonitorsByAgentID(ctx context.Context, age
14591470
returnq.db.FetchVolumesResourceMonitorsByAgentID(ctx,agentID)
14601471
}
14611472

1473+
func (q*querier)FetchVolumesResourceMonitorsUpdatedAfter(ctx context.Context,updatedAt time.Time) ([]database.WorkspaceAgentVolumeResourceMonitor,error) {
1474+
// Ideally, we would return a list of monitors that the user has access to. However, that check would need to
1475+
// be implemented similarly to GetWorkspaces, which is more complex than what we're doing here. Since this query
1476+
// was introduced for telemetry, we perform a simpler check.
1477+
iferr:=q.authorizeContext(ctx,policy.ActionRead,rbac.ResourceWorkspaceAgentResourceMonitor);err!=nil {
1478+
returnnil,err
1479+
}
1480+
1481+
returnq.db.FetchVolumesResourceMonitorsUpdatedAfter(ctx,updatedAt)
1482+
}
1483+
14621484
func (q*querier)GetAPIKeyByID(ctx context.Context,idstring) (database.APIKey,error) {
14631485
returnfetch(q.log,q.auth,q.db.GetAPIKeyByID)(ctx,id)
14641486
}

‎coderd/database/dbauthz/dbauthz_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4919,6 +4919,14 @@ func (s *MethodTestSuite) TestResourcesMonitor() {
49194919
}).Asserts(rbac.ResourceWorkspaceAgentResourceMonitor,policy.ActionUpdate)
49204920
}))
49214921

4922+
s.Run("FetchMemoryResourceMonitorsUpdatedAfter",s.Subtest(func(db database.Store,check*expects) {
4923+
check.Args(dbtime.Now()).Asserts(rbac.ResourceWorkspaceAgentResourceMonitor,policy.ActionRead)
4924+
}))
4925+
4926+
s.Run("FetchVolumesResourceMonitorsUpdatedAfter",s.Subtest(func(db database.Store,check*expects) {
4927+
check.Args(dbtime.Now()).Asserts(rbac.ResourceWorkspaceAgentResourceMonitor,policy.ActionRead)
4928+
}))
4929+
49224930
s.Run("FetchMemoryResourceMonitorsByAgentID",s.Subtest(func(db database.Store,check*expects) {
49234931
agt,w:=createAgent(s.T(),db)
49244932

‎coderd/database/dbmem/dbmem.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2503,6 +2503,19 @@ func (q *FakeQuerier) FetchMemoryResourceMonitorsByAgentID(_ context.Context, ag
25032503
return database.WorkspaceAgentMemoryResourceMonitor{},sql.ErrNoRows
25042504
}
25052505

2506+
func (q*FakeQuerier)FetchMemoryResourceMonitorsUpdatedAfter(_ context.Context,updatedAt time.Time) ([]database.WorkspaceAgentMemoryResourceMonitor,error) {
2507+
q.mutex.RLock()
2508+
deferq.mutex.RUnlock()
2509+
2510+
monitors:= []database.WorkspaceAgentMemoryResourceMonitor{}
2511+
for_,monitor:=rangeq.workspaceAgentMemoryResourceMonitors {
2512+
ifmonitor.UpdatedAt.After(updatedAt) {
2513+
monitors=append(monitors,monitor)
2514+
}
2515+
}
2516+
returnmonitors,nil
2517+
}
2518+
25062519
func (q*FakeQuerier)FetchNewMessageMetadata(_ context.Context,arg database.FetchNewMessageMetadataParams) (database.FetchNewMessageMetadataRow,error) {
25072520
err:=validateDatabaseType(arg)
25082521
iferr!=nil {
@@ -2547,6 +2560,19 @@ func (q *FakeQuerier) FetchVolumesResourceMonitorsByAgentID(_ context.Context, a
25472560
returnmonitors,nil
25482561
}
25492562

2563+
func (q*FakeQuerier)FetchVolumesResourceMonitorsUpdatedAfter(_ context.Context,updatedAt time.Time) ([]database.WorkspaceAgentVolumeResourceMonitor,error) {
2564+
q.mutex.RLock()
2565+
deferq.mutex.RUnlock()
2566+
2567+
monitors:= []database.WorkspaceAgentVolumeResourceMonitor{}
2568+
for_,monitor:=rangeq.workspaceAgentVolumeResourceMonitors {
2569+
ifmonitor.UpdatedAt.After(updatedAt) {
2570+
monitors=append(monitors,monitor)
2571+
}
2572+
}
2573+
returnmonitors,nil
2574+
}
2575+
25502576
func (q*FakeQuerier)GetAPIKeyByID(_ context.Context,idstring) (database.APIKey,error) {
25512577
q.mutex.RLock()
25522578
deferq.mutex.RUnlock()

‎coderd/database/dbmetrics/querymetrics.go

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/database/dbmock/dbmock.go

Lines changed: 30 additions & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/database/querier.go

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

‎coderd/database/queries.sql.go

Lines changed: 81 additions & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/database/queries/workspaceagentresourcemonitors.sql

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
-- name: FetchVolumesResourceMonitorsUpdatedAfter :many
2+
SELECT
3+
*
4+
FROM
5+
workspace_agent_volume_resource_monitors
6+
WHERE
7+
updated_at> $1;
8+
9+
-- name: FetchMemoryResourceMonitorsUpdatedAfter :many
10+
SELECT
11+
*
12+
FROM
13+
workspace_agent_memory_resource_monitors
14+
WHERE
15+
updated_at> $1;
16+
117
-- name: FetchMemoryResourceMonitorsByAgentID :one
218
SELECT
319
*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp