Drop prematurely added FK constraint fk_rails_3f92913d27
Production Change
Change Summary
This change issue aims to expediently mitigate the severity2 incident #18792 (closed). The POST /api/:version/runners/verify endpoint is failing for CI runners that are either new or have not been active for over 7 days. The root cause for that failure is the premature creation of a foreign key constraint, which we need to drop. Rather than wait for a 2nd attempt at doing so via a rails migration, we are going to manually drop it and then follow-up with an equivalent migration.
For context, the FK constraint to be dropped was newly created today. The table referenced by the constraint has not yet been backfilled. The constraint is in a NOT VALID state, but it still gets enforced for new INSERT/UPDATE statements -- some of which are failing due to the lack of a backfill.
Change Details
- Services Impacted - ServicePostgres (and fixes ServiceAPI)
- Change Technician - @msmiley
- Change Reviewer - DRI for the review of this change
- Time tracking - 5 minutes
-
Downtime Component - Applying the schema change is expected to cause a brief spike of lock contention in the
cidatabase but no downtime. The incident's ongoing API errors should immediately stop, bringing the incident to a IncidentMitigated status.
Set Maintenance Mode in GitLab
If your change involves scheduled maintenance, add a step to set and unset maintenance mode per our runbooks. This will make sure SLA calculations adjust for the maintenance period.
Detailed steps for the change
Change Steps - steps to take to execute the change
Estimated Time to Complete (mins) - Estimated Time to Complete in Minutes
-
Set label changein-progress /label ~change::in-progress -
Run the following SQL on the cidatabase's primary node (currentlypatroni-ci-v16-01-db-gprd.c.gitlab-production.internal). If it fails due to statement timeout or deadlock, try again. The change is idempotent.BEGIN ; SET statement_timeout = '1s' ; LOCK TABLE group_type_ci_runners_e59bb2812d ; LOCK TABLE group_type_ci_runner_machines_687967fa8a ; ALTER TABLE group_type_ci_runner_machines_687967fa8a DROP CONSTRAINT IF EXISTS fk_rails_3f92913d27 ; COMMIT ; -
Check the postgres logs to confirm the FK constraint violation errors have stopped insert or update on table "group_type_ci_runner_machines_687967fa8a" violates foreign key constraint "fk_rails_3f92913d27" -
Check the rails logs to confirm the API endpoint POST /api/:version/runners/verifyhas stopped throwing HTTP 500 errors. -
Set label changecomplete /label ~change::complete
Rollback
Rollback steps - steps to be taken in the event of a need to rollback this change
This change should not be rolled back, but for completeness, running the following SQL would recreate the FK constraint in its current (NOT VALID) state.
ALTER TABLE group_type_ci_runner_machines_687967fa8a
ADD CONSTRAINT "fk_rails_3f92913d27" FOREIGN KEY (runner_id, runner_type) REFERENCES group_type_ci_runners_e59bb2812d(id, runner_type)
ON UPDATE CASCADE
ON DELETE CASCADE
NOT VALID
;
Monitoring
Key metrics to observe
-
Postgres logs - FK constraint violation errors specific to this FK constraint:
insert or update on table "group_type_ci_runner_machines_687967fa8a" violates foreign key constraint "fk_rails_3f92913d27" -
Rails logs - Rails error logs specifically for the failing API endpoint
POST /api/:version/runners/verify - Rails
apidashboard showing overall error ratio: https://dashboards.gitlab.net/d/api-main/api3a-overview?from=now-6h%2Fm&to=now-1m%2Fm&var-environment=gprd&var-stage=main&orgId=1&viewPanel=387946920
Change Reviewer checklist
-
Check if the following applies: - The scheduled day and time of execution of the change is appropriate.
- The change plan is technically accurate.
- The change plan includes estimated timing values based on previous testing.
- The change plan includes a viable rollback plan.
- The specified metrics/monitoring dashboards provide sufficient visibility for the change.
-
Check if the following applies: - The complexity of the plan is appropriate for the corresponding risk of the change. (i.e. the plan contains clear details).
- The change plan includes success measures for all steps/milestones during the execution.
- The change adequately minimizes risk within the environment/service.
- The performance implications of executing the change are well-understood and documented.
- The specified metrics/monitoring dashboards provide sufficient visibility for the change.
- If not, is it possible (or necessary) to make changes to observability platforms for added visibility?
- The change has a primary and secondary SRE with knowledge of the details available during the change window.
- The change window has been agreed with Release Managers in advance of the change. If the change is planned for APAC hours, this issue has an agreed pre-change approval.
- The labels blocks deployments and/or blocks feature-flags are applied as necessary.
Change Technician checklist
-
Check if all items below are complete: - The change plan is technically accurate.
- This Change Issue is linked to the appropriate Issue and/or Epic
- Change has been tested in staging and results noted in a comment on this issue.
- A dry-run has been conducted and results noted in a comment on this issue.
- The change execution window respects the Production Change Lock periods.
- For C1 and C2 change issues, the change event is added to the GitLab Production calendar.
- For C1 and C2 change issues, the SRE on-call has been informed prior to change being rolled out. (In #production channel, mention
@sre-oncalland this issue and await their acknowledgement.) - For C1 and C2 change issues, the SRE on-call provided approval with the eoc_approved label on the issue.
- For C1 and C2 change issues, the Infrastructure Manager provided approval with the manager_approved label on the issue.
- Release managers have been informed prior to any C1, C2, or blocks deployments change being rolled out. (In #production channel, mention
@release-managersand this issue and await their acknowledgment.) - There are currently no active incidents that are severity1 or severity2
- If the change involves doing maintenance on a database host, an appropriate silence targeting the host(s) should be added for the duration of the change.