Skip to content

Commit

Permalink
Add important version of round-robin escalation step
Browse files Browse the repository at this point in the history
  • Loading branch information
Ferril committed Jan 20, 2025
1 parent 2a87bea commit 2ced4b5
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ def execute(self, alert_group: "AlertGroup", reason: str) -> StepExecutionResult
EscalationPolicy.STEP_NOTIFY_SCHEDULE_IMPORTANT: self._escalation_step_notify_on_call_schedule,
EscalationPolicy.STEP_TRIGGER_CUSTOM_WEBHOOK: self._escalation_step_trigger_custom_webhook,
EscalationPolicy.STEP_NOTIFY_USERS_QUEUE: self._escalation_step_notify_users_queue,
EscalationPolicy.STEP_NOTIFY_USERS_QUEUE_IMPORTANT: self._escalation_step_notify_users_queue,
EscalationPolicy.STEP_NOTIFY_IF_TIME: self._escalation_step_notify_if_time,
EscalationPolicy.STEP_NOTIFY_IF_NUM_ALERTS_IN_TIME_WINDOW: self._escalation_step_notify_if_num_alerts_in_time_window,
EscalationPolicy.STEP_NOTIFY_MULTIPLE_USERS: self._escalation_step_notify_multiple_users,
Expand Down Expand Up @@ -199,6 +200,7 @@ def _escalation_step_notify_users_queue(self, alert_group: "AlertGroup", reason:
),
{
"reason": reason,
"important": self.step == EscalationPolicy.STEP_NOTIFY_USERS_QUEUE_IMPORTANT,
},
immutable=True,
)
Expand Down
12 changes: 10 additions & 2 deletions engine/apps/alerts/incident_log_builder/incident_log_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ def _get_log_records_for_after_resolve_report(self) -> "RelatedManager['AlertGro
EscalationPolicy.STEP_NOTIFY,
EscalationPolicy.STEP_NOTIFY_IMPORTANT,
EscalationPolicy.STEP_NOTIFY_USERS_QUEUE,
EscalationPolicy.STEP_NOTIFY_USERS_QUEUE_IMPORTANT,
]

# exclude logs that we don't want to see in after resolve report
Expand Down Expand Up @@ -466,14 +467,18 @@ def _render_escalation_step_plan_from_escalation_policy_snapshot(
EscalationPolicy.STEP_NOTIFY_MULTIPLE_USERS,
EscalationPolicy.STEP_NOTIFY_MULTIPLE_USERS_IMPORTANT,
EscalationPolicy.STEP_NOTIFY_USERS_QUEUE,
EscalationPolicy.STEP_NOTIFY_USERS_QUEUE_IMPORTANT,
]:
users_to_notify: UsersToNotify = escalation_policy_snapshot.sorted_users_queue

if future_step:
if users_to_notify:
plan_line = f'escalation step "{escalation_policy_snapshot.step_display}"'

if escalation_policy_snapshot.step == EscalationPolicy.STEP_NOTIFY_USERS_QUEUE:
if escalation_policy_snapshot.step in (
EscalationPolicy.STEP_NOTIFY_USERS_QUEUE,
EscalationPolicy.STEP_NOTIFY_USERS_QUEUE_IMPORTANT,
):
try:
last_user_index = users_to_notify.index(escalation_policy_snapshot.last_notified_user)
except ValueError:
Expand All @@ -489,7 +494,10 @@ def _render_escalation_step_plan_from_escalation_policy_snapshot(

escalation_plan.setdefault(timedelta, []).append({"plan_lines": [plan_line]})

elif escalation_policy_snapshot.step == EscalationPolicy.STEP_NOTIFY_USERS_QUEUE:
elif escalation_policy_snapshot.step in (
EscalationPolicy.STEP_NOTIFY_USERS_QUEUE,
EscalationPolicy.STEP_NOTIFY_USERS_QUEUE_IMPORTANT,
):
last_notified_user = escalation_policy_snapshot.last_notified_user
users_to_notify = [last_notified_user] if last_notified_user else []

Expand Down
15 changes: 12 additions & 3 deletions engine/apps/alerts/models/escalation_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ class EscalationPolicy(OrderedModel):
STEP_NOTIFY_TEAM_MEMBERS,
STEP_NOTIFY_TEAM_MEMBERS_IMPORTANT,
STEP_DECLARE_INCIDENT,
) = range(20)
STEP_NOTIFY_USERS_QUEUE_IMPORTANT,
) = range(21)

# Must be the same order as previous
STEP_CHOICES = (
Expand All @@ -72,6 +73,7 @@ class EscalationPolicy(OrderedModel):
(STEP_NOTIFY_TEAM_MEMBERS, "Notify all users in a Team"),
(STEP_NOTIFY_TEAM_MEMBERS_IMPORTANT, "Notify all users in a Team (Important)"),
(STEP_DECLARE_INCIDENT, "Declare Incident"),
(STEP_NOTIFY_USERS_QUEUE_IMPORTANT, "Notify User (next each time) (Important)"),
)

# Ordered step choices available for internal api.
Expand Down Expand Up @@ -114,6 +116,7 @@ class EscalationPolicy(OrderedModel):
STEP_TRIGGER_CUSTOM_WEBHOOK,
STEP_REPEAT_ESCALATION_N_TIMES,
STEP_DECLARE_INCIDENT,
STEP_NOTIFY_USERS_QUEUE_IMPORTANT,
]

