Skip to content
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

CSS-5179 Audit log enhacement #1026

Merged
merged 4 commits into from
Aug 15, 2023

Conversation

kian99
Copy link
Contributor

@kian99 kian99 commented Aug 14, 2023

Description

Based on a discussion with the web team, they found that audit logs were not filtering based on method, this was a bug due to the translation from API params to a db.AuditLogFilter struct (this has been moved to a separate function with its own tests). They also requested the ability to sort logs with the most recent first, this has been added as an optional flag.

Engineering checklist

Check only items that apply

  • Documentation updated
  • Covered by unit tests
  • Covered by integration tests

- Fixed inability to filter by method
- Added ability to sort by time
@@ -73,6 +73,8 @@ func (c *listAuditEventsCommand) SetFlags(f *gnuflag.FlagSet) {
f.StringVar(&c.args.Model, "model", "", "display events for a specific model (model name is controller/model)")
f.IntVar(&c.args.Limit, "offset", 0, "offset the set of returned audit events")
f.IntVar(&c.args.Limit, "limit", 0, "limit the maximum number of returned audit events")
f.BoolVar(&c.args.SortTime, "reverse", false, "reverse the order of logs, showing the most recent first")
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a bit confusing. Having the SortTime as bool indicates that if set to false, then the records are not be sorted by time (either desc or asc), but it seems that SortTime would reverse the already sorted logs.

Maybe We can change the name to SortDescending instead of SortTime.

any instead of reverse, we can just call it descending.

Just a thought, though

Copy link
Contributor

Choose a reason for hiding this comment

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

Or
We can use an enum to allow for

Descending 
No order (default)
Ascending

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think if the reverse flag is false (default) the expectation from a user would be that the order is not reversed i.e oldest logs first, this is the behavior you'll see with a lot of tools like journalctl and kubectl. And that is what JIMM will do as well because our logs (without sorting) are returned in order of ID which is effectively sorted in ascending order of time.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But I agree the name could be better

@@ -55,6 +55,10 @@ type AuditLogFilter struct {
// Limit is the maximum number of audit events to return.
// A value of zero will ignore the limit.
Limit int `json:"limit,omitempty"`

// SortTime will sort by most recent first (time descending) when true.
// When false no explicit ordering will be applied.
Copy link
Contributor

Choose a reason for hiding this comment

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

if no specific ordering, should we call the flag reverse? What is it reversing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We could call it reverse, it's just a little tricky because as I mentioned above, the default ordering is by ID which will essentially be ordering by time in ascending order.

@kian99 kian99 changed the title Audit log enhacement CSS-5179 Audit log enhacement Aug 15, 2023
@babakks
Copy link
Member

babakks commented Aug 15, 2023

I think the --reverse option is clear enough for the user. It just means it returns the list in the reverse order you'd normally get.

@kian99 kian99 merged commit 8af625d into canonical:feature-rebac Aug 15, 2023
1 check passed
@kian99 kian99 deleted the audit-log-enhacement branch August 15, 2023 09:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants