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

docs(oncall): fix withShifts usage example #23

Merged
merged 3 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
52 changes: 28 additions & 24 deletions docs/oncall.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,28 +227,30 @@ Shifts are unordered, and so are supplied as an object to allow for
reuse. For example, a Primary/Secondary pair of Schedules could be
declared like:

local calendar = grafanaplane.oncall.schedule.calendar,
local onCallUsers = [['[email protected]'], ['[email protected]']],
primary: calendar.new('Primary', [
// 24 hour daily shift
calendar.shift.new('Weekday', '2025-01-01T12:00:00', 24 * 60 * 60)
+ calendar.shift.withByDay(['MO', 'TU', 'WE', 'TH', 'FR'])
+ calendar.shift.withRollingUsers('daily', onCallUsers),
// 72 hour weekend shift
calendar.shift.new('Weekend', '2025-01-01T12:00:00', 72 * 60 * 60)
+ calendar.shift.withByDay(['FR', 'SA', 'SU', 'MO'])
+ calendar.shift.withRollingUsers('weekly', onCallUsers),
]),

// same as the primary shift, but shifted one person
secondary: calendar.new('Secondary', [
shift
// replace the resource ID
+ calendar.shift.withId('secondary-' + shift.metadata.name)
// start rotating from the second person
+ calendar.shift.withStartRotationFromUserIndex(1)
for shift in std.objectKeysValues(self.primary.shifts)
]),
```jsonnet
local calendar = grafanaplane.oncall.schedule.calendar,
local onCallUsers = [['[email protected]'], ['[email protected]']],
primary: calendar.new('Primary', [
// 24 hour daily shift
calendar.shift.new('Weekday', '2025-01-01T12:00:00', 24 * 60 * 60)
+ calendar.shift.withByDay(['MO', 'TU', 'WE', 'TH', 'FR'])
+ calendar.shift.withRollingUsers('daily', onCallUsers),
// 72 hour weekend shift
calendar.shift.new('Weekend', '2025-01-01T12:00:00', 72 * 60 * 60)
+ calendar.shift.withByDay(['FR', 'SA', 'SU', 'MO'])
+ calendar.shift.withRollingUsers('weekly', onCallUsers),
]),

// same as the primary shift, but shifted one person
secondary: calendar.new('Secondary', [
shift
// replace the resource ID
+ calendar.shift.withId('secondary-' + shift.metadata.name)
// start rotating from the second person
+ calendar.shift.withStartRotationFromUserIndex(1)
for shift in self.primary.shifts
]),
```

##### fn schedule.calendar.withId

Expand Down Expand Up @@ -337,8 +339,10 @@ together.

For example, if

frequency: 'daily',
users: [['[email protected]', '[email protected]'], ['[email protected]']]
```jsonnet
frequency: 'daily',
users: [['[email protected]', '[email protected]'], ['[email protected]']]
```

then on the first day, Alex and Bob would both be notified. On the next
day, only Alice would be. After that, Alex and Bob again, then Alice, and
Expand Down
44 changes: 23 additions & 21 deletions grafanaplane/oncall/schedule.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,30 @@ local forProvider = schedule.spec.parameters.forProvider;
reuse. For example, a Primary/Secondary pair of Schedules could be
declared like:

local calendar = grafanaplane.oncall.schedule.calendar,
local onCallUsers = [['[email protected]'], ['[email protected]']],
primary: calendar.new('Primary', [
// 24 hour daily shift
calendar.shift.new('Weekday', '2025-01-01T12:00:00', 24 * 60 * 60)
+ calendar.shift.withByDay(['MO', 'TU', 'WE', 'TH', 'FR'])
+ calendar.shift.withRollingUsers('daily', onCallUsers),
// 72 hour weekend shift
calendar.shift.new('Weekend', '2025-01-01T12:00:00', 72 * 60 * 60)
+ calendar.shift.withByDay(['FR', 'SA', 'SU', 'MO'])
+ calendar.shift.withRollingUsers('weekly', onCallUsers),
]),
```jsonnet
local calendar = grafanaplane.oncall.schedule.calendar,
local onCallUsers = [['[email protected]'], ['[email protected]']],
primary: calendar.new('Primary', [
// 24 hour daily shift
calendar.shift.new('Weekday', '2025-01-01T12:00:00', 24 * 60 * 60)
+ calendar.shift.withByDay(['MO', 'TU', 'WE', 'TH', 'FR'])
+ calendar.shift.withRollingUsers('daily', onCallUsers),
// 72 hour weekend shift
calendar.shift.new('Weekend', '2025-01-01T12:00:00', 72 * 60 * 60)
+ calendar.shift.withByDay(['FR', 'SA', 'SU', 'MO'])
+ calendar.shift.withRollingUsers('weekly', onCallUsers),
]),

// same as the primary shift, but shifted one person
secondary: calendar.new('Secondary', [
shift
// replace the resource ID
+ calendar.shift.withId('secondary-' + shift.metadata.name)
// start rotating from the second person
+ calendar.shift.withStartRotationFromUserIndex(1)
for shift in std.objectKeysValues(self.primary.shifts)
]),
// same as the primary shift, but shifted one person
secondary: calendar.new('Secondary', [
shift
// replace the resource ID
+ calendar.shift.withId('secondary-' + shift.metadata.name)
// start rotating from the second person
+ calendar.shift.withStartRotationFromUserIndex(1)
for shift in self.primary.shifts
]),
```
|||,
[
d.argument.new('name', d.T.string),
Expand Down
6 changes: 4 additions & 2 deletions grafanaplane/oncall/shift.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ local forProvider = shift.spec.parameters.forProvider;

For example, if

frequency: 'daily',
users: [['[email protected]', '[email protected]'], ['[email protected]']]
```jsonnet
frequency: 'daily',
users: [['[email protected]', '[email protected]'], ['[email protected]']]
```

then on the first day, Alex and Bob would both be notified. On the next
day, only Alice would be. After that, Alex and Bob again, then Alice, and
Expand Down