Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9529222

Browse files
committed
introduce dedicated queries for workspaces and workspace agents metrics
Signed-off-by: Callum Styan <[email protected]>
1 parent 6d39077 commit 9529222

File tree

8 files changed

+348
-10
lines changed

8 files changed

+348
-10
lines changed

coderd/database/dbauthz/dbauthz.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3433,6 +3433,13 @@ func (q *querier) GetWorkspaceAgentsByWorkspaceAndBuildNumber(ctx context.Contex
34333433
return q.db.GetWorkspaceAgentsByWorkspaceAndBuildNumber(ctx, arg)
34343434
}
34353435

3436+
func (q *querier) GetWorkspaceAgentsByWorkspaceIDAndBuildNumber(ctx context.Context, arg database.GetWorkspaceAgentsByWorkspaceIDAndBuildNumberParams) ([]database.WorkspaceAgent, error) {
3437+
if err := q.authorizeContext(ctx, policy.ActionRead, rbac.ResourceSystem); err != nil {
3438+
return nil, err
3439+
}
3440+
return q.db.GetWorkspaceAgentsByWorkspaceIDAndBuildNumber(ctx, arg)
3441+
}
3442+
34363443
func (q *querier) GetWorkspaceAgentsCreatedAfter(ctx context.Context, createdAt time.Time) ([]database.WorkspaceAgent, error) {
34373444
if err := q.authorizeContext(ctx, policy.ActionRead, rbac.ResourceSystem); err != nil {
34383445
return nil, err
@@ -3745,6 +3752,20 @@ func (q *querier) GetWorkspacesEligibleForTransition(ctx context.Context, now ti
37453752
return q.db.GetWorkspacesEligibleForTransition(ctx, now)
37463753
}
37473754

3755+
func (q *querier) GetWorkspacesForAgentMetrics(ctx context.Context, deleted bool) ([]database.GetWorkspacesForAgentMetricsRow, error) {
3756+
if err := q.authorizeContext(ctx, policy.ActionRead, rbac.ResourceSystem); err != nil {
3757+
return nil, err
3758+
}
3759+
return q.db.GetWorkspacesForAgentMetrics(ctx, deleted)
3760+
}
3761+
3762+
func (q *querier) GetWorkspacesForWorkspaceMetrics(ctx context.Context, deleted bool) ([]database.GetWorkspacesForWorkspaceMetricsRow, error) {
3763+
if err := q.authorizeContext(ctx, policy.ActionRead, rbac.ResourceSystem); err != nil {
3764+
return nil, err
3765+
}
3766+
return q.db.GetWorkspacesForWorkspaceMetrics(ctx, deleted)
3767+
}
3768+
37483769
func (q *querier) InsertAPIKey(ctx context.Context, arg database.InsertAPIKeyParams) (database.APIKey, error) {
37493770
// TODO(Cian): ideally this would be encoded in the policy, but system users are just members and we
37503771
// don't currently have a capability to conditionally deny creating resources by owner ID in a role.

coderd/database/dbmetrics/querymetrics.go

Lines changed: 21 additions & 0 deletions
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: 45 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/querier.go

Lines changed: 3 additions & 0 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: 196 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries/workspaceagents.sql

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,3 +365,17 @@ WHERE
365365
id = $1
366366
AND parent_id IS NOT NULL
367367
AND deleted = FALSE;
368+
369+
-- name: GetWorkspaceAgentsByWorkspaceIDAndBuildNumber :many
370+
SELECT
371+
workspace_agents.*
372+
FROM
373+
workspace_agents
374+
JOIN
375+
workspace_resources ON workspace_agents.resource_id = workspace_resources.id
376+
JOIN
377+
workspace_builds ON workspace_resources.job_id = workspace_builds.job_id
378+
WHERE
379+
workspace_builds.workspace_id = @workspace_id :: uuid
380+
AND workspace_builds.build_number = @build_number :: integer
381+
AND workspace_agents.deleted = FALSE;

0 commit comments

Comments
 (0)