Skip to content

Draft: Add policy_id and escalations_started_at to Alert

What does this MR do and why?

Describe in detail what your merge request does and why.

This adds a foreign key to IncidentManagement::EscalationPolicy (under policy_id), and a escalations_started_at field to track Escalation data on alert.

This will be used when we need a history of which Escalation Policy was used to escalate an alert, and when the escalations started. An example is !75176 (merged), where we need this data to copy over to an Incident Escalation Status.

DB Changes

Column name Type Nullable Index
policy_id Int (Foreign key) true CREATE INDEX index_im_alert_management_alerts_on_policy_id ON alert_management_alerts USING btree (policy_id);
escalations_started_at Datetime true -

Migrations

Up
 rake db:migrate:up VERSION=20211130001348
== 20211130001348 AddPolicyIdEscalationsStartedAtToAlert: migrating ===========
-- add_column(:alert_management_alerts, :policy_id, :integer)
   -> 0.0019s
-- transaction_open?()
   -> 0.0000s
-- index_exists?(:alert_management_alerts, :policy_id, {:name=>"index_im_alert_management_alerts_on_policy_id", :algorithm=>:concurrently})
   -> 0.0066s
-- execute("SET statement_timeout TO 0")
   -> 0.0007s
-- add_index(:alert_management_alerts, :policy_id, {:name=>"index_im_alert_management_alerts_on_policy_id", :algorithm=>:concurrently})
   -> 0.0046s
-- execute("RESET statement_timeout")
   -> 0.0007s
-- transaction_open?()
   -> 0.0000s
-- foreign_keys(:alert_management_alerts)
   -> 0.0044s
-- transaction_open?()
   -> 0.0000s
-- execute("ALTER TABLE alert_management_alerts\nADD CONSTRAINT fk_1e65f09ee5\nFOREIGN KEY (policy_id)\nREFERENCES incident_management_escalation_policies (id)\nON DELETE SET NULL\nNOT VALID;\n")
   -> 0.0044s
-- execute("ALTER TABLE alert_management_alerts VALIDATE CONSTRAINT fk_1e65f09ee5;")
   -> 0.0075s
-- add_column(:alert_management_alerts, :escalations_started_at, :datetime_with_timezone)
   -> 0.0011s
== 20211130001348 AddPolicyIdEscalationsStartedAtToAlert: migrated (0.0514s) ==
Down
rake db:migrate:down VERSION=20211130001348
== 20211130001348 AddPolicyIdEscalationsStartedAtToAlert: reverting ===========
-- remove_column(:alert_management_alerts, :policy_id)
   -> 0.0126s
-- remove_column(:alert_management_alerts, :escalations_started_at)
   -> 0.0009s
== 20211130001348 AddPolicyIdEscalationsStartedAtToAlert: reverted (0.0137s) ==

Screenshots or screen recordings

These are strongly recommended to assist reviewers and reduce the time to merge your change.

How to set up and validate locally

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

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 #346614 (closed)

Edited by Sean Arnold

Merge request reports