Update namespace_id in standards adherence when a project is moved
What does this MR do and why?
-
Update
namespace_id
in standards adherence when a project is moved. When a project is moved but thenamespace_id
in thecompliance_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. -
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
- Changes in the finder query
- Existing query - https://console.postgres.ai/gitlab/gitlab-production-tunnel-pg12/sessions/21857/commands/70846
- New Query - https://console.postgres.ai/gitlab/gitlab-production-tunnel-pg12/sessions/21881/commands/70879
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.
- Ensure you have Ultimate license.
- Enable feature flag
Feature.enable(:compliance_adherence_report)
. - Create a new project in a group. Existing projects won't have compliance adherence records hence you should create new projects.
- 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. - Move the project to a new group.
- Switch to master branch
-
⚠ Navigate to the project's merge request settings and update the number of required approvers. This will retry theAtLeastTwoApprovalsService
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 ofnamespace_id
,project_id
,check_name
, andstandard
. - Switch to this MR's branch
- 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.
-
I have evaluated the MR acceptance checklist for this MR.
Closes #423405 (closed)