-
Notifications
You must be signed in to change notification settings - Fork 943
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 1 commit
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
- Loading branch information
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,8 +44,8 @@ FROM | |
workspaces | ||
LEFT JOIN LATERAL ( | ||
SELECT | ||
build_number, | ||
workspace_builds.job_id, | ||
build_number, | ||
workspace_builds.job_id, | ||
workspace_builds.transition, | ||
provisioner_jobs.started_at, | ||
provisioner_jobs.updated_at, | ||
|
@@ -64,13 +64,13 @@ LEFT JOIN LATERAL ( | |
ON | ||
provisioner_jobs.id = workspace_builds.job_id | ||
LEFT JOIN | ||
workspace_resources | ||
workspace_resources | ||
ON | ||
workspace_resources.job_id = provisioner_jobs.id | ||
workspace_resources.job_id = provisioner_jobs.id | ||
LEFT JOIN | ||
workspace_agents | ||
workspace_agents | ||
ON | ||
workspace_agents.resource_id = workspace_resources.id | ||
workspace_agents.resource_id = workspace_resources.id | ||
WHERE | ||
workspace_builds.workspace_id = workspaces.id | ||
ORDER BY | ||
|
@@ -163,7 +163,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 | ||
|
@@ -187,7 +187,7 @@ WHERE | |
WHEN @has_agent = 'timeout' THEN | ||
latest_build.first_connected_at IS NULL AND (latest_build.created_at + latest_build.connection_timeout_seconds * INTERVAL '1 second' < NOW()) | ||
WHEN @has_agent = 'connecting' THEN | ||
latest_build.first_connected_at IS NULL | ||
latest_build.first_connected_at IS NULL | ||
WHEN @has_agent = 'disconnected' THEN | ||
( | ||
latest_build.disconnected_at IS NOT NULL AND | ||
|
@@ -197,22 +197,22 @@ WHERE | |
latest_build.last_connected_at + 6 * INTERVAL '1 second' < NOW() -- FIXME agentInactiveDisconnectTimeout = 6 | ||
mtojek marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) | ||
WHEN @has_agent = 'connected' THEN | ||
latest_build.last_connected_at IS NOT NULL | ||
latest_build.last_connected_at IS NOT NULL | ||
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. Should this case also verify that the state isn't actually 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 extended the condition. Frankly speaking,, I'm thinking about refactoring that part of the code and creating an extra "runtime" column for 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 guess that you can take a look at the CASE logic implementation one more time as I've rewritten it to look similar to the Go code. 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. @mtojek I think the case logic is exactly what you want. But you would have to add that case logic to all reads. So either remove all 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. 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. The only reason I mentioned a So you have A "view" is a way to repackage the extra dynamic column in a way sqlc still sees it as a single type. So all the above queries go from So tl;dr the view is just a way to keep the sqlc clean. You'll see when you run a 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.
Fortunately, at moment we only need it to search workspaces using filtering. I guess that we don't need to hurry up and inject the case logic everywhere.
In terms of clean code and the benefits of sqlc, I totally agree with you. I admit that I wouldn't like to get stuck in this pull request with too many changes and I'm wondering if I can split it into multiple PRs. Follow-up ideas:
Frankly speaking, if there aren't big performance or clean code concerns around this PR, I would leave it as is, and focus on improvements once the requested feature is delivered. Let me know what you think. 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. 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. That's a good point @mtojek, it definitely hampers the use case. Ideally this value would come from either the terraform provider or be stored in the database by some other means, at which point it can be part of the query. I don't find it unthinkable that we would serialize certain coder server runtime properties in the database, either as a temp table or one that is (re)written on startup. The inactivity seconds could then be stored there and joined. |
||
ELSE true | ||
END | ||
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.