Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add next oncall incident commander as observer #4100

Merged
merged 7 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"""Adds the engage_next_oncall column to the incident_role table.

Revision ID: 2f06fd73eae6
Revises: 580a18ec4c39
Create Date: 2023-12-08 11:22:15.565073

"""
from alembic import op
import sqlalchemy as sa

# revision identifiers, used by Alembic.
revision = "2f06fd73eae6"
down_revision = "580a18ec4c39"
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column("incident_role", sa.Column("engage_next_oncall", sa.Boolean(), nullable=True))
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column("incident_role", "engage_next_oncall")
# ### end Alembic commands ###
19 changes: 19 additions & 0 deletions src/dispatch/incident/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,25 @@ def create(*, db_session, incident_in: IncidentCreate) -> Incident:
role=ParticipantRoleType.scribe,
)

# add observer (if engage_next_oncall is enabled)
incident_role = resolve_role(db_session=db_session, role=ParticipantRoleType.incident_commander, incident=incident)
if incident_role and incident_role.engage_next_oncall:
oncall_plugin = plugin_service.get_active_instance(
db_session=db_session, project_id=incident.project.id, plugin_type="oncall"
)
if not oncall_plugin:
log.debug("Resolved observer role not available since oncall plugin is not active.")
else:
oncall_email = oncall_plugin.instance.get_next_oncall(service_id=incident_role.service.external_id)
if oncall_email:
participant_flows.add_participant(
oncall_email,
incident,
db_session,
service_id=incident_role.service.id,
role=ParticipantRoleType.observer,
)

return incident


Expand Down
3 changes: 3 additions & 0 deletions src/dispatch/incident_role/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ class IncidentRole(Base, TimeStampMixin, ProjectMixin):
individual_id = Column(Integer, ForeignKey("individual_contact.id"))
individual = relationship("IndividualContact")

engage_next_oncall = Column(Boolean, default=False)


# Pydantic models
class IncidentRoleBase(DispatchBase):
Expand All @@ -70,6 +72,7 @@ class IncidentRoleBase(DispatchBase):
incident_priorities: Optional[List[IncidentPriorityRead]]
service: Optional[ServiceRead]
individual: Optional[IndividualContactRead]
engage_next_oncall: Optional[bool]


class IncidentRoleCreateUpdate(IncidentRoleBase):
Expand Down
11 changes: 11 additions & 0 deletions src/dispatch/plugins/dispatch_pagerduty/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
oncall_shift_check,
get_escalation_policy,
get_service,
get_next_oncall,
)


Expand Down Expand Up @@ -114,3 +115,13 @@ def get_schedule_id_from_service_id(self, service_id: str) -> Optional[str]:
except Exception as e:
log.error("Error trying to retrieve schedule_id from service_id")
log.exception(e)

def get_next_oncall(self, service_id: str) -> Optional[str]:
schedule_id = self.get_schedule_id_from_service_id(service_id)

client = APISession(self.configuration.api_key.get_secret_value())
client.url = self.configuration.pagerduty_api_url
return get_next_oncall(
client=client,
schedule_id=schedule_id,
)
10 changes: 10 additions & 0 deletions src/dispatch/plugins/dispatch_pagerduty/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,3 +194,13 @@ def oncall_shift_check(client: APISession, schedule_id: str, hour: int) -> Optio

if previous_oncall["email"] != next_oncall["email"]:
return previous_oncall


def get_next_oncall(client: APISession, schedule_id: str) -> Optional[str]:
"""Retrieves the email of the next oncall person. Assumes 12-hour shifts"""
now = datetime.utcnow()

next_shift = (now + timedelta(hours=13)).isoformat(timespec="minutes") + "Z"
next_oncall = get_oncall_at_time(client=client, schedule_id=schedule_id, utctime=next_shift)

return None if not next_oncall else next_oncall["email"]
6 changes: 6 additions & 0 deletions src/dispatch/static/dispatch/src/case/priority/Table.vue
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,9 @@ export default {
},
}
</script>

<style>
.mdi-school {
color: white !important;
}
</style>
6 changes: 6 additions & 0 deletions src/dispatch/static/dispatch/src/case/severity/Table.vue
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,9 @@ export default {
},
}
</script>

<style>
.mdi-school {
color: white !important;
}
</style>
6 changes: 6 additions & 0 deletions src/dispatch/static/dispatch/src/case/type/Table.vue
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,9 @@ export default {
},
}
</script>

<style>
.mdi-school {
color: white !important;
}
</style>
6 changes: 6 additions & 0 deletions src/dispatch/static/dispatch/src/incident/priority/Table.vue
Original file line number Diff line number Diff line change
Expand Up @@ -195,3 +195,9 @@ export default {
},
}
</script>

<style>
.mdi-school {
color: white !important;
}
</style>
6 changes: 6 additions & 0 deletions src/dispatch/static/dispatch/src/incident/severity/Table.vue
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,9 @@ export default {
},
}
</script>

<style>
.mdi-school {
color: white !important;
}
</style>
6 changes: 6 additions & 0 deletions src/dispatch/static/dispatch/src/incident/type/Table.vue
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,9 @@ export default {
},
}
</script>

<style>
.mdi-school {
color: white !important;
}
</style>
6 changes: 6 additions & 0 deletions src/dispatch/static/dispatch/src/incident_cost_type/Table.vue
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,9 @@ export default {
},
}
</script>

<style>
.mdi-school {
color: white !important;
}
</style>
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,22 @@
</v-list-item>
<v-list-item>
<service-select-new
label="Target Service"
label="Oncall Service"
:project="project"
v-model="policy.service"
/>
</v-list-item>
<v-list-item>
<v-checkbox
v-if="label === 'Incident Commander'"
v-model="policy.engage_next_oncall"
label="Add next on-call as an Observer"
hint="Check this if you would like the next oncall incident commander to be added as an observer."
/>
</v-list-item>
<v-list-item>
<v-checkbox
style="margin-top: -18px"
v-model="policy.enabled"
label="Enabled"
hint="Check this if you would like this policy to be considered when resolving the role."
Expand Down Expand Up @@ -148,6 +157,7 @@ function add() {
role: props.label,
project: props.project,
enabled: false,
engage_next_oncall: false,
service: null,
incident_priorities: [],
incident_types: [],
Expand Down
6 changes: 6 additions & 0 deletions src/dispatch/static/dispatch/src/incident_role/Table.vue
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,9 @@ export default {
},
}
</script>

<style>
.mdi-school {
color: white !important;
}
</style>
6 changes: 6 additions & 0 deletions src/dispatch/static/dispatch/src/search/Table.vue
Original file line number Diff line number Diff line change
Expand Up @@ -196,3 +196,9 @@ export default {
},
}
</script>

<style>
.mdi-school {
color: white !important;
}
</style>
6 changes: 6 additions & 0 deletions src/dispatch/static/dispatch/src/signal/Table.vue
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,9 @@ export default {
},
}
</script>

<style>
.mdi-school {
color: white !important;
}
</style>
6 changes: 6 additions & 0 deletions src/dispatch/static/dispatch/src/workflow/Table.vue
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,9 @@ export default {
},
}
</script>

<style>
.mdi-school {
color: white !important;
}
</style>