Skip to content

Add audit links/kira pilot #5156

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

Merged
merged 13 commits into from
Dec 2, 2022
Merged

Add audit links/kira pilot #5156

merged 13 commits into from
Dec 2, 2022

Conversation

Kira-Pilot
Copy link
Member

@Kira-Pilot Kira-Pilot commented Nov 23, 2022

We've added support for links in certain audit log entries, like those for resources workspace and workspace_build:

Kapture 2022-11-30 at 11 25 57

as well as template and user:
Screen Shot 2022-11-30 at 11 29 49 AM

These links do not appear if the resource is deleted, as we do not have great UI support for deleted resources at this moment in time. Instead, we show a deleted label next to the audit log description.

@Kira-Pilot Kira-Pilot requested a review from a team as a code owner November 23, 2022 18:26
@Kira-Pilot Kira-Pilot requested review from code-asher and removed request for a team November 23, 2022 18:26
@Kira-Pilot Kira-Pilot marked this pull request as draft November 23, 2022 20:51
@Kira-Pilot Kira-Pilot requested a review from coadler November 30, 2022 16:35
BuildNumber string
}

func (api *API) auditLogIsResourceDeleted(ctx context.Context, alog database.GetAuditLogsOffsetRow) bool {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@coadler I'm concerned the queries in this switch will take a while to resolve. Is there a better way to determine if a resource has been deleted?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think there's a great way to do so without something hacky like reflection here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the only way to really fix this would be to return if the resource is deleted in the GetAuditLogsOffset query.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per our Slack convo, will try to add that as a fast follow!

@Kira-Pilot Kira-Pilot marked this pull request as ready for review November 30, 2022 16:39
{auditLog.resource_link ? (
<Link component={RouterLink} to={auditLog.resource_link}>
<strong>{target}</strong>
</Link>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having a link on workspace name for workspace_build strings is a little awkward - it might be better if this link was built around the word build instead of on the workspace target. However, that add a surprising amount of complexity, so I figured this was okay for now. If you object, let me know!

@Kira-Pilot Kira-Pilot requested review from BrunoQuaresma and removed request for code-asher November 30, 2022 20:59
Copy link
Collaborator

@BrunoQuaresma BrunoQuaresma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we show a deleted label next to the audit log description.

I would add a storybook that shows this state but it is up to you. FE lgtm, great work!

coderd/audit.go Outdated
User: user,
Description: auditLogDescription(dblog),
ResourceLink: api.auditLogResourceLink(ctx, dblog),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because this calls api.auditLogIsResourceDeleted as well, you are making the same database calls twice here. One way to speed this up and save the work would be to call api.auditLogIsResourceDeleted before this struct and pass it into both IsDeleted and also as an arg into api.auditLogResourceLink.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Woops, you're totally right! Pushing a fix now.

BuildNumber string
}

func (api *API) auditLogIsResourceDeleted(ctx context.Context, alog database.GetAuditLogsOffsetRow) bool {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the only way to really fix this would be to return if the resource is deleted in the GetAuditLogsOffset query.

coderd/audit.go Outdated
Comment on lines 241 to 244
template, err := api.Database.GetTemplateByID(ctx, alog.ResourceID)
if err != nil {
api.Logger.Error(ctx, "could not fetch template", slog.Error(err))
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should also check if xerrors.Is(err, sql.ErrNoRows) { return true }, in case the assumption that rows are never deleted changes.

coderd/audit.go Outdated
case database.ResourceTypeUser:
user, err := api.Database.GetUserByID(ctx, alog.ResourceID)
if err != nil {
api.Logger.Error(ctx, "could not fetch user", slog.Error(err))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

small nit; normally we don't prefix log lines with could not/failed to because the error level implies it

@Kira-Pilot Kira-Pilot merged commit 6540746 into main Dec 2, 2022
@Kira-Pilot Kira-Pilot deleted the add-audit-links/kira-pilot branch December 2, 2022 20:14
@github-actions github-actions bot locked and limited conversation to collaborators Dec 2, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants