Fix Usernamespace Audit events
What does this MR do and why?
Fix Usernamespace Audit events
This commit adds a batched background migration to update usernamespace audit events to instance scope and also insert them in new table of instance audit events
Changelog: other
References
Please include cross links to any resources that are relevant to this MR. This will give reviewers and future readers helpful context to give an efficient review of the changes introduced.
Migration Logs
rails db:migrate
DEPRECATION WARNING: Support for Rails versions < 7.1 is deprecated and will be removed from ViewComponent 4.0.0 (ViewComponent v4 will remove support for Rails versions < 7.1 no earlier than April 1, 2025) (called from <main> at /Users/harsimar/dev/gitlab-development-kit/gitlab/config/environment.rb:7)
main: == [advisory_lock_connection] object_id: 131440, pg_backend_pid: 55381
main: == 20250106104021 QueueFixUsernamespaceAuditEvents: migrating =================
main: == 20250106104021 QueueFixUsernamespaceAuditEvents: migrated (0.0671s) ========
main: == [advisory_lock_connection] object_id: 131440, pg_backend_pid: 55381
ci: == [advisory_lock_connection] object_id: 131880, pg_backend_pid: 55383
ci: == 20250106104021 QueueFixUsernamespaceAuditEvents: migrating =================
ci: -- The migration is skipped since it modifies the schemas: [:gitlab_main].
ci: -- This database can only apply migrations in one of the following schemas: [:gitlab_ci, :gitlab_internal, :gitlab_shared].
ci: == 20250106104021 QueueFixUsernamespaceAuditEvents: migrated (0.0064s) ========
ci: == [advisory_lock_connection] object_id: 131880, pg_backend_pid: 55383
How to set up and validate locally
For testing purposes you can update your local audit events entity type to Namespaces::UserNamespace
run rails console and enter:
AuditEvent.update_all(entity_type: 'Namespaces::UserNamespace')
after running migration:
- Check if data is correctly inserted into
AuditEvents::InstanceAuditEvent
- Historical audit events should now have
entity_type: Gitlab::Audit::InstanceScope
Related to #500619
Edited by Harsimar Sandhu