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

Sequel datetime class consistency #151

Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
## 5.4.11
- Fixes an issue in which any one instance of a JDBC input plugin using `jdbc_default_timezone` changes the behaviour of plugin instances that do _not_ use `jdbc_default_timezone`, ensuring that timezone offsets remain consistent for each instance of the plugin _as configured_ [#151](https://github.com/logstash-plugins/logstash-integration-jdbc/pull/151)
- Fixes an exception that could occur while reloading `jdbc_static` databases when the underlying connection to the remote has been broken [#165](https://github.com/logstash-plugins/logstash-integration-jdbc/pull/165)

## 5.4.10
Expand Down
2 changes: 1 addition & 1 deletion lib/logstash/filters/jdbc/basic_database.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# encoding: utf-8
require "fileutils"
require "sequel"
require "logstash/plugin_mixins/jdbc/sequel_bootstrap"
require "sequel/adapters/jdbc"
require "java"
require "logstash/util/loggable"
Expand Down
3 changes: 2 additions & 1 deletion lib/logstash/plugin_mixins/jdbc/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ def load_driver
return @driver_impl if @driver_impl ||= nil

require "java"
require "sequel"

require_relative "sequel_bootstrap"
require "sequel/adapters/jdbc"

# execute all the driver loading related duties in a serial fashion to avoid
Expand Down
21 changes: 21 additions & 0 deletions lib/logstash/plugin_mixins/jdbc/sequel_bootstrap.rb
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
27 changes: 27 additions & 0 deletions spec/inputs/jdbc_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,33 @@
# With no timezone set, no change should occur
expect(event.get("custom_time").time).to eq(Time.iso8601("2015-01-01T12:00:00Z"))
end

%w(
Etc/UTC
America/Los_Angeles
Europe/Berlin
Asia/Tokyo
).each do |local_timezone|
context "when host machine has timezone `#{local_timezone}`" do
around(:each) do |example|
begin
previous_tz = ENV['TZ']
ENV['TZ'] = local_timezone
example.call
ensure
ENV['TZ'] = previous_tz
end
end

let(:tz) { TZInfo::Timezone.get(local_timezone) }

it "converts the time using the machine's local timezone" do
plugin.run(queue)
event = queue.pop
expect(event.get("custom_time").time).to eq(Time.new(2015,1,1,12,0,0,tz))
end
end
end
end

context "when iteratively running plugin#run" do
Expand Down