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
Fix broken TimePeriod/ScheduledDowntime
s
#9983
base: master
Are you sure you want to change the base?
Conversation
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.
First of all, I disagree with this one:
closes #7855
That PR even describes what's not optimal with the current implementation of the time period inclusion/exclusion.
It's okay to disagree! As I said before, I don't see any serious problems with the current implementation and it doesn't introduce any known bugs. So why are you willing to change this "working" path with a "better" implementation that might introduce another bug? |
6d0bce4
to
c4d0838
Compare
Your argument is legit, but I think this is a discussion to be continued in #7855 itself. We don't have to decide whether or not to close that PR neither right now, nor along with this one. |
All that timeperiod code relies heavily on the following behavior of
So that shouldn't be the same time (also, if there reference time may be the startup time, hours/minutes/seconds should not be from the reference time). I'm not sure whether you're implying that begin and end is set to the same time, they should be a day apart. |
Ja! NVM!
No, I'm not!
Yes, they are the same, as the "hours/minutes/seconds" are set to 0 here, i.e. the reference time becomes the same as the actual end date of for example icinga2/lib/icinga/legacytimeperiod.cpp Lines 589 to 595 in 01a6c4c
|
c4d0838
to
e0bfb59
Compare
This PR fixes a broken behaviour of the
LegacyTimePeriod::IsInTimeRange()
method that affects the overall time period and scheduled downtime handling and frustrates so many users just due to this nasty little logic error.LegacyTimePeriod::ScriptFunc()
callsIsInDayDefinition()
with the current time range e.g. (2024-01-29
) and a reference time, which is the local time of the Icinga 2 daemon being started, i.e the time being Icinga 2 started at.icinga2/lib/icinga/legacytimeperiod.cpp
Line 622 in 01a6c4c
LegacyTimePeriod::IsInDayDefinition()
then parses the specified time range "daydef" with theParseTimeRange()
method and passes the argumentsbegin
andend
.icinga2/lib/icinga/legacytimeperiod.cpp
Lines 392 to 395 in 01a6c4c
LegacyTimePeriod::ParseTimeRange()
then callsParseTimeSpec()
, which normalises thebegin
andend
arguments if they are set, which is true in this case.icinga2/lib/icinga/legacytimeperiod.cpp
Lines 183 to 192 in 01a6c4c
icinga2/lib/icinga/legacytimeperiod.cpp
Lines 194 to 202 in 01a6c4c
At this point, the end time is normalised the same way as the start date, but its tm_hour is set to 24 (
which is incorrect anyway, since), and passing it throughmtkime(3)
wraps around at23
mtkime(3)
produces the exactly the same timestamp as the given reference time, which is erroneously considered to be within range.Irrespective of this PR, we should consider changing this. According to the method description, the end date is supposed to be set to
0
o'clock in the following day, instead it is set to 1 o'clock due to the wrapping around.mktime(3)
Tests
Test cases for #9781
Before:
Even if the time period is not active, it has exceeded the time span and still includes the next day after the end of the range!
After:
Test cases for #9388
Before:
There should be no segments at all, as the time period only covers 28 January.
After:
Test cases for #8741 and #7398
Before:
Today (monday) is just getting skipped!
After:
Test cases for #7239
Before:
Firstly, the period shouldn't be active and secondly, the end date spans across the entire day.
After:
fixes #9781
fixes #9388
fixes #8741
fixes #7398
fixes #7239
fixes also https://community.icinga.com/t/i-get-notifications-for-users-outside-their-timeperiod/13126/3
May also fix #7061 (I haven't verified it, but since both object types use the same code, I would expect this to be fixed as well.)
closes #7855 (There is nothing wrong with the current implementation of the time period inclusion/exclusion, so why should it be changed?)