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

Silent incident #142

Closed
wants to merge 15 commits into from
Closed
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
1 change: 1 addition & 0 deletions docs/CONFIGURING-SLACK.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
- usergroups:read
- users:read
- users:read.email
- groups:write
```

## Slash Commands
Expand Down
1 change: 1 addition & 0 deletions internal/bot/dialog_submission.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,5 @@ type Submission struct {
PostMortemMeeting string `json:"post_mortem_meeting"`
PauseNotifyTime string `json:"pause_notify_time"`
PauseNotifyReason string `json:"pause_notify_reason"`
SilentIncident string `json:"silent_incident"`
}
2 changes: 1 addition & 1 deletion internal/commands/cancel.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func CancelIncidentByDialog(
return err
}

if notifyOnCancel {
if notifyOnCancel && inc.ChannelType == model.TypePublic {
err := postAndPinMessage(
client,
productChannelID,
Expand Down
3 changes: 2 additions & 1 deletion internal/commands/close.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ func CloseIncidentByDialog(ctx context.Context, client bot.Client, logger log.Lo
var waitgroup sync.WaitGroup
defer waitgroup.Wait()

if notifyOnClose {
if notifyOnClose && inc.ChannelType == model.TypePublic {
concurrence.WithWaitGroup(&waitgroup, func() {
postAndPinMessage(
client,
Expand All @@ -253,6 +253,7 @@ func CloseIncidentByDialog(ctx context.Context, client bot.Client, logger log.Lo
message,
channelAttachment,
)

err = client.ArchiveConversationContext(ctx, channelID)
if err != nil {
logger.Error(
Expand Down
64 changes: 60 additions & 4 deletions internal/commands/open.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,29 @@ func OpenStartIncidentDialog(client bot.Client, triggerID string) error {
MaxLength: 500,
}

silentIncident := &slack.DialogInputSelect{
DialogInput: slack.DialogInput{
Label: "This is a silent incident?",
Name: "silent_incident",
Type: "select",
Placeholder: "Silent Incident",
Optional: false,
},
Value: "false",
Options: []slack.DialogSelectOption{
{
Label: "Yes",
Value: "true",
},
{
Label: "No",
Value: "false",
},
},
OptionGroups: []slack.DialogOptionGroup{},
Hint: "A silent incident is characterized by having a private channel and not notifying the main channel of incident when it opens.",
}

dialog := slack.Dialog{
CallbackID: "inc-open",
Title: "Start an Incident",
Expand All @@ -136,6 +159,7 @@ func OpenStartIncidentDialog(client bot.Client, triggerID string) error {
product,
commander,
description,
silentIncident,
},
}

Expand Down Expand Up @@ -168,6 +192,7 @@ func StartIncidentByDialog(
product = submission.Product
commander = submission.IncidentCommander
description = submission.IncidentDescription
silentIncident = submission.SilentIncident
environment = config.Env.Environment
matrixURL = config.Env.MatrixHost
supportTeam = config.Env.SupportTeam
Expand All @@ -180,7 +205,17 @@ func StartIncidentByDialog(
return fmt.Errorf("commands.StartIncidentByDialog.get_slack_user_info: incident=%v commanderId=%v error=%v", channelName, commander, err)
}

channel, err := client.CreateConversationContext(ctx, channelName, false)
hasSilentIncident, err := strconv.ParseBool(silentIncident)
if err != nil {
logger.Error(
ctx,
log.Trace(),
log.Reason("strconv.ParseBool"),
log.NewValue("error", err),
)
}

channel, err := client.CreateConversationContext(ctx, channelName, hasSilentIncident)
if err != nil {
return fmt.Errorf("commands.StartIncidentByDialog.create_conversation_context: incident=%v error=%v", channelName, err)
}
Expand All @@ -202,6 +237,11 @@ func StartIncidentByDialog(
IncidentAuthor: incidentAuthor,
CommanderId: user.SlackID,
CommanderEmail: user.Email,
ChannelType: model.TypePublic,
}

if hasSilentIncident {
incident.ChannelType = model.TypePrivate
}

incidentID, err := repository.InsertIncident(ctx, &incident)
Expand All @@ -226,9 +266,25 @@ func StartIncidentByDialog(
concurrence.WithWaitGroup(&waitgroup, func() {
postAndPinMessage(client, channel.ID, message, attachment)
})
concurrence.WithWaitGroup(&waitgroup, func() {
postAndPinMessage(client, productChannelID, message, attachment)
})

if incident.ChannelType == model.TypePublic {
concurrence.WithWaitGroup(&waitgroup, func() {
postAndPinMessage(client, productChannelID, message, attachment)
})

_, warning, metaWarning, err := client.JoinConversationContext(ctx, channel.ID)
if err != nil {
logger.Error(
ctx,
log.Trace(),
log.Reason("JoinConversationContext"),
log.NewValue("warning", warning),
log.NewValue("meta_warning", metaWarning),
log.NewValue("error", err),
)
return err
}
}

//We need run that without wait because the modal need close in only 3s
go createPostMortemAndUpdateTopic(ctx, logger, client, fileStorage, incident, incidentID, repository, channel, warRoomURL)
Expand Down
3 changes: 3 additions & 0 deletions internal/commands/open_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ func TestStartIncidentByDialog(t *testing.T) {
Product: "A",
IncidentCommander: "UYGFQB9C0",
IncidentDescription: "Incident Resolved!",
SilentIncident: "false",
},
},
},
Expand All @@ -101,6 +102,7 @@ func TestStartIncidentByDialog(t *testing.T) {
Product: "",
IncidentCommander: "",
IncidentDescription: "",
SilentIncident: "false",
},
},
},
Expand All @@ -118,6 +120,7 @@ func TestStartIncidentByDialog(t *testing.T) {
Product: "",
IncidentCommander: "",
IncidentDescription: "",
SilentIncident: "false",
},
},
},
Expand Down
3 changes: 2 additions & 1 deletion internal/commands/resolve.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func ResolveIncidentByDialog(
channelAttachment,
)
})
if notifyOnResolve {
if notifyOnResolve && inc.ChannelType == model.TypePublic {
concurrence.WithWaitGroup(&waitgroup, func() {
postAndPinMessage(
client,
Expand All @@ -190,6 +190,7 @@ func ResolveIncidentByDialog(
)
})
}

postMessage(client, userID, "", privateAttachment)

return nil
Expand Down
3 changes: 3 additions & 0 deletions internal/model/incident.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ const (
StatusCancel = "canceled"
StatusResolved = "resolved"
StatusClosed = "closed"
TypePrivate = "private"
TypePublic = "public"
)

type Incident struct {
Expand Down Expand Up @@ -38,4 +40,5 @@ type Incident struct {
IncidentAuthor string `db:"incident_author_id,omitempty"`
CommanderId string `db:"commander_id,omitempty"`
CommanderEmail string `db:"commander_email,omitempty"`
ChannelType string `db:"channel_type,omitempty"`
}
17 changes: 12 additions & 5 deletions internal/model/sql/postgres/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func incidentLogValues(inc *model.Incident) []log.Value {
log.NewValue("channelID", inc.ChannelId),
log.NewValue("commanderID", inc.CommanderId),
log.NewValue("commanderEmail", inc.CommanderEmail),
log.NewValue("channelType", inc.ChannelType),
}
}

Expand Down Expand Up @@ -78,8 +79,9 @@ func (r *repository) InsertIncident(ctx context.Context, inc *model.Incident) (i
, channel_name
, channel_id
, commander_id
, commander_email)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20)
, commander_email
, channel_type )
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21)
RETURNING id`

