[FF] use_db_diff_for_code_owner_entries -- Use DB-based diff comparison for code owner entries

Everyone can contribute. Help move this issue forward while earning points, leveling up and collecting rewards.

Summary

This issue is to roll out the DB-based diff comparison optimization on production, that is currently behind the use_db_diff_for_code_owner_entries feature flag.

When enabled, this feature uses persisted merge_request_diff_files from the database to compute the symmetric difference of modified paths between consecutive MR diff versions, instead of making an expensive Gitaly CompareService RPC call. This is the largest bottleneck in MergeRequestResetApprovalsWorker (P95: 4.636s for entries_since_commit).

Falls back to the Gitaly-based comparison when no matching MergeRequestDiff record exists.

Related issue: #579591

Owners

  • Most appropriate Slack channel to reach out to: #g_code_review
  • Best individual to reach out to: @marc_shaw

Expectations

What are we expecting to happen?

Significant reduction in entries_since_commit latency for the MergeRequestResetApprovalsWorker. Local benchmarks show a 3.5x speedup. Production impact expected to be larger since Gitaly RPC cost scales with repo size.

What can go wrong and how would we detect it?

  • Incorrect path comparison could lead to wrong code owner approvals being reset. This would manifest as approvals being incorrectly preserved or incorrectly removed.
  • Monitor merge_request_reset_approvals_worker duration metrics and error rates.
  • The feature gracefully falls back to Gitaly when no matching diff record exists.

Rollout Steps

Rollout on non-production environments

  • Enable the feature flag on staging with /chatops run feature set use_db_diff_for_code_owner_entries true --dev --pre --staging --staging-ref
  • Verify that code owner approval resets work correctly on staging

Global rollout on production

  • Incrementally roll out the feature on production
    • /chatops run feature set use_db_diff_for_code_owner_entries 25 --actors
    • /chatops run feature set use_db_diff_for_code_owner_entries 50 --actors
    • /chatops run feature set use_db_diff_for_code_owner_entries 100 --actors
  • Monitor entries_since_commit duration metrics for improvement
  • Enable globally: /chatops run feature set use_db_diff_for_code_owner_entries true

Release the feature

  • Create a merge request to remove the feature flag
  • Close this issue

Rollback Steps

  • This feature can be disabled by running: /chatops run feature set use_db_diff_for_code_owner_entries false
Edited by 🤖 GitLab Bot 🤖