-
Notifications
You must be signed in to change notification settings - Fork 876
Audit build outcomes/kira pilot #5143
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
coderd/audit.go
Outdated
var agent string | ||
|
||
if dblog.UserAgent.Valid { | ||
agent = dblog.UserAgent.String | ||
} |
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 this should be necessary. You can access dblog.UserAgent.String
safely without checking if it's valid, it'll just be an empty string, so both outcomes are essentially the same.
@@ -967,6 +1035,19 @@ func convertWorkspaceTransition(transition database.WorkspaceTransition) (sdkpro | |||
} | |||
} | |||
|
|||
func determineAuditAction(transition database.WorkspaceTransition) database.AuditAction { |
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 auditActionFromTransition
would make this more clearer.
JobID: job.ID, | ||
Action: auditAction, | ||
New: workspaceBuild, | ||
Status: 200, |
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.
Status: 200, | |
Status: http.StatusOK, |
|
||
wriBytes, err := json.Marshal(workspaceResourceInfo) | ||
if err != nil { | ||
server.Logger.Error(ctx, "could not marshal workspace name", slog.Error(err)) |
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.
server.Logger.Error(ctx, "could not marshal workspace name", slog.Error(err)) | |
server.Logger.Error(ctx, "marshal resource info", slog.Error(err)) |
@@ -596,11 +635,12 @@ func (server *Server) CompleteJob(ctx context.Context, completed *proto.Complete | |||
return nil, xerrors.Errorf("get workspace build: %w", err) | |||
} | |||
|
|||
workspace, getWorkspaceError := server.Database.GetWorkspaceByID(ctx, workspaceBuild.WorkspaceID) |
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 this GetWorkspaceByID
needs to stay in the transaction, otherwise it's unsafe to update it. You could make it assign to a variable outside of the function to access the info!
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.
Frontend ✅
resolves #4724
Previously, all
workspace_build
audit logs showed 201 status codes - regardless of success or failure. This was because we were logging the initiation of the request - but not the outcome.We are now logging the outcome (and have stopped logging the initiation for now). If a build fails, the audit log will reflect that failure (status code
500
). If it is successful, the audit log will reflect that success (status code200
). The tradeoff is that there may be a delay in log generation as we have to wait for the build to finish. There are no diffs forworkspace_build
audit logs. I will add links to build logs in a fast follow to this PR so users can investigate failures.