-
Notifications
You must be signed in to change notification settings - Fork 905
feat: add audit log filter for autostarted and autostopped workspace builds #5830
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
Conversation
(audit_logs.resource_type = 'workspace' AND | ||
audit_logs.action = 'create' AND | ||
workspaces.id = workspace_builds.workspace_id AND | ||
workspace_builds.build_number = 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The above is a bit obnoxious, but it exists to handle the case when a workspace is first created. In these situations, the resource_type
is workspace
, not workspace_build
.
Otherwise, we could simplify:
LEFT JOIN workspace_builds on audit_logs.resource_type = ‘workspace_build’ AND audit_logs.resource_id = workspace_builds.id
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need to fix the formatting on this sql.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Emyrk I think I fixed it with pgFormatter
but please let me know if it still looks wonky.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it did, but we don't abide by some standard sql formatting because the sqlc
directives are not valid sql, and the formatters do not know what to do 🤷.
-- GetAuditLogsBefore retrieves `row_limit` number of audit logs before the provided
-- ID.
-- name: GetAuditLogsOffset :many
SELECT
audit_logs.*,
users.username AS user_username,
users.email AS user_email,
users.created_at AS user_created_at,
users.status AS user_status,
users.rbac_roles AS user_roles,
users.avatar_url AS user_avatar_url,
COUNT(audit_logs.*) OVER() AS count
FROM
audit_logs
LEFT JOIN
users ON audit_logs.user_id = users.id
LEFT JOIN
-- First join on workspaces to get the initial workspace create
-- to workspace build 1 id. This is because the first create is
-- is a different audit log than subsequent starts.
workspaces on
audit_logs.resource_type = 'workspace'
AND audit_logs.resource_id = workspaces.id
LEFT JOIN
workspace_builds on
-- Get the reason from the build if the resource type
-- is a workspace_build
(
audit_logs.resource_type = 'workspace_build' AND
audit_logs.resource_id = workspace_builds.id
)
OR
-- Get the reason from the build #1 if this is the first
-- workspace create.
(
audit_logs.resource_type = 'workspace' AND
audit_logs.action = 'create' AND
workspaces.id = workspace_builds.workspace_id AND
workspace_builds.build_number = 1
)
-- WHERE clause stuff below. I think the indentation is messed up there too a bit.
Be sure to avoid using tabs. I notice we inconsistently use tabs and spaces, so I converted all tabs to 4 spaces.
(audit_logs.resource_type = 'workspace' AND | ||
audit_logs.action = 'create' AND | ||
workspaces.id = workspace_builds.workspace_id AND | ||
workspace_builds.build_number = 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need to fix the formatting on this sql.
👍
follow-up to #5813. resolves #4729
We now can filter
workspace_build
resources bybuild_reason
. Users will be able to filter out builds that were autostarted/autostopped.