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

Change schedule configuration to support new rotations #204

Merged
merged 8 commits into from
Jun 12, 2024

Conversation

julianbrost
Copy link
Collaborator

@julianbrost julianbrost commented May 28, 2024

This is a fundamental and incompatible change to how schedules are defined. Now, a schedule consists of a list of rotations that's ordered by priority. Each rotation contains multiple members where each is either a contact or a contact group. Each member is linked to some timeperiod entries which defines when this member is active in the rotation.

This PR already includes code for a feature that was planned but is not yet possible using the web interface at the moment: multiple versions of the same rotation where the handoff time defines when a given version becomes active.

With this change, for the time being, the TimePeriod type itself fulfills no real purpose and the timeperiod entries are directly loaded as part of the schedule, bypassing the timeperiod loading code. However, there still is the plan to add standalone timeperiods in the future, thus the timeperiod code is kept.

More context for these changes:

The commits in this PR:

Dependencies

To allow testing with Icinga Notifications Web, the following PRs are required there:

Caution

Applying the schema upgrade is destructive to the current schedule configuration and there is no easy way to rollback. Be prepared for this and better create a backup first.

closes #193 (schema change already contained in this PR)

@cla-bot cla-bot bot added the cla/signed CLA is signed by all contributors of a PR label May 28, 2024
@julianbrost
Copy link
Collaborator Author

Force push just updated a comment in rotations.go and rebased. The latter looks a bit confusing in the diff view: I just renamed 025.sql to 026.sql but it shows the differences between the two different and unrelated versions of 025.sql.

Copy link
Member

@oxzi oxzi left a comment

Choose a reason for hiding this comment

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

I have successfully tested the changes together with the mentioned other PRs. Everything seems to work, even when it is sometimes a bit hard to try, especially due to UI limitations.

I would like to see more debugging logs and, as discussed offline the other day, maybe another handler to the Listener showing the computed schedule. This might also get in handy to compare the calculated rotations against web.

return contacts
// GetContactsAt returns the contacts that are active in the schedule at the given time.
func (s *Schedule) GetContactsAt(t time.Time) []*Contact {
return s.rotationResolver.getContactsAt(t)
Copy link
Member

Choose a reason for hiding this comment

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

For debugging reasons, it would be nice to have a logging message when no Contacts are being returned. This might also happen somewhere up the call stack.

internal/config/schedule.go Outdated Show resolved Hide resolved
internal/timeperiod/timeperiod.go Outdated Show resolved Hide resolved
@julianbrost julianbrost marked this pull request as draft June 5, 2024 10:26
@julianbrost
Copy link
Collaborator Author

Most new changes are within the three new additional commits (please see their commit messages and the updated PR description). Changes to to existing commits should only include changes necessary due to the rebase over #114 (changed import, more db:"-" needed) and the removal of the unnecessary explicit access of the embedded SugaredLogger (#204 (comment)).

@julianbrost julianbrost marked this pull request as ready for review June 5, 2024 10:46
@julianbrost julianbrost requested review from oxzi and yhabteab June 5, 2024 10:46
internal/config/schedule.go Outdated Show resolved Hide resolved
internal/config/schedule.go Outdated Show resolved Hide resolved
internal/config/schedule.go Outdated Show resolved Hide resolved
internal/listener/listener.go Outdated Show resolved Hide resolved
julianbrost and others added 7 commits June 5, 2024 15:56
This adds the required fields and tags to timeperiod.Entry so that this struct
can be used directly for querying the database. This removes the previous
inline struct TimeperiodEntry that was present in the config loading code. All
the initialization is now done in the Init() method instead of when copying the
values between the structs.

This is done in preparation for changes to schedules where timeperiod entries
are loaded directly as part of schedules.
This allows to easily log those using zap.Object().
Reduce the schema file to the minimal changes that are needed to go from the
old to the new version. This makes it easier to follow what has been changed
and also allows keeping other timeperiods (if they were manually created as it
was not yet possible to create those outside of schedules using the web
interface so far). Comments were removed from here as they still exist in the
full schema file and the purpose of the upgrade file is not to document the
schema.
This is a fundamental and incompatible change to how schedules are defined.
Now, a schedule consists of a list of rotations that's ordered by priority.
Each rotation contains multiple members where each is either a contact or a
contact group. Each member is linked to some timeperiod entries which defines
when this member is active in the rotation.

This commit already includes code for a feature that was planned but is
possible using the web interface at the moment: multiple versions of the same
rotation where the handoff time defines when a given version becomes active.

With this change, for the time being, the TimePeriod type itself fulfills no
real purpose and the timeperiod entries are directly loaded as part of the
schedule, bypassing the timeperiod loading code. However, there still is the
plan to add standalone timeperiods in the future, thus the timeperiod code is
kept.

More context for these changes:
- Icinga/icinga-notifications-web#177
- #193
Lazily initializing the timeperiod entries comes with problems regarding the
error handling and would also result in race conditions if multiple callers use
the object at the same time. This commit changes this so that Init() has to be
called explicitly first, allowing proper error handling and read-only use of
the object later.
The most relevant case where this is interesting is when a schedule expands to
no contacts at the time of a notification.
Copy link
Member

@yhabteab yhabteab left a comment

Choose a reason for hiding this comment

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

Apart from this small change (see comment below), it looks fine for me and works smoothly.

internal/listener/listener.go Outdated Show resolved Hide resolved
This allows to quickly dump all schedules and how they expand to contacts for
the next two days for debugging/testing purposes.
Copy link
Member

@oxzi oxzi left a comment

Choose a reason for hiding this comment

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

I have tested the changes successfully.

internal/listener/listener.go Show resolved Hide resolved
@julianbrost
Copy link
Collaborator Author

Next step: coordinating merging of all the required PRs, that'll be fun.

@julianbrost julianbrost merged commit 2b3ca42 into main Jun 12, 2024
12 checks passed
@julianbrost julianbrost deleted the schedule-rotations branch June 12, 2024 11:29
nilmerg added a commit to Icinga/icinga-notifications-web that referenced this pull request Jun 12, 2024
@julianbrost
Copy link
Collaborator Author

Next step: coordinating merging of all the required PRs, that'll be fun.

That was surprisingly easy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla/signed CLA is signed by all contributors of a PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants