Skip to content

Update agent config for workspaces with desired state not terminated

Vishal Tak requested to merge vtak/rename_scopes into master

What does this MR do and why?

Based on Sync in the Remote Development team on 2024/01/15, we decided that the agent configuration would only be updated when the desired state of the workspace is not terminated.

Related discussion

/cc @hkhanna2 @cwoolley-gitlab @a_akgun

DB query and plans

Query for the code

          model_instance
            .workspaces
            .desired_state_not_terminated
            .update_all(force_include_all_resources: true)
UPDATE
    "workspaces"
SET
    "force_include_all_resources" = TRUE
WHERE
    "workspaces"."id" IN (
        SELECT
            "workspaces"."id"
        FROM
            "workspaces"
            INNER JOIN "cluster_agents" ON "workspaces"."cluster_agent_id" = "cluster_agents"."id"
        WHERE
            "cluster_agents"."id" = 12
            AND "workspaces"."desired_state" != 'Terminated')

DB Query plan - https://postgres.ai/console/gitlab/gitlab-production-tunnel-pg12/sessions/25223/commands/80116

 ModifyTable on public.workspaces  (cost=6.76..9.80 rows=0 width=0) (actual time=3.497..3.499 rows=0 loops=1)
   Buffers: shared hit=3 read=1
   I/O Timings: read=3.445 write=0.000
   ->  Nested Loop  (cost=6.76..9.80 rows=1 width=19) (actual time=3.495..3.497 rows=0 loops=1)
         Buffers: shared hit=3 read=1
         I/O Timings: read=3.445 write=0.000
         ->  HashAggregate  (cost=6.49..6.50 rows=1 width=20) (actual time=3.494..3.496 rows=0 loops=1)
               Group Key: workspaces_1.id
               Buffers: shared hit=3 read=1
               I/O Timings: read=3.445 write=0.000
               ->  Nested Loop  (cost=0.43..6.48 rows=1 width=20) (actual time=3.492..3.493 rows=0 loops=1)
                     Buffers: shared hit=3 read=1
                     I/O Timings: read=3.445 write=0.000
                     ->  Index Scan using index_workspaces_on_cluster_agent_id on public.workspaces workspaces_1  (cost=0.15..3.17 rows=1 width=22) (actual time=3.491..3.491 rows=0 loops=1)
                           Index Cond: (workspaces_1.cluster_agent_id = 12)
                           Filter: (workspaces_1.desired_state <> 'Terminated'::text)
                           Rows Removed by Filter: 0
                           Buffers: shared hit=3 read=1
                           I/O Timings: read=3.445 write=0.000
                     ->  Index Scan using cluster_agents_pkey on public.cluster_agents  (cost=0.29..3.31 rows=1 width=14) (actual time=0.000..0.000 rows=0 loops=0)
                           Index Cond: (cluster_agents.id = 12)
                           I/O Timings: read=0.000 write=0.000
         ->  Index Scan using workspaces_pkey on public.workspaces  (cost=0.27..3.29 rows=1 width=14) (actual time=0.000..0.000 rows=0 loops=0)
               Index Cond: (workspaces.id = workspaces_1.id)
               I/O Timings: read=0.000 write=0.000

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

How to set up and validate locally

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

  1. Running the tests should be fine.
Edited by Vishal Tak

Merge request reports