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

Batch access list review reminders and provide link (slack) #43782

Merged
merged 4 commits into from
Jul 10, 2024

Conversation

kimlisa
Copy link
Contributor

@kimlisa kimlisa commented Jul 3, 2024

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:

image

If a recipient has only one review due, it keeps the previous messaging, including a link out to the specific access list:

image

changelog: For slack integration, Access List reminders are batched into 1 message and provides link out to the web UI.

@@ -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
Copy link
Contributor

@smallinsky smallinsky Jul 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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

Copy link
Contributor Author

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

Copy link
Contributor

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

Comment on lines 32 to 34
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
Copy link
Contributor

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) ?

Comment on lines 153 to 154
remindersLookup := make(map[string][]*accesslist.AccessList)
recipientLookup := make(map[string]common.Recipient)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not

Suggested change
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

Copy link
Contributor Author

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return recipients, err
return recipients, nil

@kimlisa kimlisa force-pushed the lisa/batch-access-list-review-reminder branch 2 times, most recently from f72c524 to 667a6b6 Compare July 6, 2024 04:29
@kimlisa kimlisa requested a review from smallinsky July 6, 2024 04:53
@kimlisa kimlisa force-pushed the lisa/batch-access-list-review-reminder branch from 667a6b6 to 00ae5a0 Compare July 6, 2024 04:55
Comment on lines 180 to 183
if _, ok := remindersLookup[recipient]; !ok {
remindersLookup[recipient] = []*accesslist.AccessList{}
}
remindersLookup[recipient] = append(remindersLookup[recipient], accessList)
Copy link
Contributor

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 👍

Suggested change
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")
Copy link
Contributor

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 {
Copy link
Contributor

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.

Suggested change
if err != nil {
if len(errs) > 0 {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agh thanks!!!

@public-teleport-github-review-bot public-teleport-github-review-bot bot removed the request for review from tigrato July 9, 2024 07:16
@kimlisa kimlisa added this pull request to the merge queue Jul 10, 2024
@kimlisa kimlisa removed this pull request from the merge queue due to a manual request Jul 10, 2024
@kimlisa kimlisa added this pull request to the merge queue Jul 10, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jul 10, 2024
@kimlisa kimlisa added this pull request to the merge queue Jul 10, 2024
Merged via the queue into master with commit cdc3548 Jul 10, 2024
38 checks passed
@kimlisa kimlisa deleted the lisa/batch-access-list-review-reminder branch July 10, 2024 19:14
@public-teleport-github-review-bot

@kimlisa See the table below for backport results.

Branch Result
branch/v15 Create PR
branch/v16 Create PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants