Skip to content

Prevent errors for conflicting pending escalations

Sarah Yasonik requested to merge 372194-sy-fix-uncaught-escalation-error into master

What does this MR do and why?

  • Resolves uncaught Rule has already been taken error when an escalatable is queued for escalation multiple times.
  • Makes the {Alert/Issue}CreateWorkers actually idempotent.

How to set up and validate locally

  1. Open a project for which you have maintainer permissions (ids needed for command below)
  2. Create an escalation policy (project > Monitor > Escalation Policies) with multiple rules:
    1. One rule should fire after 0 minutes
    2. Another rule should fire after 5+ minutes
      Screen_Shot_2022-10-21_at_7.25.19_PM
  3. Create an incident & trigger escalations
    user = User.first # your user
    project = Project.find(21) # your project
    incident = IncidentManagement::Incidents::CreateService.new(project, user, title: 'incident title', description: 'description').execute[:issue]
    IncidentManagement::PendingEscalations::CreateService.new(incident.escalation_status).execute
    # => Should return an array of strings with as many elements as escalation rules you configured; escalations were created!
  4. Before the 2nd escalation rule fires, queue escalations again
    IncidentManagement::PendingEscalations::CreateService.new(incident.escalation_status).execute
    # => Should return nil; escalations should not be created

BEFORE

If you ran the above code on master, the last step would result in an error:

IncidentManagement::PendingEscalations::CreateService.new(incident.escalation_status).execute
# => ActiveRecord::RecordInvalid: Validation failed: Rule has already been taken

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

Edited by Sarah Yasonik

Merge request reports

Loading