-
Notifications
You must be signed in to change notification settings - Fork 894
Filter query: has-agent connecting, connected, disconnected, timeout #5145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 28 commits
ee6577d
7d61519
b5a1ecc
dca2b8b
0a4746c
70952e1
7965a54
c1bd839
2af4133
f9e2167
45957c1
66892d7
fc93f90
e587b5d
458a8eb
81d9fef
5ca8c17
ec2d571
4b2f831
3c0d4fe
9067a9e
c14663c
9c2f64a
44bf343
598b140
f3787d1
ba13e03
d74b072
4255448
4ace659
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -44,6 +44,7 @@ FROM | |||||||||||||||||||||||||||||||||
workspaces | ||||||||||||||||||||||||||||||||||
LEFT JOIN LATERAL ( | ||||||||||||||||||||||||||||||||||
SELECT | ||||||||||||||||||||||||||||||||||
workspace_builds.build_number, | ||||||||||||||||||||||||||||||||||
workspace_builds.transition, | ||||||||||||||||||||||||||||||||||
provisioner_jobs.started_at, | ||||||||||||||||||||||||||||||||||
provisioner_jobs.updated_at, | ||||||||||||||||||||||||||||||||||
|
@@ -146,7 +147,7 @@ WHERE | |||||||||||||||||||||||||||||||||
-- Use the organization filter to restrict to 1 org if needed. | ||||||||||||||||||||||||||||||||||
AND CASE | ||||||||||||||||||||||||||||||||||
WHEN @template_name :: text != '' THEN | ||||||||||||||||||||||||||||||||||
template_id = ANY(SELECT id FROM templates WHERE lower(name) = lower(@template_name) AND deleted = false) | ||||||||||||||||||||||||||||||||||
template_id = ANY(SELECT id FROM templates WHERE lower(name) = lower(@template_name) AND deleted = false) | ||||||||||||||||||||||||||||||||||
ELSE true | ||||||||||||||||||||||||||||||||||
END | ||||||||||||||||||||||||||||||||||
-- Filter by template_ids | ||||||||||||||||||||||||||||||||||
|
@@ -161,17 +162,63 @@ WHERE | |||||||||||||||||||||||||||||||||
name ILIKE '%' || @name || '%' | ||||||||||||||||||||||||||||||||||
ELSE true | ||||||||||||||||||||||||||||||||||
END | ||||||||||||||||||||||||||||||||||
-- 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 | ||||||||||||||||||||||||||||||||||
( | ||||||||||||||||||||||||||||||||||
SELECT COUNT(*) | ||||||||||||||||||||||||||||||||||
FROM | ||||||||||||||||||||||||||||||||||
workspace_builds | ||||||||||||||||||||||||||||||||||
JOIN | ||||||||||||||||||||||||||||||||||
provisioner_jobs | ||||||||||||||||||||||||||||||||||
ON | ||||||||||||||||||||||||||||||||||
provisioner_jobs.id = workspace_builds.job_id | ||||||||||||||||||||||||||||||||||
JOIN | ||||||||||||||||||||||||||||||||||
workspace_resources | ||||||||||||||||||||||||||||||||||
ON | ||||||||||||||||||||||||||||||||||
workspace_resources.job_id = provisioner_jobs.id | ||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I haven't tested if this works, but I would suggest this final change:
Suggested change
You'll need to add This should be more performant than re-joining these tables here. (It also eliminates the need for the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm afraid that it would work if |
||||||||||||||||||||||||||||||||||
JOIN | ||||||||||||||||||||||||||||||||||
workspace_agents | ||||||||||||||||||||||||||||||||||
ON | ||||||||||||||||||||||||||||||||||
workspace_agents.resource_id = workspace_resources.id | ||||||||||||||||||||||||||||||||||
WHERE | ||||||||||||||||||||||||||||||||||
workspace_builds.workspace_id = workspaces.id AND | ||||||||||||||||||||||||||||||||||
workspace_builds.build_number = latest_build.build_number AND | ||||||||||||||||||||||||||||||||||
workspace_builds.transition = 'start'::workspace_transition AND | ||||||||||||||||||||||||||||||||||
@has_agent = ( | ||||||||||||||||||||||||||||||||||
CASE | ||||||||||||||||||||||||||||||||||
WHEN workspace_agents.first_connected_at IS NULL THEN | ||||||||||||||||||||||||||||||||||
CASE | ||||||||||||||||||||||||||||||||||
WHEN workspace_agents.connection_timeout_seconds > 0 AND NOW() - workspace_agents.created_at > workspace_agents.connection_timeout_seconds * INTERVAL '1 second' THEN | ||||||||||||||||||||||||||||||||||
'timeout' | ||||||||||||||||||||||||||||||||||
ELSE | ||||||||||||||||||||||||||||||||||
'connecting' | ||||||||||||||||||||||||||||||||||
END | ||||||||||||||||||||||||||||||||||
WHEN workspace_agents.disconnected_at > workspace_agents.last_connected_at THEN | ||||||||||||||||||||||||||||||||||
'disconnected' | ||||||||||||||||||||||||||||||||||
WHEN NOW() - workspace_agents.last_connected_at > INTERVAL '1 second' * @agent_inactive_disconnect_timeout_seconds :: bigint THEN | ||||||||||||||||||||||||||||||||||
'disconnected' | ||||||||||||||||||||||||||||||||||
WHEN workspace_agents.last_connected_at IS NOT NULL THEN | ||||||||||||||||||||||||||||||||||
'connected' | ||||||||||||||||||||||||||||||||||
ELSE | ||||||||||||||||||||||||||||||||||
NULL | ||||||||||||||||||||||||||||||||||
END | ||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||
) > 0 | ||||||||||||||||||||||||||||||||||
ELSE true | ||||||||||||||||||||||||||||||||||
END | ||||||||||||||||||||||||||||||||||
-- Authorize Filter clause will be injected below in GetAuthorizedWorkspaces | ||||||||||||||||||||||||||||||||||
-- @authorize_filter | ||||||||||||||||||||||||||||||||||
ORDER BY | ||||||||||||||||||||||||||||||||||
last_used_at DESC | ||||||||||||||||||||||||||||||||||
last_used_at DESC | ||||||||||||||||||||||||||||||||||
LIMIT | ||||||||||||||||||||||||||||||||||
CASE | ||||||||||||||||||||||||||||||||||
WHEN @limit_ :: integer > 0 THEN | ||||||||||||||||||||||||||||||||||
@limit_ | ||||||||||||||||||||||||||||||||||
END | ||||||||||||||||||||||||||||||||||
CASE | ||||||||||||||||||||||||||||||||||
WHEN @limit_ :: integer > 0 THEN | ||||||||||||||||||||||||||||||||||
@limit_ | ||||||||||||||||||||||||||||||||||
END | ||||||||||||||||||||||||||||||||||
OFFSET | ||||||||||||||||||||||||||||||||||
@offset_ | ||||||||||||||||||||||||||||||||||
@offset_ | ||||||||||||||||||||||||||||||||||
; | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
-- name: GetWorkspaceByOwnerIDAndName :one | ||||||||||||||||||||||||||||||||||
|
Uh oh!
There was an error while loading. Please reload this page.