id := int64(0)
Expand All @@ -105,7 +107,8 @@ func (r *repository) InsertIncident(ctx context.Context, inc *model.Incident) (i
inc.ChannelName,
inc.ChannelId,
inc.CommanderId,
inc.CommanderEmail)
inc.CommanderEmail,
inc.ChannelType)

switch err := idResult.Scan(&id); err {
case nil:
Expand Down Expand Up @@ -224,6 +227,7 @@ func (r *repository) GetIncident(ctx context.Context, channelID string) (inc mod
&inc.ChannelId,
&inc.CommanderId,
&inc.CommanderEmail,
&inc.ChannelType,
)

r.logger.Info(
Expand All @@ -244,8 +248,8 @@ func GetIncidentByChannelID() string {
, start_ts
, end_ts
, identification_ts
, snoozed_until
, responsibility
, snoozed_until
, responsibility
, functionality
, root_cause
, customer_impact
Expand All @@ -258,6 +262,7 @@ func GetIncidentByChannelID() string {
, CASE WHEN channel_id IS NULL THEN '' ELSE channel_id END AS channel_id
, CASE WHEN commander_id IS NULL THEN '' ELSE commander_id END commander_id
, CASE WHEN commander_email IS NULL THEN '' ELSE commander_email END commander_email
, channel_type
FROM incident
WHERE channel_id = $1
LIMIT 1`
Expand Down Expand Up @@ -553,6 +558,7 @@ func (r *repository) ListActiveIncidents(ctx context.Context) ([]model.Incident,
GetIncidentStatusFilterQuery(),
model.StatusOpen,
model.StatusResolved,
model.TypePrivate,
)
if err != nil {
r.logger.Error(
Expand Down Expand Up @@ -641,6 +647,7 @@ func GetIncidentStatusFilterQuery() string {
, CASE WHEN commander_email IS NULL THEN '' ELSE commander_email END commander_email
FROM incident
WHERE status IN ($1, $2)
AND channel_type <> ($3)
GLOFonseca marked this conversation as resolved.
Show resolved Hide resolved
LIMIT 100`
}

Expand Down
1 change: 1 addition & 0 deletions internal/model/sql/postgres/schema/hellper.sql
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ CREATE TABLE public.incident (
channel_id varchar(50) NULL,
commander_id text NULL,
commander_email text NULL,
channel_type varchar(50) NULL,
CONSTRAINT firstkey PRIMARY KEY (id)
);

Expand Down