# Maps internal api's steps choices to their verbal. First string in tuple is display name for existent step.
Expand Down Expand Up @@ -142,7 +145,10 @@ class EscalationPolicy(OrderedModel):
),
# Other
STEP_TRIGGER_CUSTOM_WEBHOOK: ("Trigger webhook {{custom_webhook}}", "Trigger webhook"),
STEP_NOTIFY_USERS_QUEUE: ("Round robin notification for {{users}}", "Notify users one by one (round-robin)"),
STEP_NOTIFY_USERS_QUEUE: (
"Round robin {{importance}} notification for {{users}}",
"Notify users one by one (round-robin)",
),
STEP_NOTIFY_IF_TIME: (
"Continue escalation if current UTC time is in {{timerange}}",
"Continue escalation if current UTC time is in range",
Expand All @@ -166,7 +172,6 @@ class EscalationPolicy(OrderedModel):
STEP_FINAL_NOTIFYALL,
STEP_FINAL_RESOLVE,
STEP_TRIGGER_CUSTOM_WEBHOOK,
STEP_NOTIFY_USERS_QUEUE,
STEP_NOTIFY_IF_TIME,
STEP_REPEAT_ESCALATION_N_TIMES,
STEP_DECLARE_INCIDENT,
Expand All @@ -177,12 +182,14 @@ class EscalationPolicy(OrderedModel):
STEP_NOTIFY_SCHEDULE: STEP_NOTIFY_SCHEDULE_IMPORTANT,
STEP_NOTIFY_MULTIPLE_USERS: STEP_NOTIFY_MULTIPLE_USERS_IMPORTANT,
STEP_NOTIFY_TEAM_MEMBERS: STEP_NOTIFY_TEAM_MEMBERS_IMPORTANT,
STEP_NOTIFY_USERS_QUEUE: STEP_NOTIFY_USERS_QUEUE_IMPORTANT,
}
IMPORTANT_TO_DEFAULT_STEP_MAPPING = {
STEP_NOTIFY_GROUP_IMPORTANT: STEP_NOTIFY_GROUP,
STEP_NOTIFY_SCHEDULE_IMPORTANT: STEP_NOTIFY_SCHEDULE,
STEP_NOTIFY_MULTIPLE_USERS_IMPORTANT: STEP_NOTIFY_MULTIPLE_USERS,
STEP_NOTIFY_TEAM_MEMBERS_IMPORTANT: STEP_NOTIFY_TEAM_MEMBERS,
STEP_NOTIFY_USERS_QUEUE_IMPORTANT: STEP_NOTIFY_USERS_QUEUE,
}

# Default steps are just usual version of important steps. E.g. notify group - notify group important
Expand All @@ -191,13 +198,15 @@ class EscalationPolicy(OrderedModel):
STEP_NOTIFY_SCHEDULE,
STEP_NOTIFY_MULTIPLE_USERS,
STEP_NOTIFY_TEAM_MEMBERS,
STEP_NOTIFY_USERS_QUEUE,
}

IMPORTANT_STEPS_SET = {
STEP_NOTIFY_GROUP_IMPORTANT,
STEP_NOTIFY_SCHEDULE_IMPORTANT,
STEP_NOTIFY_MULTIPLE_USERS_IMPORTANT,
STEP_NOTIFY_TEAM_MEMBERS_IMPORTANT,
STEP_NOTIFY_USERS_QUEUE_IMPORTANT,
}

SLACK_INTEGRATION_REQUIRED_STEPS = [
Expand Down
7 changes: 6 additions & 1 deletion engine/apps/public_api/serializers/escalation_policies.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,10 @@ def _get_field_to_represent(self, step, result):
EscalationPolicy.STEP_NOTIFY_TEAM_MEMBERS_IMPORTANT,
]:
fields_to_remove.remove("team_to_notify")
elif step == EscalationPolicy.STEP_NOTIFY_USERS_QUEUE:
elif step in [
EscalationPolicy.STEP_NOTIFY_USERS_QUEUE,
EscalationPolicy.STEP_NOTIFY_USERS_QUEUE_IMPORTANT,
]:
fields_to_remove.remove("persons_to_notify_next_each_time")
elif step in [EscalationPolicy.STEP_NOTIFY_GROUP, EscalationPolicy.STEP_NOTIFY_GROUP_IMPORTANT]:
fields_to_remove.remove("group_to_notify")
Expand Down Expand Up @@ -243,6 +246,7 @@ def _correct_validated_data(self, validated_data):
validated_data_fields_to_remove.remove("wait_delay")
elif step in [
EscalationPolicy.STEP_NOTIFY_USERS_QUEUE,
EscalationPolicy.STEP_NOTIFY_USERS_QUEUE_IMPORTANT,
EscalationPolicy.STEP_NOTIFY_MULTIPLE_USERS,
EscalationPolicy.STEP_NOTIFY_MULTIPLE_USERS_IMPORTANT,
]:
Expand Down Expand Up @@ -298,6 +302,7 @@ def update(self, instance, validated_data):
instance.wait_delay = None
if step not in [
EscalationPolicy.STEP_NOTIFY_USERS_QUEUE,
EscalationPolicy.STEP_NOTIFY_USERS_QUEUE_IMPORTANT,
EscalationPolicy.STEP_NOTIFY_MULTIPLE_USERS,
EscalationPolicy.STEP_NOTIFY_MULTIPLE_USERS_IMPORTANT,
]:
Expand Down

0 comments on commit 2ced4b5

Please sign in to comment.