Skip to content

Delete PagesDeployment when MergeRequest gets closed or merged

What does this MR do and why?

This MR adds a Worker to ensure Pages deployments created by a MR will be deactivated (soft delete) when that MR gets closed or merged. See #425940 (closed) for the full issue description.

For context: We perform a soft delete (setting deleted_at), because we can use the existing cronjob that will perform a hard delete on all deployments with deleted_at <= now

Screenshots or screen recordings

(There is no UI change)

How to set up and validate locally

  1. Create a Project with a Pages deployment triggered by a MR, for example using the following .gitlab-ci.yml:
pages:
  script:
    - mkdir public
    - echo '<html><body><h1>Hello World</h1></body></html>' > public/index.html
  artifacts:
    paths:
      - public
  publish: public
  only:
  - merge_requests
  1. Open an MR on the project, wait until the pages deployment job is complete
  2. Since the MR enabling this is not yet merged, update the created PagesDeployment's path_prefix manually to /foo
  3. Close the MR
  4. View the PagesDeployment's deleted_at column now has a value.

Query plan

UPDATE "pages_deployments" SET deleted_at=now() WHERE NOT (("pages_deployments"."path_prefix" = '' OR "pages_deployments"."path_prefix" IS NULL)) AND "pages_deployments"."ci_build_id" IN [604, 123]

Plan

 ModifyTable on public.pages_deployments  (cost=0.55..6.55 rows=0 width=0) (actual time=0.098..0.099 rows=0 loops=1)
   Buffers: shared hit=11
   I/O Timings: read=0.000 write=0.000
   ->  Index Scan using index_pages_deployments_on_ci_build_id on public.pages_deployments  (cost=0.55..6.55 rows=1 width=14) (actual time=0.096..0.097 rows=0 loops=1)
         Index Cond: (pages_deployments.ci_build_id = ANY ('{604,123}'::bigint[]))
         Filter: ((pages_deployments.path_prefix IS NOT NULL) AND (pages_deployments.path_prefix <> ''::text))
         Rows Removed by Filter: 0
         Buffers: shared hit=11
         I/O Timings: read=0.000 write=0.000

Summary

Time: 1.473 ms  
  - planning: 1.317 ms  
  - execution: 0.156 ms  
    - I/O read: 0.000 ms  
    - I/O write: 0.000 ms  
  
Shared buffers:  
  - hits: 11 (~88.00 KiB) from the buffer pool  
  - reads: 0 from the OS file cache, including disk I/O  
  - dirtied: 0  
  - writes: 0  

Link

https://console.postgres.ai/gitlab/gitlab-production-tunnel-pg12/sessions/23980/commands/76663

MR acceptance checklist

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

Related to #425940 (closed)

Edited by Janis Altherr

Merge request reports