Skip to content

Improve auditlog table and model#3776

Merged
Simrayz merged 3 commits intomasterfrom
feat/3757-improve-auditlog-table-and-model
Mar 20, 2026
Merged

Improve auditlog table and model#3776
Simrayz merged 3 commits intomasterfrom
feat/3757-improve-auditlog-table-and-model

Conversation

@Simrayz
Copy link
Copy Markdown
Contributor

@Simrayz Simrayz commented Feb 10, 2026

Scope and purpose

Resolves #3757

Adds sortable display name columns (actor_sortkey, object_sortkey, target_sortkey) to auditlog entries. This enables sorting and searching on these columns, and allows showing entity links when the referenced objects still exist.

Key decisions:

  • Sortkeys preserve display names after objects are deleted
  • Batch resolution pattern loads entities without causing N+1 queries
  • Created API v2 to add entity linking while maintaining v1 backward compatibility

API v2 added: New /api/2/auditlog/ endpoint returns actor, object, and target as objects with {name, url} for entity linking. The existing /api/1/auditlog/ endpoint continues to return plain strings and remains unchanged. The web UI now uses v2.

Migration note: The backfill operation may take some time on deployments with millions of log entries.

Testing backfill and entity links

Filter by verb=edit-account-add-org, verb=disable-interface, verb=create-netbox, verb=delete-netbox, or verb=create-account to observe:

  • Clickable links when entities still exist - The actor/object/target names are clickable and navigate to the entity's detail page (e.g., clicking an account name goes to the account detail page)
  • Placeholder text when entities are deleted - Shows model_name (ID) format (e.g., account (123)) since the object no longer exists, but the sortkey preserved the searchable text

Contributor Checklist

Every pull request should have this checklist filled out, no matter how small it is.
More information about contributing to NAV can be found in the
Hacker's guide to NAV.

  • Added a changelog fragment for towncrier
  • Added/amended tests for new/changed code
  • Added/changed documentation
  • Linted/formatted the code with ruff, easiest by using pre-commit
  • Wrote the commit message so that the first line continues the sentence "If applied, this commit will ...", starts with a capital letter, does not end with punctuation and is 50 characters or less long. See https://cbea.ms/git-commit/
  • Based this pull request on the correct upstream branch: For a patch/bugfix affecting the latest stable version, it should be based on that version's branch (<major>.<minor>.x). For a new feature or other additions, it should be based on master.
  • If applicable: Created new issues if this PR does not fix the issue completely/there is further work to be done
  • If it's not obvious from a linked issue, described how to interact with NAV in order for a reviewer to observe the effects of this change first-hand (commands, URLs, UI interactions)
  • If this results in changes in the UI: Added screenshots of the before and after
  • If this adds a new Python source code file: Added the boilerplate header to that file

@github-actions
Copy link
Copy Markdown

github-actions bot commented Feb 10, 2026

Test results

    13 files      13 suites   24m 57s ⏱️
 2 907 tests  2 907 ✅ 0 💤 0 ❌
16 998 runs  16 998 ✅ 0 💤 0 ❌

Results for commit fd79ad9.

♻️ This comment has been updated with latest results.

@codecov
Copy link
Copy Markdown

codecov bot commented Feb 10, 2026

Codecov Report

❌ Patch coverage is 92.30769% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 63.89%. Comparing base (234c86d) to head (04d1731).
⚠️ Report is 4 commits behind head on master.

Files with missing lines Patch % Lines
python/nav/auditlog/api.py 91.66% 7 Missing ⚠️
python/nav/models/manage.py 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3776      +/-   ##
==========================================
+ Coverage   63.83%   63.89%   +0.06%     
==========================================
  Files         624      625       +1     
  Lines       46174    46260      +86     
  Branches       43       43              
==========================================
+ Hits        29476    29559      +83     
- Misses      16688    16691       +3     
  Partials       10       10              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Simrayz Simrayz force-pushed the feat/3757-improve-auditlog-table-and-model branch 3 times, most recently from 56f4174 to 0d458cb Compare February 12, 2026 11:45
@Simrayz Simrayz requested a review from a team February 12, 2026 12:32
@Simrayz Simrayz force-pushed the feat/3757-improve-auditlog-table-and-model branch from d4445f6 to 3837d41 Compare February 12, 2026 12:34
@Simrayz Simrayz marked this pull request as ready for review February 12, 2026 12:35
@Simrayz Simrayz force-pushed the feat/3757-improve-auditlog-table-and-model branch from 3837d41 to 878e419 Compare February 12, 2026 12:58
@Simrayz Simrayz force-pushed the feat/3757-improve-auditlog-table-and-model branch from 878e419 to 35e0dc7 Compare February 12, 2026 13:15
@sonarqubecloud
Copy link
Copy Markdown

@lunkwill42
Copy link
Copy Markdown
Member

This potentially replaces #3705

@lunkwill42
Copy link
Copy Markdown
Member

Migration note: The backfill operation may take some time on deployments with millions of log entries.

Just to have some real-world data: I checked customer installs, and the biggest audit log table I could find was about ~64k rows.

Copy link
Copy Markdown
Member

@lunkwill42 lunkwill42 left a comment

Choose a reason for hiding this comment

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

Seems pretty good (apart from the obvious table bloat, but that's a tradeoff we'll have to live with).

The merge conflict / migration script names has to be fixed - I assume we can get this in 5.18 :-)

@Simrayz Simrayz force-pushed the feat/3757-improve-auditlog-table-and-model branch from 35e0dc7 to 867db61 Compare March 20, 2026 08:45
@Simrayz Simrayz requested a review from lunkwill42 March 20, 2026 10:21
Copy link
Copy Markdown
Member

@lunkwill42 lunkwill42 left a comment

Choose a reason for hiding this comment

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

👍

Simrayz added 3 commits March 20, 2026 15:38
Add actor_sortkey, object_sortkey, and target_sortkey columns to
the auditlog_logentry table. These store the human-readable display
name at write time, enabling efficient database-level sorting and
searching, and preserving display names after referenced objects
are deleted.
@Simrayz Simrayz force-pushed the feat/3757-improve-auditlog-table-and-model branch from fd79ad9 to 04d1731 Compare March 20, 2026 14:38
@Simrayz Simrayz merged commit ba5d68e into master Mar 20, 2026
13 of 14 checks passed
@sonarqubecloud
Copy link
Copy Markdown

@Simrayz Simrayz deleted the feat/3757-improve-auditlog-table-and-model branch March 20, 2026 14:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Proposal to make our current auditlog much easier to deal with

2 participants