-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Batch access list review reminders and provide link (slack) #43782
Conversation
@@ -192,12 +225,12 @@ func (a *App) notifyForAccessListReviews(ctx context.Context, accessList *access | |||
// If the current time before the notification start time, skip notifications. | |||
if now.Before(notificationStart) { | |||
log.Debugf("Access list %s is not ready for notifications, notifications start at %s", accessList.GetName(), notificationStart.Format(time.RFC3339)) | |||
return nil | |||
return nil, nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return nil, nil | |
return []common.Recipient,, nil |
I would assume that:
val, err := getRecipientsRequiringReminders
if err != nil {
return err
}
val = append(val, common.Recipient{...})
will not panic
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if i understood you correctly, iterating over a nil slice and spreading a nil slice, doesn't result in panic: https://go.dev/play/p/VbdQF2X6s5f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My bad. I always confusing when I'm seeing return nil, nil
SendReviewReminders(ctx context.Context, recipient common.Recipient, accessList *accesslist.AccessList) error | ||
// SendBatchedReviewReminder will send a batched review reminder. | ||
SendBatchedReviewReminder(ctx context.Context, recipient common.Recipient, accessLists []*accesslist.AccessList) error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it make sens to reduce interface and instead of having 2 methods
have only one:
SendReviewReminders(ctx context.Context, recipient common.Recipient, accessLists []*accesslist.AccessList) error
and distinguish the flow internally depending on len(accessLists) ?
remindersLookup := make(map[string][]*accesslist.AccessList) | ||
recipientLookup := make(map[string]common.Recipient) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not
remindersLookup := make(map[string][]*accesslist.AccessList) | |
recipientLookup := make(map[string]common.Recipient) | |
remindersLookup := make(map[common.Recipient][]*accesslist.AccessList) |
where the recipientLookup
can be removed because remindersLookup already have all necessary information
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's wild... made the change 👍
} | ||
|
||
return trace.Wrap(a.sendMessages(ctx, accessList, allRecipients, now, notificationStart)) | ||
return recipients, err |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return recipients, err | |
return recipients, nil |
f72c524
to
667a6b6
Compare
667a6b6
to
00ae5a0
Compare
if _, ok := remindersLookup[recipient]; !ok { | ||
remindersLookup[recipient] = []*accesslist.AccessList{} | ||
} | ||
remindersLookup[recipient] = append(remindersLookup[recipient], accessList) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
append
will return a new list if the first argument is nil 👍
if _, ok := remindersLookup[recipient]; !ok { | |
remindersLookup[recipient] = []*accesslist.AccessList{} | |
} | |
remindersLookup[recipient] = append(remindersLookup[recipient], accessList) | |
remindersLookup[recipient] = append(remindersLookup[recipient], accessList) |
log.WithError(err).Warn("Error notifying for access list reviews") | ||
recipients, err := a.getRecipientsRequiringReminders(ctx, accessList) | ||
if err != nil { | ||
log.WithError(err).Warn("Error getting recipients to notify for access list reviews") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be helpful to log the access list name?
} | ||
} | ||
|
||
if err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This err
is not relevant to the current operation. I think you meant to check for errs
instead.
if err != nil { | |
if len(errs) > 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agh thanks!!!
part of https://github.com/gravitational/teleport.e/issues/3571
Instead of sending a reminder PER access list review due, it now only sends one (batched or singular) and includes link to the access list page. This required to gather all access list upfront (instead of processing reminders per page), putting it into a lookup map by recipients.
If a recipient has >1 access list reviews due, the messaging is batched, with the earliest due date mentioned, and links out to the access list listing page:
If a recipient has only one review due, it keeps the previous messaging, including a link out to the specific access list:
changelog: For slack integration, Access List reminders are batched into 1 message and provides link out to the web UI.