-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[RAM] Add data model for scheduled and recurring snoozes #131019
Conversation
…-datamodel # Conflicts: # x-pack/plugins/alerting/server/saved_objects/migrations.ts # x-pack/plugins/alerting/server/task_runner/task_runner.ts
…cqary/kibana into 130724-snooze-sched-datamodel
…-datamodel # Conflicts: # x-pack/plugins/alerting/server/saved_objects/mappings.json
…-datamodel # Conflicts: # package.json # yarn.lock
…-datamodel # Conflicts: # x-pack/plugins/alerting/server/lib/index.ts # x-pack/plugins/alerting/server/routes/find_rules.ts # x-pack/plugins/alerting/server/rules_client/rules_client.ts
Updated the description with this but reposting here: To aid in filtering, |
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.
Added some comments. It feels like we have too many combinations of properties that can be used to define "mute all forever", "mute all with a duration", and the eventual rRule-based snoozes. Wondering if we can boil this down to a simpler set of properties, where we ALWAYS have an rRule in place.
I could totally believe we can't! I just need to be convinced.
And I think we need a bit of doc in the rule_snooze_type module describing these properties, as well as some doc in the PR describing all the combinations of things that can happen today, with an hint of how we plan on dealing with rRule schedules in the future.
@@ -2817,3 +2860,9 @@ function parseDate(dateString: string | undefined, propertyName: string, default | |||
|
|||
return parsedDate; | |||
} | |||
|
|||
function clearUnscheduledSnooze(attributes: { snoozeSchedule?: RuleSnooze }) { |
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.
Not completely clear what this function is doing, but I think it's removing "mute all" snoozes that have a duration.
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.
Not exactly. This clears any "simple" snoozes, i.e. the user selects "Snooze for 3 days (starting now)" in the currently-existing UX, instead of e.g. "Snooze on Friday for 3 days" or "Snooze every Friday for 3 days" as made possible by the new functionality. It's the functional equivalent of setting snoozeEndTime: null
in the previous version of the data model.
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.
Ah ... somehow we need to get all this documented, at least for ourselves. Doesn't need to be this PR though, in the spirit of time. I added a request to add doc to #132266 ...
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.
LGTM; noted some things for follow ups - more doc (somewhere) and more robust parsing for the wacky day-of-week with optional numeric suffix thing (probably could be made into a grep pattern).
@@ -2817,3 +2860,9 @@ function parseDate(dateString: string | undefined, propertyName: string, default | |||
|
|||
return parsedDate; | |||
} | |||
|
|||
function clearUnscheduledSnooze(attributes: { snoozeSchedule?: RuleSnooze }) { |
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.
Ah ... somehow we need to get all this documented, at least for ourselves. Doesn't need to be this PR though, in the spirit of time. I added a request to add doc to #132266 ...
function parseByWeekday(byweekday: Array<string | number>): ByWeekday[] { | ||
return byweekday.map((w) => { | ||
if (typeof w === 'number') return w; | ||
if (['SU', 'MO', 'TU', 'WE', 'TH', 'FR', 'SA'].includes(w)) return w as WeekdayStr; |
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.
nit: you could create a const
Set for these strings at the top-level, and then just use WeekdaySet.has(w)
return byweekday.map((w) => { | ||
if (typeof w === 'number') return w; | ||
if (['SU', 'MO', 'TU', 'WE', 'TH', 'FR', 'SA'].includes(w)) return w as WeekdayStr; | ||
const dayOfWeek = w.slice(-2) as WeekdayStr; |
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.
Feels like we may need a more robust parser for these BYDAY
values - I had to look it up to make sure I was understanding this code :-). Who proposed using this wacky format!!! :-). https://icalendar.org/iCalendar-RFC-5545/3-3-10-recurrence-rule.html
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.
Yeah unfortunately the rrule
library will parse an entire rrule string, but not just a segment of it, so we can't rely on its already robust parsing of BYDAY
. I added a comment though.
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.
Not that we need to do it for this PR, but could we construct a legal but fake rRule with the BYDAY value, then send it to the rRule parser to just extract the relevant fields?
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.
Oh wait actually yeah that does work
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.
No, may have spoken too soon, the parsed RRule
object only seems to return its byweekday
in the form of an array of numbers, and I'm not sure how to extract an nth day of week from it. Still playing with it though
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.
Oops nevermind had to use origOptions
, this works fine
…-ref HEAD~1..HEAD --fix'
💚 Build SucceededMetrics [docs]Module Count
Public APIs missing comments
Async chunks
Page load bundle
Saved Objects .kibana field count
History
To update your PR or re-run it, just comment with: |
Summary
Closes #130724
Migrates the data model for rules from
/muteAll
snoozeEndTime
to/snoozeIndefinitely
snoozeSchedule
.(Removed this as it's too large of a code change;snoozeIndefinitely
is a straight rename ofmuteAll
and functions the same way.muteAll
is used in a ton of places)snoozeSchedule
is an array of scheduled snooze times, including options for recurring on a time interval or certain days of the week. Recurrence is formatted in the form of an iCal RRULE, and this PR adds the rrule package to parse these. Also adds luxon which is its required peer dependency for dealing with time zones.This just changes the data model and the task manager's parsing of it. APIs and UIs remain broadly unchanged for now.
The only change to the APIs and UIs are the addition of an
is_snoozed_until
property in the API response. This property is identical to the previously existingsnooze_end_time
, but it gets derived on the server side from the snooze schedule using thegetRuleSnoozeEndTime
function. The reason we do this is because making therrule
package available in the frontend balloons thealerting
plugin size, so all RRULE parsing needs to happen on the server. This may not last, as we're eventually going to need to generate RRULE strings from the snooze UI, but I don't want to include the decision to increase the alerting bundle size in this PR.UPDATE 5/12: To aid in filtering,
isSnoozedUntil
will now be stored in the SavedObject. This property is computed and added to the SavedObject either when the_snooze
API is called (for snoozes that start as soon as they're added), OR when the task runner attempts to execute the rule (for recurring snoozes). As far as the task runner is concerned, the actual snooze source of truth will always be thesnoozeSchedule
.isSnoozedUntil
will purely be for display and sorting.UPDATE 5/16: Closes #132164 and uses
rRule
even for simple snoozes. When the user clicks "Snooze for 3 days" this will now set a snooze with anrRule
of{ dtstart: NOW, count: 1 }
Checklist