mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat: add healthy filter for workspace queries (#21743)
Adds support for filtering workspaces by health status using healthy:true or healthy:false in the search query. This is done by changing `has-agent` to accept a list of statuses and aliasing `health:true` to `has-agent:connected` and `healthy:false` to `has-agent:timeout,disconnected`. Fixes #21623
This commit is contained in:
@@ -268,7 +268,7 @@ func (q *sqlQuerier) GetAuthorizedWorkspaces(ctx context.Context, arg GetWorkspa
|
||||
pq.Array(arg.TemplateIDs),
|
||||
pq.Array(arg.WorkspaceIds),
|
||||
arg.Name,
|
||||
arg.HasAgent,
|
||||
pq.Array(arg.HasAgentStatuses),
|
||||
arg.AgentInactiveDisconnectTimeoutSeconds,
|
||||
arg.Dormant,
|
||||
arg.LastUsedBefore,
|
||||
|
||||
@@ -22977,7 +22977,7 @@ WHERE
|
||||
-- Filter by agent status
|
||||
-- has-agent: is only applicable for workspaces in "start" transition. Stopped and deleted workspaces don't have agents.
|
||||
AND CASE
|
||||
WHEN $13 :: text != '' THEN
|
||||
WHEN array_length($13 :: text[], 1) > 0 THEN
|
||||
(
|
||||
SELECT COUNT(*)
|
||||
FROM
|
||||
@@ -22991,7 +22991,7 @@ WHERE
|
||||
latest_build.transition = 'start'::workspace_transition AND
|
||||
-- Filter out deleted sub agents.
|
||||
workspace_agents.deleted = FALSE AND
|
||||
$13 = (
|
||||
(
|
||||
CASE
|
||||
WHEN workspace_agents.first_connected_at IS NULL THEN
|
||||
CASE
|
||||
@@ -23009,7 +23009,7 @@ WHERE
|
||||
ELSE
|
||||
NULL
|
||||
END
|
||||
)
|
||||
) = ANY($13 :: text[])
|
||||
) > 0
|
||||
ELSE true
|
||||
END
|
||||
@@ -23074,6 +23074,7 @@ WHERE
|
||||
workspaces.group_acl ? ($23 :: uuid) :: text
|
||||
ELSE true
|
||||
END
|
||||
|
||||
-- Authorize Filter clause will be injected below in GetAuthorizedWorkspaces
|
||||
-- @authorize_filter
|
||||
), filtered_workspaces_order AS (
|
||||
@@ -23177,7 +23178,7 @@ type GetWorkspacesParams struct {
|
||||
TemplateIDs []uuid.UUID `db:"template_ids" json:"template_ids"`
|
||||
WorkspaceIds []uuid.UUID `db:"workspace_ids" json:"workspace_ids"`
|
||||
Name string `db:"name" json:"name"`
|
||||
HasAgent string `db:"has_agent" json:"has_agent"`
|
||||
HasAgentStatuses []string `db:"has_agent_statuses" json:"has_agent_statuses"`
|
||||
AgentInactiveDisconnectTimeoutSeconds int64 `db:"agent_inactive_disconnect_timeout_seconds" json:"agent_inactive_disconnect_timeout_seconds"`
|
||||
Dormant bool `db:"dormant" json:"dormant"`
|
||||
LastUsedBefore time.Time `db:"last_used_before" json:"last_used_before"`
|
||||
@@ -23255,7 +23256,7 @@ func (q *sqlQuerier) GetWorkspaces(ctx context.Context, arg GetWorkspacesParams)
|
||||
pq.Array(arg.TemplateIDs),
|
||||
pq.Array(arg.WorkspaceIds),
|
||||
arg.Name,
|
||||
arg.HasAgent,
|
||||
pq.Array(arg.HasAgentStatuses),
|
||||
arg.AgentInactiveDisconnectTimeoutSeconds,
|
||||
arg.Dormant,
|
||||
arg.LastUsedBefore,
|
||||
|
||||
@@ -292,7 +292,7 @@ WHERE
|
||||
-- Filter by agent status
|
||||
-- has-agent: is only applicable for workspaces in "start" transition. Stopped and deleted workspaces don't have agents.
|
||||
AND CASE
|
||||
WHEN @has_agent :: text != '' THEN
|
||||
WHEN array_length(@has_agent_statuses :: text[], 1) > 0 THEN
|
||||
(
|
||||
SELECT COUNT(*)
|
||||
FROM
|
||||
@@ -306,7 +306,7 @@ WHERE
|
||||
latest_build.transition = 'start'::workspace_transition AND
|
||||
-- Filter out deleted sub agents.
|
||||
workspace_agents.deleted = FALSE AND
|
||||
@has_agent = (
|
||||
(
|
||||
CASE
|
||||
WHEN workspace_agents.first_connected_at IS NULL THEN
|
||||
CASE
|
||||
@@ -324,7 +324,7 @@ WHERE
|
||||
ELSE
|
||||
NULL
|
||||
END
|
||||
)
|
||||
) = ANY(@has_agent_statuses :: text[])
|
||||
) > 0
|
||||
ELSE true
|
||||
END
|
||||
@@ -389,6 +389,7 @@ WHERE
|
||||
workspaces.group_acl ? (@shared_with_group_id :: uuid) :: text
|
||||
ELSE true
|
||||
END
|
||||
|
||||
-- Authorize Filter clause will be injected below in GetAuthorizedWorkspaces
|
||||
-- @authorize_filter
|
||||
), filtered_workspaces_order AS (
|
||||
|
||||
Reference in New Issue
Block a user