Add audit event when the "Collect usage data" setting is changed

What does this MR do and why?

Adds an audit event when the "Collect usage data" (ai_usage_data_collection_enabled) setting is changed on a group. This allows administrators to track who changed the setting and when.

Closes #595736

Implementation

The ai_usage_data_collection_enabled setting is stored in the namespace_ai_settings table (via Ai::NamespaceSetting), separate from the namespace_settings table that is already audited by NamespaceSettingChangesAuditor.

This MR adds:

  1. Namespaces::AiNamespaceSettingChangesAuditor - A new auditor class following the same pattern as NamespaceSettingChangesAuditor, but for the namespace_ai_settings table. Currently audits ai_usage_data_collection_enabled, but is designed to be extensible for future Ai::NamespaceSetting columns.

  2. Integration into GroupChangesAuditor - The new auditor is called from GroupChangesAuditor#execute, alongside the existing NamespaceSettingChangesAuditor and NamespaceDetailChangesAuditor calls.

  3. Audit event type YAML - ai_usage_data_collection_enabled_updated event type definition.

  4. Tests - RSpec tests for the new auditor.

References

Screenshots or screen recordings

No UI changes.

Before After
No audit event logged when "Collect usage data" setting is changed Audit event ai_usage_data_collection_enabled_updated is logged with from/to values and actor

How to set up and validate locally

  1. Enable the feature in rails console or via the group settings UI
  2. Navigate to a group's GitLab Duo settings and toggle the "Collect usage data" setting
  3. Check the audit log for the group - you should see an ai_usage_data_collection_enabled_updated event with the old and new values image

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Fred de Gier

Merge request reports

Loading