Skip to content

Commit 7ebb11d

Browse files
committed
PR feedback
1 parent b62e554 commit 7ebb11d

File tree

3 files changed

+15
-12
lines changed

3 files changed

+15
-12
lines changed

coderd/audit.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,12 @@ func (api *API) convertAuditLog(ctx context.Context, dblog database.GetAuditLogs
197197
)
198198
if err != nil {
199199
api.Logger.Error(ctx, "unmarshal additional fields", slog.Error(err))
200+
resourceInfo := map[string]string{
201+
"workspaceName": "unknown",
202+
"buildNumber": "unknown",
203+
}
204+
dblog.AdditionalFields, err = json.Marshal(resourceInfo)
205+
api.Logger.Error(ctx, "marshal additional fields", slog.Error(err))
200206
}
201207

202208
var (

coderd/provisionerdserver/provisionerdserver.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -531,23 +531,23 @@ func (server *Server) FailJob(ctx context.Context, failJob *proto.FailedJob) (*p
531531
auditor := server.Auditor.Load()
532532
build, getBuildErr := server.Database.GetWorkspaceBuildByJobID(ctx, job.ID)
533533
if getBuildErr != nil {
534-
server.Logger.Error(ctx, "failed to create audit log - get build err", slog.Error(err))
534+
server.Logger.Error(ctx, "audit log - get build", slog.Error(err))
535535
} else {
536536
auditAction := auditActionFromTransition(build.Transition)
537537
workspace, getWorkspaceErr := server.Database.GetWorkspaceByID(ctx, build.WorkspaceID)
538538
if getWorkspaceErr != nil {
539-
server.Logger.Error(ctx, "failed to create audit log - get workspace err", slog.Error(err))
539+
server.Logger.Error(ctx, "audit log - get workspace", slog.Error(err))
540540
} else {
541541
// We pass the below information to the Auditor so that it
542542
// can form a friendly string for the user to view in the UI.
543-
workspaceResourceInfo := map[string]string{
543+
buildResourceInfo := map[string]string{
544544
"workspaceName": workspace.Name,
545545
"buildNumber": strconv.FormatInt(int64(build.BuildNumber), 10),
546546
}
547547

548-
wriBytes, err := json.Marshal(workspaceResourceInfo)
548+
wriBytes, err := json.Marshal(buildResourceInfo)
549549
if err != nil {
550-
server.Logger.Error(ctx, "could not marshal workspace name", slog.Error(err))
550+
server.Logger.Error(ctx, "marshal workspace resource info for failed job", slog.Error(err))
551551
}
552552

553553
audit.BuildAudit(ctx, &audit.BuildAuditParams[database.WorkspaceBuild]{
@@ -756,14 +756,14 @@ func (server *Server) CompleteJob(ctx context.Context, completed *proto.Complete
756756

757757
// We pass the below information to the Auditor so that it
758758
// can form a friendly string for the user to view in the UI.
759-
workspaceResourceInfo := map[string]string{
759+
buildResourceInfo := map[string]string{
760760
"workspaceName": workspace.Name,
761761
"buildNumber": strconv.FormatInt(int64(workspaceBuild.BuildNumber), 10),
762762
}
763763

764-
wriBytes, err := json.Marshal(workspaceResourceInfo)
764+
wriBytes, err := json.Marshal(buildResourceInfo)
765765
if err != nil {
766-
server.Logger.Error(ctx, "marshal resource info", slog.Error(err))
766+
server.Logger.Error(ctx, "marshal resource info for successful job", slog.Error(err))
767767
}
768768

769769
audit.BuildAudit(ctx, &audit.BuildAuditParams[database.WorkspaceBuild]{

site/src/components/AuditLogRow/AuditLogDescription.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@ export const AuditLogDescription: FC<{ auditLog: AuditLog }> = ({
1414
let target = auditLog.resource_target.trim()
1515

1616
// audit logs with a resource_type of workspace build use workspace name as a target
17-
if (
18-
auditLog.resource_type === "workspace_build" &&
19-
auditLog.additional_fields.workspaceName
20-
) {
17+
if (auditLog.resource_type === "workspace_build") {
2118
target = auditLog.additional_fields.workspaceName.trim()
2219
}
2320

0 commit comments

Comments
 (0)