Skip to content

Migrate all 'incident' labelled issues to have issue type 'incident'

What does this MR do?

Blocked by !37781 (merged), or else this migration will have to be ran again in the future.

Adds the issue_type of incident to the Issues which be define as incident issues.

We use the combination of:

  • Issues authored by Alert bot, and
  • with the incident label

This matches the criteria we use when creating the issues (label and alert bot user).

database up/down:

I've added ActiveRecord::Base.logger = Logger.new(STDOUT) to the migration to get the output

UP

== 20200723040950 MigrateIncidentIssuesToIncidentType: migrating ==============
D, [2020-07-29T12:17:58.035891 #8814] DEBUG -- :    (0.2ms)  BEGIN
D, [2020-07-29T12:17:58.052749 #8814] DEBUG -- :   MigrateIncidentIssuesToIncidentType::Issue Load (3.5ms)  SELECT "issues"."id" FROM "issues" INNER JOIN label_links ON label_links.target_type = 'Issue' AND label_links.target_id = issues.id INNER JOIN labels ON labels.id = label_links.label_id WHERE "labels"."title" = $1 AND "labels"."color" = $2 AND "labels"."description" = $3 ORDER BY "issues"."id" ASC LIMIT $4  [["title", "incident"], ["color", "#CC0033"], ["description", "Denotes a disruption to IT services and the associated issues require immediate attention"], ["LIMIT", 1]]
D, [2020-07-29T12:17:58.053106 #8814] DEBUG -- :   ↳ app/models/concerns/each_batch.rb:61:in `each_batch'
D, [2020-07-29T12:17:58.076653 #8814] DEBUG -- :   MigrateIncidentIssuesToIncidentType::Issue Load (1.2ms)  SELECT "issues"."id" FROM "issues" INNER JOIN label_links ON label_links.target_type = 'Issue' AND label_links.target_id = issues.id INNER JOIN labels ON labels.id = label_links.label_id WHERE "labels"."title" = $1 AND "labels"."color" = $2 AND "labels"."description" = $3 AND "issues"."id" >= 440 ORDER BY "issues"."id" ASC LIMIT $4 OFFSET $5  [["title", "incident"], ["color", "#CC0033"], ["description", "Denotes a disruption to IT services and the associated issues require immediate attention"], ["LIMIT", 1], ["OFFSET", 1000]]
D, [2020-07-29T12:17:58.076984 #8814] DEBUG -- :   ↳ app/models/concerns/each_batch.rb:78:in `block in each_batch'
D, [2020-07-29T12:17:58.103055 #8814] DEBUG -- :   MigrateIncidentIssuesToIncidentType::Issue Update All (25.4ms)  UPDATE "issues" SET "issue_type" = $1, "lock_version" = COALESCE("lock_version", 0) + $2 WHERE "issues"."id" IN (SELECT "issues"."id" FROM "issues" INNER JOIN label_links ON label_links.target_type = 'Issue' AND label_links.target_id = issues.id INNER JOIN labels ON labels.id = label_links.label_id WHERE "labels"."title" = $3 AND "labels"."color" = $4 AND "labels"."description" = $5 AND "issues"."id" >= 440)  [["issue_type", 1], ["lock_version", 1], ["title", "incident"], ["color", "#CC0033"], ["description", "Denotes a disruption to IT services and the associated issues require immediate attention"]]
D, [2020-07-29T12:17:58.103346 #8814] DEBUG -- :   ↳ app/models/concerns/each_batch.rb:90:in `block in each_batch'
== 20200723040950 MigrateIncidentIssuesToIncidentType: migrated (0.0691s) =====
EXPLAIN for migration (complete update)
ModifyTable on public.issues  (cost=194.13..197.03 rows=5 width=1301) (actual time=206280.103..206280.103 rows=0 loops=1)
   Buffers: shared hit=1001169 read=151080 dirtied=112670
   I/O Timings: read=196463.800
   ->  Nested Loop  (cost=194.13..197.03 rows=5 width=1301) (actual time=13019.194..13228.307 rows=6865 loops=1)
         Buffers: shared hit=69159 read=6599
         I/O Timings: read=12639.399
         ->  HashAggregate  (cost=193.56..193.61 rows=5 width=26) (actual time=13019.161..13039.475 rows=6865 loops=1)
               Group Key: issues_1.id
               Buffers: shared hit=34816 read=6599
               I/O Timings: read=12639.399
               ->  Nested Loop  (cost=1.57..193.55 rows=5 width=26) (actual time=0.091..12960.694 rows=6878 loops=1)
                     Buffers: shared hit=34816 read=6599
                     I/O Timings: read=12639.399
                     ->  Nested Loop  (cost=1.00..190.15 rows=5 width=16) (actual time=0.075..74.322 rows=6878 loops=1)
                           Buffers: shared hit=7007
                           ->  Index Scan using index_labels_on_title on public.labels  (cost=0.43..70.44 rows=1 width=10) (actual time=0.041..1.041 rows=71 loops=1)
                                 Index Cond: ((labels.title)::text = 'incident'::text)
                                 Filter: (((labels.color)::text = '#CC0033'::text) AND ((labels.description)::text = 'Denotes a disruption to IT services and the associated issues require immediate attention'::text))
                                 Rows Removed by Filter: 79
                                 Buffers: shared hit=154
                           ->  Index Scan using index_label_links_on_label_id on public.label_links  (cost=0.57..115.84 rows=387 width=14) (actual time=0.023..0.935 rows=97 loops=71)
                                 Index Cond: (label_links.label_id = labels.id)
                                 Filter: ((label_links.target_type)::text = 'Issue'::text)
                                 Rows Removed by Filter: 0
                                 Buffers: shared hit=6853
                     ->  Index Scan using issues_pkey on public.issues issues_1  (cost=0.56..0.68 rows=1 width=10) (actual time=1.868..1.868 rows=1 loops=6878)
                           Index Cond: (issues_1.id = label_links.target_id)
                           Buffers: shared hit=27809 read=6599
                           I/O Timings: read=12639.399
         ->  Index Scan using issues_pkey on public.issues  (cost=0.56..0.68 rows=1 width=1253) (actual time=0.022..0.022 rows=1 loops=6865)
               Index Cond: (issues.id = label_links.target_id)
               Buffers: shared hit=34343

Down:

== 20200723040950 MigrateIncidentIssuesToIncidentType: reverting ==============
D, [2020-07-29T12:19:31.156738 #8878] DEBUG -- :    (0.1ms)  BEGIN
D, [2020-07-29T12:19:31.157135 #8878] DEBUG -- :   ↳ app/models/concerns/each_batch.rb:50:in `each_batch'
D, [2020-07-29T12:19:31.169535 #8878] DEBUG -- :   MigrateIncidentIssuesToIncidentType::Issue Load (1.7ms)  SELECT "issues"."id" FROM "issues" WHERE "issues"."issue_type" = $1 ORDER BY "issues"."id" ASC LIMIT $2  [["issue_type", 1], ["LIMIT", 1]]
D, [2020-07-29T12:19:31.169882 #8878] DEBUG -- :   ↳ app/models/concerns/each_batch.rb:61:in `each_batch'
D, [2020-07-29T12:19:31.191440 #8878] DEBUG -- :   MigrateIncidentIssuesToIncidentType::Issue Load (0.7ms)  SELECT "issues"."id" FROM "issues" WHERE "issues"."issue_type" = $1 AND "issues"."id" >= 440 ORDER BY "issues"."id" ASC LIMIT $2 OFFSET $3  [["issue_type", 1], ["LIMIT", 1], ["OFFSET", 1000]]
D, [2020-07-29T12:19:31.191842 #8878] DEBUG -- :   ↳ app/models/concerns/each_batch.rb:78:in `block in each_batch'
D, [2020-07-29T12:19:31.211388 #8878] DEBUG -- :   MigrateIncidentIssuesToIncidentType::Issue Update All (19.0ms)  UPDATE "issues" SET "issue_type" = $1, "lock_version" = COALESCE("lock_version", 0) + $2 WHERE "issues"."issue_type" = $3 AND "issues"."id" >= 440  [["issue_type", 0], ["lock_version", 1], ["issue_type", 1]]
D, [2020-07-29T12:19:31.211665 #8878] DEBUG -- :   ↳ app/models/concerns/each_batch.rb:90:in `block in each_batch'
== 20200723040950 MigrateIncidentIssuesToIncidentType: reverted (0.0566s) =====

Screenshots

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:

  • [-] Label as security and @ mention @gitlab-com/gl-security/appsec
  • [-] The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • [-] Security reports checked/validated by a reviewer from the AppSec team

Related to #229544 (closed)

Edited by Mayra Cabrera

Merge request reports

Loading