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

DST starting/ending causes overlap/gap in schedules #5247

Closed
zackman0010 opened this issue Nov 11, 2024 · 1 comment · Fixed by #5266
Closed

DST starting/ending causes overlap/gap in schedules #5247

zackman0010 opened this issue Nov 11, 2024 · 1 comment · Fixed by #5266
Labels
bug Something isn't working part:schedules

Comments

@zackman0010
Copy link
Contributor

zackman0010 commented Nov 11, 2024

What went wrong?

When using the API to create a schedule that has a time zone with DST, there will be a one hour gap in the schedule when DST ends and a one hour overlap when DST begins.

Image
Image

How do we reproduce it?

  1. Create a weekly rotating shift
    POST {baseUrl}/api/v1/on_call_shifts
{
    "name": "Test API Shift",
    "type": "rolling_users",
    "start": "2024-10-01T09:00:00",
    "duration": 604800,
    "frequency": "weekly",
    "week_start": "MO",
    "rolling_users": [["SomeUserId"]],
    "start_rotation_from_user_index": 0
}
  1. Create a schedule using the shift created previously. A time zone that has DST must be used.
    POST {baseUrl}/api/v1/schedules
{
    "name": "Test API Schedule",
    "type": "calendar",
    "time_zone": "America/Chicago",
    "enable_web_overrides": true,
    "shifts": ["IdOfShiftFromStep1"]
}
  1. In Grafana, look at the scheduled shifts for when DST ends (Such as November 3, 2024 for America/Chicago). You should see a one hour gap.

  2. In Grafana, look at the scheduled shifts for when DST begins (Such as March 9, 2024 for America/Chicago). You should see a one hour overlap.

Grafana OnCall Version

Cloud (Plugin management says v1.14.1 is installed)

Product Area

Schedules

Grafana OnCall Platform?

I use Grafana Cloud

User's Browser?

No response

Anything else to add?

I found the PR #4103 that says it fixes schedule gaps, but it appears that it only fixed the visual gaps caused by a schedule being in UTC and the user's time zone being non-UTC. In that situation, there is no actual schedule gap because the schedule was in UTC, so the only issue was a visual bug. In this case, I believe there actually is a one hour gap.

@zackman0010 zackman0010 added the bug Something isn't working label Nov 11, 2024
@zackman0010 zackman0010 changed the title DST ending causes gap in schedule DST starting/ending causes overlap/gap in schedules Nov 11, 2024
@zackman0010
Copy link
Contributor Author

zackman0010 commented Nov 13, 2024

Looking into it, the best way to fix this requires updating the recurring_ical_events dependency to a newer version, as the version currently in use does not call pytz's .normalize function on the end date, causing it to be an invalid date (ie - Nov 3, 2024 9:00 AM CDT instead of the correct 8:00 AM CST). However, some of the tests are currently failing with the updated dependencies. I'm looking into it now to see if I can tell what exactly changed, but in the meantime I also have an alternate fix that doesn't involve updating the dependencies.

The tests that are failing with the updated dependencies show changed behavior in recurring_ical_events that I'm not sure how to rectify, so I'm abandoning that line of research and will just stick with the fix that doesn't require updating dependencies.

Fix with dependency update (Failing tests): zackman0010@d918955
Fix without dependency update: zackman0010@9d48c88

github-merge-queue bot pushed a commit that referenced this issue Nov 20, 2024
# What this PR does

This older version of recurring_ical_events does not call the pytz
.normalize() function, which can cause some invalid datetime objects to
return when a DST swap happens. For example: Nov 3, 2024 9:00 AM CDT
instead of the correct 8:00 AM CST). By calling tz.normalize on the end
date and checking if the time zone information changed, we can detect
when DST starts/stops and adjust the end date accordingly.

| | DST stopping on November 3, 2024: | DST starting on March 9, 2024 |

|-|-----------------------------------------|-----------------------------------|
| Before |
![image](https://github.com/user-attachments/assets/933bce80-9b6a-475b-88f2-6356d0e3a6fd)
|
![image](https://github.com/user-attachments/assets/264b816f-6f40-4f14-bbc0-1d03f7b74ac4)
| After |
![image](https://github.com/user-attachments/assets/fbd71991-c4f8-4685-a527-6dbb147b2cb6)
|
![image](https://github.com/user-attachments/assets/ccd932df-2ab4-4472-bc90-045372712f75)
|

## Which issue(s) this PR closes

Closes #5247

## Checklist

- [ ] Unit, integration, and e2e (if applicable) tests updated
- [ ] Documentation added (or `pr:no public docs` PR label added if not
required)
- [ ] Added the relevant release notes label (see labels prefixed w/
`release:`). These labels dictate how your PR will
    show up in the autogenerated release notes.

---------

Co-authored-by: Matias Bordese <mbordese@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working part:schedules
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant