-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sequel datetime class consistency (#151)
* timezones: absent instruction otherwise, interpret times as local these tests SUCCEED when run on their own, but FAIL when run after any instance of a plugin has been initialized with `jdbc_default_timezone`, since doing so globally configures Sequel to use DateTime instead of Time: To validate, modify the `.ci/run.sh` execution line to be: > ~~~ > bundle exec rspec spec --format documentation --example "without jdbc_default_timezone" > ~~~ * timezones: consistently pre-load Sequel, force datetime_class=Time By default, when a plugin is configured _without_ `jdbc_default_timezone` timestamps are assumed to be in the same timezone as the Logstash host machine, because they are parsed with Ruby's `Time#parse` which uses local context. However, when any one plugin declares `jdbc_default_timezone`, we load Sequel's `named_timezones` extension, which has a side-effect of globally changing `Sequel.datetime_class` to ruby's `DateTime`. The plugins that are configured with `jdbc_default_timezone` have enough information to apply the separately-provided offset, but the plugins that do _not_ have a `jdbc_default_timezone` directive become broken and effectively fail to parse the timestamps as they did when run on their own. Sequel's `named_timezones` extension supports being used with `Time` objects, and is noted to override `Sequel#datetime_class` on load only for historic reasons. We force Sequel to use ruby's `Time` class globally (enforcing its default and preventing it from being changed). This is done inside of a separately-required bootstrap, which allows us to ensure it is loaded exacltly once. * bump version & add changelog entry
- Loading branch information
Showing
5 changed files
with
52 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# encoding: utf-8 | ||
|
||
require "sequel" | ||
|
||
# prevent Sequel's datetime_class from being modified, | ||
# and ensure behaviour is restored to the library's default | ||
# if something else in the Ruby VM has already changed it. | ||
Sequel.synchronize do | ||
def Sequel.datetime_class=(klass) | ||
# noop | ||
end | ||
def Sequel.datetime_class | ||
::Time | ||
end | ||
end | ||
|
||
# load the named_timezones extension, which will attempt to | ||
# override the global Sequel::datetime_class; for safety, | ||
# we reset it once more. | ||
Sequel.extension(:named_timezones) | ||
Sequel.datetime_class = ::Time |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters