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

notification: slack status updates #1785

Merged
merged 28 commits into from
Aug 12, 2021
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
dfea350
add originalstatus field to alert status struct
arurao Jul 21, 2021
29d56ec
add field to struct
arurao Jul 21, 2021
e1bb152
add alert status replies in thread in slack
arurao Jul 21, 2021
36ab498
modified rate limiting to include only some types
arurao Jul 21, 2021
5ef54df
adding alert as a field to alertstatus
arurao Jul 22, 2021
6fb9fbb
added fields for summary and details
arurao Jul 22, 2021
5b93440
Merge branch 'master' of https://github.com/target/goalert into slack…
arurao Jul 28, 2021
3d2cbc4
Merge branch 'dont-dedup-sent-messages' of https://github.com/target/…
arurao Jul 28, 2021
c40a2b6
Merge branch 'master' of https://github.com/target/goalert into slack…
arurao Jul 28, 2021
3eeab92
Update notification/alertstatus.go
arurao Jul 28, 2021
0ab2699
updating field as per alert status struct
arurao Jul 28, 2021
3e74c04
return err if couldn't find orig msg,tweak to test
arurao Jul 29, 2021
e6cc988
Update notification/slack/channel.go
arurao Aug 3, 2021
84a0763
rewording and prefixing with current status
arurao Aug 4, 2021
56c9447
Merge branch 'slack-status-updates' of https://github.com/target/goal…
arurao Aug 4, 2021
ad51d0e
added comment
arurao Aug 4, 2021
839cb66
Merge branch 'master' of https://github.com/target/goalert into slack…
arurao Aug 4, 2021
31a23a2
Update notification/slack/channel.go
arurao Aug 4, 2021
0cf103f
new type for status
arurao Aug 5, 2021
51c5023
Merge branch 'slack-status-updates' of https://github.com/target/goal…
arurao Aug 5, 2021
010c1d7
Merge branch 'master' of https://github.com/target/goalert into slack…
arurao Aug 5, 2021
021f262
Merge branch 'ignore-unknown-numbers' of https://github.com/target/go…
arurao Aug 5, 2021
4878af9
use alert.Status in the new field
arurao Aug 5, 2021
db60b52
Merge branch 'master' of https://github.com/target/goalert into slack…
arurao Aug 9, 2021
3e6647a
Merge branch 'master' of https://github.com/target/goalert into slack…
arurao Aug 11, 2021
ddedcb9
mapping statuses in engine
arurao Aug 12, 2021
c14ce83
Merge branch 'master' of https://github.com/target/goalert into slack…
arurao Aug 12, 2021
bf0b8c6
Update notification/alertstatus.go
dctalbot Aug 12, 2021
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
7 changes: 5 additions & 2 deletions engine/message/ratelimit.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ var PerCMThrottle ThrottleConfig
func init() {
var perCM ThrottleConfigBuilder

// all message types
perCM.AddRules([]ThrottleRule{{Count: 1, Per: time.Minute}})
// Rate limit sms, voice and email types
perCM.
WithDestTypes(notification.DestTypeVoice, notification.DestTypeSMS, notification.DestTypeUserEmail).
AddRules([]ThrottleRule{{Count: 1, Per: time.Minute}})

// On-Call Status Notifications
perCM.
Expand All @@ -29,6 +31,7 @@ func init() {
// status notifications
perCM.
WithMsgTypes(notification.MessageTypeAlertStatus).
WithDestTypes(notification.DestTypeVoice, notification.DestTypeSMS, notification.DestTypeUserEmail).
AddRules([]ThrottleRule{
{Count: 1, Per: 3 * time.Minute},
{Count: 3, Per: 20 * time.Minute},
Expand Down
22 changes: 18 additions & 4 deletions engine/sendmessage.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,25 @@ func (p *Engine) sendMessage(ctx context.Context, msg *message.Message) (*notifi
if err != nil {
return nil, errors.Wrap(err, "lookup alert log entry")
}
a, err := p.cfg.AlertStore.FindOne(ctx, msg.AlertID)
if err != nil {
return nil, fmt.Errorf("lookup original alert: %w", err)
}
stat, err := p.cfg.NotificationStore.OriginalMessageStatus(ctx, msg.AlertID, msg.Dest)
if err != nil {
return nil, fmt.Errorf("lookup original message: %w", err)
}
if stat == nil {
return nil, fmt.Errorf("could not find original notification for alert %d to %s", msg.AlertID, msg.Dest.String())
}
notifMsg = notification.AlertStatus{
Dest: msg.Dest,
AlertID: e.AlertID(),
CallbackID: msg.ID,
LogEntry: e.String(),
Dest: msg.Dest,
AlertID: e.AlertID(),
CallbackID: msg.ID,
LogEntry: e.String(),
Summary: a.Summary,
Details: a.Details,
OriginalStatus: *stat,
}
case notification.MessageTypeTest:
notifMsg = notification.Test{
Expand Down
8 changes: 8 additions & 0 deletions notification/alertstatus.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ type AlertStatus struct {
CallbackID string
AlertID int
LogEntry string

// Summary of the alert that this status is in regards to.
Summary string
// Details of the alert that this status is in regards to.
Details string

// OriginalStatus is the status of the first Alert notification to this Dest for this AlertID.
OriginalStatus SendResult
}

var _ Message = &AlertStatus{}
Expand Down
6 changes: 5 additions & 1 deletion notification/slack/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,12 +321,16 @@ func (s *ChannelSender) Send(ctx context.Context, msg notification.Message) (str
if t.OriginalStatus != nil {
// Reply in thread if we already sent a message for this alert.
vals.Set("thread_ts", t.OriginalStatus.ProviderMessageID.ExternalID)
vals.Set("text", "Escalated.")
// only if escalation results in second notification to channel
vals.Set("text", "Notified.")
vals.Set("reply_broadcast", "true")
break
}

vals.Set("text", fmt.Sprintf("Alert: %s\n\n<%s>", t.Summary, cfg.CallbackURL("/alerts/"+strconv.Itoa(t.AlertID))))
case notification.AlertStatus:
vals.Set("thread_ts", t.OriginalStatus.ProviderMessageID.ExternalID)
vals.Set("text", t.LogEntry)
case notification.AlertBundle:
vals.Set("text", fmt.Sprintf("Service '%s' has %d unacknowledged alerts.\n\n<%s>", t.ServiceName, t.Count, cfg.CallbackURL("/services/"+t.ServiceID+"/alerts")))
case notification.ScheduleOnCallUsers:
Expand Down
4 changes: 4 additions & 0 deletions smoketest/statusinprogress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ func TestStatusInProgress(t *testing.T) {
insert into user_last_alert_log (user_id, alert_id, log_id, next_log_id)
values
({{uuid "u1"}}, 1, 102, 103);

insert into outgoing_messages(message_type, user_id, contact_method_id, alert_id, service_id, escalation_policy_id, last_status, sent_at)
values
('alert_notification', {{uuid "u1"}}, {{uuid "c1"}}, 1, {{uuid "sid"}}, {{uuid "eid"}}, 'sent', now());
`

h := harness.NewHarness(t, sql, "sched-module-v3")
Expand Down