Add label_applied and scope to Issuable Sla
What does this MR do?
This MR adds a new column, label_applied
, to the IssuableSla
model. This is used to mark that a label (Exceeded SLA) label has been applied to the related issue.
We use this boolean column to avoid enqueuing needless jobs in the IncidentManagement::IncidentSlaExceededCheckWorker
. Previously, if the issue/incident was still open we would enqueue a job to add a SLA label even if the label had been applied already.
DB Migration
Up:
== 20210712052519 AddLabelAppliedIssuableClosedToIssuableSla: migrating =======
-- add_column(:issuable_slas, :label_applied, :boolean, {:default=>false, :null=>false})
-> 0.0092s
-- add_column(:issuable_slas, :issuable_closed, :boolean, {:default=>false, :null=>false})
-> 0.0016s
== 20210712052519 AddLabelAppliedIssuableClosedToIssuableSla: migrated (0.0109s)
== 20210714043818 AddIndexForLabelAppliedToIssuableSla: migrating =============
-- transaction_open?()
-> 0.0000s
-- index_exists?(:issuable_slas, :due_at, {:name=>"index_issuable_slas_on_due_at_label_applied", :where=>"label_applied = FALSE", :algorithm=>:concurrently})
-> 0.0039s
-- execute("SET statement_timeout TO 0")
-> 0.0005s
-- add_index(:issuable_slas, :due_at, {:name=>"index_issuable_slas_on_due_at_label_applied", :where=>"label_applied = FALSE", :algorithm=>:concurrently})
-> 0.0193s
-- execute("RESET ALL")
-> 0.0007s
== 20210714043818 AddIndexForLabelAppliedToIssuableSla: migrated (0.0252s) ====
Post Migration:
== 20210722042939 UpdateIssuableSlasWhereIssueClosed: migrating ===============
-- execute("UPDATE issuable_slas SET issuable_closed = TRUE WHERE issuable_slas.id IN (SELECT issuable_slas.id FROM issuable_slas INNER JOIN issues ON issues.id = issuable_slas.issue_id WHERE (issues.state_id IN (2)))")
-> 0.0258s
== 20210722042939 UpdateIssuableSlasWhereIssueClosed: migrated (0.0259s) ======
Down:
== 20210712052519 AddLabelAppliedIssuableClosedToIssuableSla: reverting =======
-- remove_column(:issuable_slas, :issuable_closed, :boolean, {:default=>false, :null=>false})
-> 0.0170s
-- remove_column(:issuable_slas, :label_applied, :boolean, {:default=>false, :null=>false})
-> 0.0010s
== 20210712052519 AddLabelAppliedIssuableClosedToIssuableSla: reverted (0.0203s)
== 20210714043818 AddIndexForLabelAppliedToIssuableSla: reverting =============
-- transaction_open?()
-> 0.0000s
-- indexes(:issuable_slas)
-> 0.0030s
-- execute("SET statement_timeout TO 0")
-> 0.0005s
-- remove_index(:issuable_slas, {:algorithm=>:concurrently, :name=>"index_issuable_slas_on_id_due_at_label_applied"})
-> 0.0065s
-- execute("RESET ALL")
-> 0.0005s
== 20210714043818 AddIndexForLabelAppliedToIssuableSla: reverted (0.0114s) ====
Post migration (no-op):
== 20210722042939 UpdateIssuableSlasWhereIssueClosed: reverting ===============
== 20210722042939 UpdateIssuableSlasWhereIssueClosed: reverted (0.0000s) ======
Queries used in worker
- Before: https://explain.depesz.com/s/6GPg
- After:
- Outer loop: https://explain.depesz.com/s/oIQO (DB lab: https://console.postgres.ai/gitlab/gitlab-production-tunnel-pg12/sessions/5266/commands/18586)
- Inner loop (
records.to_sql
): DB lab: https://postgres.ai/console/gitlab/gitlab-production-tunnel-pg12/sessions/5266/commands/18587
Post-migration query with plans
Generate test data
ALTER TABLE "issuable_slas" ADD "label_applied" boolean DEFAULT FALSE NOT NULL
ALTER TABLE "issuable_slas" ADD "issuable_closed" boolean DEFAULT FALSE NOT NULL
exec CREATE INDEX CONCURRENTLY "index_issuable_slas_on_due_at_id_label_applied_issuable_closed" ON "issuable_slas" ("due_at", "id") WHERE label_applied = FALSE AND issuable_closed = FALSE;
INSERT INTO
issuable_slas (issue_id, due_at, label_applied, issuable_closed)
SELECT
id, NOW() - INTERVAL '60 days' + (random() * (INTERVAL '90 days')), (round(random()) :: int) :: boolean, (round(random()) :: int) :: boolean
FROM
issues
WHERE
id > (
SELECT
id
FROM
issues
ORDER BY
id DESC OFFSET 20000
LIMIT
1
);
Screenshots or Screencasts (strongly suggested)
Does this MR meet the acceptance criteria?
Conformity
-
I have included changelog trailers, or none are needed. (Does this MR need a changelog?) -
I have added/updated documentation, or it's not needed. (Is documentation required?) -
I have properly separated EE content from FOSS, or this MR is FOSS only. (Where should EE code go?) -
I have added information for database reviewers in the MR description, or it's not needed. (Does this MR have database related changes?) -
I have self-reviewed this MR per code review guidelines. -
This MR does not harm performance, or I have asked a reviewer to help assess the performance impact. (Merge request performance guidelines) -
I have followed the style guides. -
This change is backwards compatible across updates, or this does not apply.
Availability and Testing
-
I have added/updated tests following the Testing Guide, or it's not needed. (Consider all test levels. See the Test Planning Process.) -
I have tested this MR in all supported browsers, or it's not needed. -
I have informed the Infrastructure department of a default or new setting change per definition of done, or it's not needed.
Security
Does this MR contain changes to processing or storing of credentials or tokens, authorization and authentication methods or other items described in the security review guidelines? If not, then delete this Security section.
-
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 #335008 (closed)
Edited by Sean Arnold