Skip to content

Update namespace_id in standards adherence when a project is moved

What does this MR do and why?

  1. Update namespace_id in standards adherence when a project is moved. When a project is moved but the namespace_id in the compliance_standards_adherence for that project is not updated it leads to an infinite loop of retrying the service which caused the incident gitlab-com/gl-infra/production#16234 (closed). More details in this comment.

  2. It creates the following database query and seems to be efficient on executing this on DB lab.

UPDATE
    "project_compliance_standards_adherence"
SET
    "namespace_id" = 785414
WHERE
    "project_compliance_standards_adherence"."project_id" = 278964
  1. Changes in the finder query
SELECT
    "project_compliance_standards_adherence".*
FROM
    "project_compliance_standards_adherence"
WHERE
    "project_compliance_standards_adherence"."project_id" = 48778131
    AND "project_compliance_standards_adherence"."check_name" = 0
    AND "project_compliance_standards_adherence"."standard" = 0
ORDER BY
    "project_compliance_standards_adherence"."id" ASC
LIMIT 1

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other merge requests.

Before After

How to set up and validate locally

Numbered steps to set up and validate the change are strongly suggested.

  1. Ensure you have Ultimate license.
  2. Enable feature flag Feature.enable(:compliance_adherence_report).
  3. Create a new project in a group. Existing projects won't have compliance adherence records hence you should create new projects.
  4. Once the project is created visit the compliance center dashboard. Eg: https://<gdk-host>/groups/<group-name>/-/security/compliance_dashboard/standards_adherence. Verify that the standards adherence records for the new projects are visible.
  5. Move the project to a new group.
  6. Switch to master branch
  7. Navigate to the project's merge request settings and update the number of required approvers. This will retry the AtLeastTwoApprovalsService infinitely and the process will never stop. The reason for that is this block of code which keeps on retrying since the adherence record is not found for the given combination of namespace_id, project_id, check_name, and standard.
  8. Switch to this MR's branch
  9. Follow steps 3-5 and then navigate to project's merge request settings and update the number of required approvers. This time the service will run only once and update the status of the adherence record correctly.

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Closes #423405 (closed)

Edited by Huzaifa Iftikhar

Merge request reports

Loading