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

Allow to specify daily time periods without chaos #62

Merged
merged 5 commits into from Feb 17, 2018
Merged

Conversation

linki
Copy link
Owner

@linki linki commented Feb 12, 2018

allows to specify time periods per day that chaoskube is inactive, e.g.

--excluded-times-of-day="11:00-13:00,22:00-06:00"

@linki linki changed the title WIP: per-day time periods to disable chaoskube Allow to specify daily time periods without chaos Feb 15, 2018
@linki linki merged commit 2ffe5d2 into master Feb 17, 2018
@linki
Copy link
Owner Author

linki commented Feb 17, 2018

@twildeboer I overhauled your implementation of the --hours feature and this is what I came up with.

@linki linki deleted the time-periods branch February 17, 2018 15:28
for _, tp := range strings.Split(timePeriods, ",") {
parts := strings.Split(tp, "-")
if len(parts) != 2 {
continue

Choose a reason for hiding this comment

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

Isn't this an error condition? Or are you just choosing to ignore it without logging it?

Copy link
Owner Author

Choose a reason for hiding this comment

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

Good point. I intended to silently ignore the case when there's only whitespace so that the default case "" doesn't need any special treatment. I'll provide a fix for when there's a value but doesn't seem to be valid time period, e.g. contains exactly one - I guess.

continue
}

begin, err := time.ParseInLocation(timeFormatKitchen24, strings.TrimSpace(parts[0]), time.Local)

Choose a reason for hiding this comment

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

Don't you want to recognize the timezone set by the user in the config?

Copy link
Owner Author

@linki linki Feb 21, 2018

Choose a reason for hiding this comment

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

Yeah, not sure what I did there. I think my intention was to just parse the string into an exactly corresponding time object regardless of any timezone, e.g. parsing a full time string ... 14:00 someTimezone into an object with hour=14. I think time.Parse without Location will just do that?!

Choose a reason for hiding this comment

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

Seems like this should work. Just be careful and thorough in your testing. Maybe use UTC just for consistency with your TimeOfDay function?

midnight := NewTimePeriod(
time.Date(1869, 9, 23, 23, 00, 00, 00, time.UTC),
time.Date(1869, 9, 24, 01, 00, 00, 00, time.UTC),
)
Copy link

Choose a reason for hiding this comment

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

Please correct me if I'm wrong, but I believe this is not a valid test because your actual code in ParseTimePeriods does not account for the beginning and ending times spanning midnight, so it would never actually produce the pair of begin and end times you are generating here. For instance, you have no test that correctly handles the excluded-times-of-day you give in the README: 22:00-08:00, which spans midnight. If you want to support that you have to detect that the end time is "earlier" than the begin time and add 24 hours to it. But beware, this will break during Daylight Saving nights and it will be very difficult to do this correctly (besides defining what "correct" is in that case). For example, what if the user sets the time period to be 23:00-02:11. On a Daylight Saving starting night, 02:11 never occurs, because it skips 02:00-02:59, and on the Daylight Saving end night 02:00-02:59 occurs twice! This is why I avoided supporting suspension periods spanning midnight. :-)

Copy link
Owner Author

@linki linki Feb 21, 2018

Choose a reason for hiding this comment

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

Right, I'll definitely double-check that but I think it worked (apart from the daylight savings issue).

The idea is to use time.Parse to convert strings to time in the same manner as go does; however we don't care about the actual day and strip it off later. I believe the test above works with any day other than the 24th as well.

So this will end up in a time range that looks like start: 23, end: 1 (on day zero). start being greater than end idicates that the range goes across midnight which triggers a different logic branch for whether a time is included or not in Includes(): https://github.com/linki/chaoskube/pull/62/files#diff-99f38c7c07bfcc03a528180716bafab5R37

Copy link
Owner Author

Choose a reason for hiding this comment

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

Regarding daylight savings: If time.Parse returns the hours that would be shown on the clock, e.g. on start it jumps from 01:59 to 03:00 and on end it jumps from 02:59 to 02:00, then I think this should also work. Of course there will be one real hour more or less chaos time, but I think that's fine.

Choose a reason for hiding this comment

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

Ah! Missed that bit of logic in Includes(). 👍

Choose a reason for hiding this comment

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

Regarding daylight savings: ...

Makes sense. I just think it's important that you satisfy yourself that you have adequately addressed the potential issue. 👍

Copy link

@twildeboer twildeboer left a comment

Choose a reason for hiding this comment

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

Added some comments. I think you will have trouble supporting the 22:00-08:00 as it is currently implemented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants