logstash-integration-jdbc 5.0.0.alpha1 → 5.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f759657c1178a3981ec4bc08de8e4efbb81a87feae4315f61f6efdc825cd5d03
4
- data.tar.gz: 1574ed773e16e4fd34812157bfc26df00dcfc2f0ab0de0fab7c8d012267c28c9
3
+ metadata.gz: c112f66e8224282b05dd0d43c1eb864164629951ebd9f2fdbc5d08514731057f
4
+ data.tar.gz: 69ee8e0cf79f4f4be6d4f0aae5b3f95a1fae46e3458c6a840e23722f9bbb8a60
5
5
  SHA512:
6
- metadata.gz: f4ceab2ea85b49a428efe7248a76ee42931974b70c0e139bdb390b57f3c7d66a36a1c0c59f0953bac9be0f7566fbfa977dfc37b8916683377fb5d979ef070c83
7
- data.tar.gz: 290b00f0f7a909c7148bd8a22dcc42a67ca360050eb0f9cd1aa898471de06e9535a795dade26cae6a5615f2a5e80437a92d84efcfaae8ebf45df5a1c05596d6e
6
+ metadata.gz: 8cc11af1a041fbb7784603be07de4243844bffbdfb980bf0f3ff4394af95d3ea2ed9da8543673f7fa866d999c9ba3df772567b64f31538eb8336cbf68283d39d
7
+ data.tar.gz: 9bc94ac7a6575a5ac797a44f8a8d987978a1bd0816733f252d80924e945a89b54383df101b2381b3d95afa2090149b7bdbdac1fb7dce06f34bd3fa987fba3354
@@ -1,3 +1,16 @@
1
+ ## 5.0.4
2
+ - Fixed issue where JDBC Drivers that don't correctly register with Java's DriverManager fail to load (such as Sybase) [#34](https://github.com/logstash-plugins/logstash-integration-jdbc/pull/34)
3
+
4
+ ## 5.0.3
5
+ - Fixed issue where a lost connection to the database can cause errors when using prepared statements with the scheduler [#25](https://github.com/logstash-plugins/logstash-integration-jdbc/pull/25)
6
+
7
+ ## 5.0.2
8
+ - Fixed potential resource leak by ensuring scheduler is shutdown when a pipeline encounter an error during the running [#28](https://github.com/logstash-plugins/logstash-integration-jdbc/pull/28)
9
+
10
+ ## 5.0.1
11
+ - Fixed tracking_column regression with Postgresql Numeric types [#17](https://github.com/logstash-plugins/logstash-integration-jdbc/pull/17)
12
+ - Fixed driver loading when file not accessible [#15](https://github.com/logstash-plugins/logstash-integration-jdbc/pull/15)
13
+
1
14
  ## 5.0.0
2
15
  - Initial Release of JDBC Integration Plugin, incorporating [logstash-input-jdbc](https://github.com/logstash-plugins/logstash-input-jdbc), [logstash-filter-jdbc_streaming](https://github.com/logstash-plugins/logstash-filter-jdbc_streaming) and
3
16
  [logstash-filter-jdbc_static](https://github.com/logstash-plugins/logstash-filter-jdbc_static)
data/LICENSE CHANGED
@@ -1,13 +1,202 @@
1
- Copyright (c) 2012-2018 Elasticsearch <http://www.elastic.co>
2
1
 
3
- Licensed under the Apache License, Version 2.0 (the "License");
4
- you may not use this file except in compliance with the License.
5
- You may obtain a copy of the License at
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
6
5
 
7
- http://www.apache.org/licenses/LICENSE-2.0
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
8
7
 
9
- Unless required by applicable law or agreed to in writing, software
10
- distributed under the License is distributed on an "AS IS" BASIS,
11
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- See the License for the specific language governing permissions and
13
- limitations under the License.
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright 2020 Elastic and contributors
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -339,6 +339,7 @@ required you can pass them separated by a comma.
339
339
  NOTE: If not provided, Plugin will look for the driver class in the Logstash Java classpath. Additionally, if the library
340
340
  does not appear to be being loaded correctly via this setting, placing the relevant jar(s) in the Logstash Java
341
341
  classpath rather than via this setting may help.
342
+ Please also make sure the path is readable by the Logstash process (e.g. `logstash` user when running as a service).
342
343
 
343
344
  [id="plugins-{type}s-{plugin}-jdbc_fetch_size"]
344
345
  ===== `jdbc_fetch_size`
@@ -95,7 +95,7 @@ module LogStash module Filters module Jdbc
95
95
  end
96
96
  begin
97
97
  db = nil
98
- ::Sequel::JDBC.load_driver(driver_class)
98
+ @options_hash[:driver] = ::Sequel::JDBC.load_driver(driver_class)
99
99
  @connection_string = connection_string
100
100
  if user
101
101
  @options_hash[:user] = user
@@ -270,6 +270,7 @@ module LogStash module Inputs class Jdbc < LogStash::Inputs::Base
270
270
  end
271
271
 
272
272
  def run(queue)
273
+ load_driver
273
274
  if @schedule
274
275
  @scheduler = Rufus::Scheduler.new(:max_work_threads => 1)
275
276
  @scheduler.cron @schedule do
@@ -282,6 +283,10 @@ module LogStash module Inputs class Jdbc < LogStash::Inputs::Base
282
283
  end
283
284
  end # def run
284
285
 
286
+ def close
287
+ @scheduler.shutdown if @scheduler
288
+ end
289
+
285
290
  def stop
286
291
  close_jdbc_connection
287
292
  @scheduler.shutdown(:wait) if @scheduler
@@ -110,13 +110,14 @@ module LogStash module PluginMixins module Jdbc
110
110
  :user => @jdbc_user,
111
111
  :password => @jdbc_password.nil? ? nil : @jdbc_password.value,
112
112
  :pool_timeout => @jdbc_pool_timeout,
113
+ :driver => @driver_impl, # Sequel uses this as a fallback, if given URI doesn't auto-load the driver correctly
113
114
  :keep_reference => false
114
115
  }.merge(@sequel_opts)
115
116
  retry_attempts = @connection_retry_attempts
116
117
  loop do
117
118
  retry_attempts -= 1
118
119
  begin
119
- return Sequel.connect(@jdbc_connection_string, opts=opts)
120
+ return Sequel.connect(@jdbc_connection_string, opts)
120
121
  rescue Sequel::PoolTimeout => e
121
122
  if retry_attempts <= 0
122
123
  @logger.error("Failed to connect to database. #{@jdbc_pool_timeout} second timeout exceeded. Tried #{@connection_retry_attempts} times.")
@@ -139,47 +140,58 @@ module LogStash module PluginMixins module Jdbc
139
140
 
140
141
  private
141
142
 
143
+ def load_driver
144
+ if @drivers_loaded.false?
145
+ require "java"
146
+ require "sequel"
147
+ require "sequel/adapters/jdbc"
148
+
149
+ load_driver_jars
150
+ begin
151
+ @driver_impl = Sequel::JDBC.load_driver(@jdbc_driver_class)
152
+ rescue Sequel::AdapterNotFound => e # Sequel::AdapterNotFound, "#{@jdbc_driver_class} not loaded"
153
+ # fix this !!!
154
+ message = if jdbc_driver_library_set?
155
+ "Are you sure you've included the correct jdbc driver in :jdbc_driver_library?"
156
+ else
157
+ ":jdbc_driver_library is not set, are you sure you included " +
158
+ "the proper driver client libraries in your classpath?"
159
+ end
160
+ raise LogStash::PluginLoadingError, "#{e}. #{message}"
161
+ end
162
+ @drivers_loaded.make_true
163
+ end
164
+ end
165
+
142
166
  def load_driver_jars
143
- unless @jdbc_driver_library.nil? || @jdbc_driver_library.empty?
167
+ if jdbc_driver_library_set?
144
168
  @jdbc_driver_library.split(",").each do |driver_jar|
169
+ @logger.debug("loading #{driver_jar}")
170
+ # load 'driver.jar' is different than load 'some.rb' as it only causes the file to be added to
171
+ # JRuby's class-loader lookup (class) path - won't raise a LoadError when file is not readable
172
+ unless FileTest.readable?(driver_jar)
173
+ raise LogStash::PluginLoadingError, "unable to load #{driver_jar} from :jdbc_driver_library, " +
174
+ "file not readable (please check user and group permissions for the path)"
175
+ end
145
176
  begin
146
- @logger.debug("loading #{driver_jar}")
147
- # Use https://github.com/jruby/jruby/wiki/CallingJavaFromJRuby#from-jar-files to make classes from jar
148
- # available
149
177
  require driver_jar
150
178
  rescue LoadError => e
151
179
  raise LogStash::PluginLoadingError, "unable to load #{driver_jar} from :jdbc_driver_library, #{e.message}"
180
+ rescue StandardError => e
181
+ raise LogStash::PluginLoadingError, "unable to load #{driver_jar} from :jdbc_driver_library, #{e}"
152
182
  end
153
183
  end
154
184
  end
155
185
  end
156
186
 
157
- private
158
- def open_jdbc_connection
159
- require "java"
160
- require "sequel"
161
- require "sequel/adapters/jdbc"
187
+ def jdbc_driver_library_set?
188
+ !@jdbc_driver_library.nil? && !@jdbc_driver_library.empty?
189
+ end
162
190
 
191
+ def open_jdbc_connection
192
+ # at this point driver is already loaded
163
193
  Sequel.application_timezone = @plugin_timezone.to_sym
164
- if @drivers_loaded.false?
165
- begin
166
- load_driver_jars
167
- Sequel::JDBC.load_driver(@jdbc_driver_class)
168
- rescue LogStash::Error => e
169
- # raised in load_drivers, e.cause should be the caught Java exceptions
170
- raise LogStash::PluginLoadingError, "#{e.message} and #{e.cause.message}"
171
- rescue Sequel::AdapterNotFound => e
172
- # fix this !!!
173
- message = if @jdbc_driver_library.nil?
174
- ":jdbc_driver_library is not set, are you sure you included
175
- the proper driver client libraries in your classpath?"
176
- else
177
- "Are you sure you've included the correct jdbc driver in :jdbc_driver_library?"
178
- end
179
- raise LogStash::PluginLoadingError, "#{e}. #{message}"
180
- end
181
- @drivers_loaded.make_true
182
- end
194
+
183
195
  @database = jdbc_connect()
184
196
  @database.extension(:pagination)
185
197
  if @jdbc_default_timezone
@@ -249,7 +261,9 @@ module LogStash module PluginMixins module Jdbc
249
261
  end
250
262
  success = true
251
263
  rescue Sequel::DatabaseConnectionError, Sequel::DatabaseError, Java::JavaSql::SQLException => e
252
- @logger.warn("Exception when executing JDBC query", :exception => e)
264
+ details = { :exception => e.message }
265
+ details[:backtrace] = e.backtrace if @logger.debug?
266
+ @logger.warn("Exception when executing JDBC query", details)
253
267
  else
254
268
  @value_tracker.set_value(sql_last_value)
255
269
  ensure
@@ -97,7 +97,14 @@ module LogStash module PluginMixins module Jdbc
97
97
  end
98
98
  bind_value_sql_last_value(sql_last_value)
99
99
  statement_logger.log_statement_parameters(statement, parameters, nil)
100
- db.call(name, parameters)
100
+ begin
101
+ db.call(name, parameters)
102
+ rescue => e
103
+ # clear the statement prepared flag - the statement may be closed by this
104
+ # time.
105
+ statement_prepared.make_false
106
+ raise e
107
+ end
101
108
  end
102
109
 
103
110
  def post_init(plugin)
@@ -62,7 +62,7 @@ module LogStash module PluginMixins module Jdbc
62
62
 
63
63
  class NumericValueTracker < ValueTracking
64
64
  def set_initial
65
- common_set_initial(:gcd, 0)
65
+ common_set_initial(:abs, 0)
66
66
  end
67
67
 
68
68
  def set_value(value)
@@ -84,7 +84,7 @@ module LogStash module PluginMixins module JdbcStreaming
84
84
  @sequel_opts_symbols[:user] = @jdbc_user unless @jdbc_user.nil? || @jdbc_user.empty?
85
85
  @sequel_opts_symbols[:password] = @jdbc_password.value unless @jdbc_password.nil?
86
86
 
87
- Sequel::JDBC.load_driver(@jdbc_driver_class)
87
+ @sequel_opts_symbols[:driver] = Sequel::JDBC.load_driver(@jdbc_driver_class)
88
88
  @database = Sequel.connect(@jdbc_connection_string, @sequel_opts_symbols)
89
89
  if @jdbc_validate_connection
90
90
  @database.extension(:connection_validator)
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'logstash-integration-jdbc'
3
- s.version = '5.0.0.alpha1'
3
+ s.version = '5.0.4'
4
4
  s.licenses = ['Apache License (2.0)']
5
5
  s.summary = "Integration with JDBC - input and filter plugins"
6
6
  s.description = "This gem is a Logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This gem is not a stand-alone program"
@@ -4,7 +4,6 @@ require "logstash/filters/jdbc_static"
4
4
  require "sequel"
5
5
  require "sequel/adapters/jdbc"
6
6
  require "stud/temporary"
7
- require "timecop"
8
7
 
9
8
  module LogStash module Filters
10
9
  describe JdbcStatic, :integration => true do
@@ -35,6 +34,7 @@ module LogStash module Filters
35
34
  let(:settings) do
36
35
  {
37
36
  "jdbc_user" => ENV['USER'],
37
+ "jdbc_password" => ENV["POSTGRES_PASSWORD"],
38
38
  "jdbc_driver_class" => "org.postgresql.Driver",
39
39
  "jdbc_driver_library" => "/usr/share/logstash/postgresql.jar",
40
40
  "staging_directory" => temp_import_path_plugin,
@@ -88,6 +88,7 @@ module LogStash module Filters
88
88
  let(:settings) do
89
89
  {
90
90
  "jdbc_user" => ENV['USER'],
91
+ "jdbc_password" => ENV["POSTGRES_PASSWORD"],
91
92
  "jdbc_driver_class" => "org.postgresql.Driver",
92
93
  "jdbc_driver_library" => "/usr/share/logstash/postgresql.jar",
93
94
  "staging_directory" => temp_import_path_plugin,
@@ -134,18 +135,16 @@ module LogStash module Filters
134
135
  describe "scheduled operation" do
135
136
  context "given a loader_schedule" do
136
137
  it "should properly schedule" do
137
- settings["loader_schedule"] = "*/10 * * * * * UTC"
138
- Timecop.travel(Time.now.utc - 3600)
139
- Timecop.scale(60)
138
+ settings["loader_schedule"] = "*/3 * * * * * UTC"
140
139
  static_filter = JdbcStatic.new(settings)
141
140
  runner = Thread.new(static_filter) do |filter|
142
141
  filter.register
143
142
  end
144
- sleep 3
143
+ runner.join(4)
144
+ sleep 4
145
145
  static_filter.filter(event)
146
146
  expect(static_filter.loader_runner.reload_count).to be > 1
147
147
  static_filter.close
148
- Timecop.return
149
148
  expect(event.get("server")).to eq([{"ip"=>"10.3.1.1", "name"=>"mv-server-1", "location"=>"MV-9-6-4"}])
150
149
  end
151
150
  end
@@ -16,7 +16,10 @@ module LogStash module Filters
16
16
  "jdbc:postgresql://postgresql:5432") + "/jdbc_streaming_db?user=postgres"
17
17
 
18
18
  let(:mixin_settings) do
19
- { "jdbc_driver_class" => "org.postgresql.Driver",
19
+ {
20
+ "jdbc_user" => ENV['USER'],
21
+ "jdbc_password" => ENV["POSTGRES_PASSWORD"],
22
+ "jdbc_driver_class" => "org.postgresql.Driver",
20
23
  "jdbc_driver_library" => "/usr/share/logstash/postgresql.jar",
21
24
  "jdbc_connection_string" => jdbc_connection_string
22
25
  }
@@ -10,28 +10,37 @@ module LogStash module Filters module Jdbc
10
10
  let(:driver_class) { "org.apache.derby.jdbc.EmbeddedDriver" }
11
11
  let(:driver_library) { nil }
12
12
  subject(:read_only_db) { described_class.create(connection_string, driver_class, driver_library) }
13
+ let(:stub_driver_class) { double(driver_class).as_null_object }
13
14
 
14
15
  describe "basic operations" do
15
16
  describe "initializing" do
17
+ before(:each) do
18
+ allow(Sequel::JDBC).to receive(:load_driver).and_return(stub_driver_class)
19
+ end
20
+
16
21
  it "tests the connection with defaults" do
17
22
  expect(Sequel::JDBC).to receive(:load_driver).once.with(driver_class)
18
- expect(Sequel).to receive(:connect).once.with(connection_string, {:test => true})
23
+ expect(Sequel).to receive(:connect).once.with(connection_string, {:test => true, :driver => stub_driver_class})
19
24
  expect(read_only_db.empty_record_set).to eq([])
20
25
  end
21
26
 
22
- it "tests the connection with fully specified arguments" do
23
- connection_str = "a connection string"
24
- user = "a user"
25
- password = Util::Password.new("secret")
26
- expect(Sequel::JDBC).to receive(:load_driver).once.with("a driver class")
27
- expect(Sequel).to receive(:connect).once.with(connection_str, {:user => user, :password => password.value, :test => true}).and_return(db)
28
- described_class.create(connection_str, "a driver class", nil, user, password)
27
+ context 'with fully-specified arguments' do
28
+ let(:connection_string) { "a connection string" }
29
+ let(:user) { "a user" }
30
+ let(:password) { Util::Password.new("secret") }
31
+ let(:driver_class) { "a driver class" }
32
+
33
+ it "tests the connection" do
34
+ expect(Sequel::JDBC).to receive(:load_driver).once.with(driver_class)
35
+ expect(Sequel).to receive(:connect).once.with(connection_string, {:user => user, :password => password.value, :test => true, :driver => stub_driver_class}).and_return(db)
36
+ described_class.create(connection_string, driver_class, nil, user, password)
37
+ end
29
38
  end
30
39
 
31
40
  it "connects with defaults" do
32
41
  expect(Sequel::JDBC).to receive(:load_driver).once.with(driver_class)
33
- expect(Sequel).to receive(:connect).once.with(connection_string, {:test => true}).and_return(db)
34
- expect(Sequel).to receive(:connect).once.with(connection_string, {}).and_return(db)
42
+ expect(Sequel).to receive(:connect).once.with(connection_string, {:test => true, :driver => stub_driver_class}).and_return(db)
43
+ expect(Sequel).to receive(:connect).once.with(connection_string, {:driver => stub_driver_class}).and_return(db)
35
44
  expect(read_only_db.connected?).to be_falsey
36
45
  read_only_db.connect("a caller specific error message")
37
46
  expect(read_only_db.connected?).to be_truthy
@@ -16,10 +16,11 @@ module LogStash module Filters module Jdbc
16
16
  describe "basic operations" do
17
17
  context "connecting to a db" do
18
18
  it "connects with defaults" do
19
- expect(::Sequel::JDBC).to receive(:load_driver).once.with("org.apache.derby.jdbc.EmbeddedDriver")
19
+ stub_driver_class = double('org.apache.derby.jdbc.EmbeddedDriver').as_null_object
20
+ expect(::Sequel::JDBC).to receive(:load_driver).once.with("org.apache.derby.jdbc.EmbeddedDriver").and_return(stub_driver_class)
20
21
  # two calls to connect because ReadWriteDatabase does verify_connection and connect
21
- expect(::Sequel).to receive(:connect).once.with(connection_string_regex, {:test => true}).and_return(db)
22
- expect(::Sequel).to receive(:connect).once.with(connection_string_regex, {}).and_return(db)
22
+ expect(::Sequel).to receive(:connect).once.with(connection_string_regex, {:driver => stub_driver_class, :test => true}).and_return(db)
23
+ expect(::Sequel).to receive(:connect).once.with(connection_string_regex, {:driver => stub_driver_class}).and_return(db)
23
24
  expect(read_write_db.empty_record_set).to eq([])
24
25
  end
25
26
 
@@ -27,9 +28,10 @@ module LogStash module Filters module Jdbc
27
28
  connection_str = "a connection string"
28
29
  user = "a user"
29
30
  password = Util::Password.new("secret")
30
- expect(::Sequel::JDBC).to receive(:load_driver).once.with("a driver class")
31
- expect(::Sequel).to receive(:connect).once.with(connection_str, {:user => user, :password => password.value, :test => true}).and_return(db)
32
- expect(::Sequel).to receive(:connect).once.with(connection_str, {:user => user, :password => password.value}).and_return(db)
31
+ stub_driver_class = double('com.example.Driver')
32
+ expect(::Sequel::JDBC).to receive(:load_driver).once.with("a driver class").and_return(stub_driver_class)
33
+ expect(::Sequel).to receive(:connect).once.with(connection_str, {:driver => stub_driver_class, :user => user, :password => password.value, :test => true}).and_return(db)
34
+ expect(::Sequel).to receive(:connect).once.with(connection_str, {:driver => stub_driver_class, :user => user, :password => password.value}).and_return(db)
33
35
  described_class.create(connection_str, "a driver class", nil, user, password)
34
36
  end
35
37
  end
@@ -1,4 +1,5 @@
1
1
  require "logstash/devutils/rspec/spec_helper"
2
+ require "logstash/devutils/rspec/shared_examples"
2
3
  require "logstash/filters/jdbc_streaming"
3
4
  require 'jdbc/derby'
4
5
  require "sequel"
@@ -3,7 +3,6 @@ require "logstash/inputs/jdbc"
3
3
  require "sequel"
4
4
  require "sequel/adapters/jdbc"
5
5
 
6
- # This test requires: Firebird installed to Mac OSX, it uses the built-in example database `employee`
7
6
 
8
7
  describe LogStash::Inputs::Jdbc, :integration => true do
9
8
  # This is a necessary change test-wide to guarantee that no local timezone
@@ -19,6 +18,7 @@ describe LogStash::Inputs::Jdbc, :integration => true do
19
18
  "jdbc_connection_string" => jdbc_connection_string,
20
19
  "jdbc_driver_library" => "/usr/share/logstash/postgresql.jar",
21
20
  "jdbc_user" => "postgres",
21
+ "jdbc_password" => ENV["POSTGRES_PASSWORD"],
22
22
  "statement" => 'SELECT FIRST_NAME, LAST_NAME FROM "employee" WHERE EMP_NO = 2'
23
23
  }
24
24
  end
@@ -1,5 +1,6 @@
1
1
  # encoding: utf-8
2
2
  require "logstash/devutils/rspec/spec_helper"
3
+ require "logstash/devutils/rspec/shared_examples"
3
4
  require "logstash/inputs/jdbc"
4
5
  require "jdbc/derby"
5
6
  require "sequel"
@@ -28,10 +29,11 @@ describe LogStash::Inputs::Jdbc do
28
29
  # before body
29
30
  Jdbc::Derby.load_driver
30
31
  db.create_table :test_table do
31
- DateTime :created_at
32
- Integer :num
33
- String :string
34
- DateTime :custom_time
32
+ DateTime :created_at
33
+ BigDecimal :big_num
34
+ Integer :num
35
+ String :string
36
+ DateTime :custom_time
35
37
  end
36
38
  db << "CREATE TABLE types_table (num INTEGER, string VARCHAR(255), started_at DATE, custom_time TIMESTAMP, ranking DECIMAL(16,6))"
37
39
  db << "CREATE TABLE test1_table (num INTEGER, string VARCHAR(255), custom_time TIMESTAMP, created_at TIMESTAMP)"
@@ -189,6 +191,18 @@ describe LogStash::Inputs::Jdbc do
189
191
  Timecop.return
190
192
  end
191
193
 
194
+ it "cleans up scheduler resources on close" do
195
+ runner = Thread.new do
196
+ plugin.run(queue)
197
+ end
198
+ sleep 1
199
+ plugin.do_close
200
+
201
+ scheduler = plugin.instance_variable_get(:@scheduler)
202
+ expect(scheduler).to_not be_nil
203
+ expect(scheduler.down?).to be_truthy
204
+ end
205
+
192
206
  end
193
207
 
194
208
  context "when scheduling and previous runs are to be preserved" do
@@ -545,6 +559,54 @@ describe LogStash::Inputs::Jdbc do
545
559
  end
546
560
  end
547
561
 
562
+ context "Test Sql Last Value with a BigDecimal `sqlLastValue`" do
563
+ let(:mixin_settings) do
564
+ { "jdbc_user" => ENV['USER'], "jdbc_driver_class" => "org.apache.derby.jdbc.EmbeddedDriver",
565
+ "jdbc_connection_string" => "jdbc:derby:memory:testdb;create=true"
566
+ }
567
+ end
568
+
569
+ let(:settings) do
570
+ { "statement" => "SELECT big_num, created_at FROM test_table WHERE big_num > :sql_last_value",
571
+ "use_column_value" => true,
572
+ "tracking_column" => "big_num",
573
+ "last_run_metadata_path" => Stud::Temporary.pathname }
574
+ end
575
+
576
+ let(:nums) { [BigDecimal.new(10), BigDecimal.new(20), BigDecimal.new(30), BigDecimal.new(40), BigDecimal.new(50)] }
577
+
578
+ before do
579
+ plugin.register
580
+ end
581
+
582
+ after do
583
+ plugin.stop
584
+ end
585
+
586
+ it "should only pick up new values" do
587
+ test_table = db[:test_table]
588
+
589
+ plugin.run(queue)
590
+ expect(queue.size).to eq(0)
591
+ test_table.insert(:big_num => nums[0], :created_at => Time.now.utc)
592
+ test_table.insert(:big_num => nums[1], :created_at => Time.now.utc)
593
+ queue = []
594
+ # Stop and restart the plugin to have it read saved value of `sql_last_value`
595
+ plugin.stop
596
+ plugin.register
597
+ plugin.run(queue)
598
+ expect(queue.size).to eq(2)
599
+ test_table.insert(:big_num => nums[2], :created_at => Time.now.utc)
600
+ test_table.insert(:big_num => nums[3], :created_at => Time.now.utc)
601
+ test_table.insert(:big_num => nums[4], :created_at => Time.now.utc)
602
+ queue = []
603
+ plugin.stop
604
+ plugin.register
605
+ plugin.run(queue)
606
+ expect(queue.size).to eq(3)
607
+ end
608
+ end
609
+
548
610
  context "when iteratively running plugin#run with timestamp tracking column with column value" do
549
611
  let(:mixin_settings) do
550
612
  { "jdbc_user" => ENV['USER'], "jdbc_driver_class" => "org.apache.derby.jdbc.EmbeddedDriver",
@@ -1291,6 +1353,38 @@ describe LogStash::Inputs::Jdbc do
1291
1353
  end
1292
1354
  end
1293
1355
 
1356
+ context "when an unreadable jdbc_driver_path entry is present" do
1357
+ let(:driver_jar_path) do
1358
+ jar_file = $CLASSPATH.find { |name| name.index(Jdbc::Derby.driver_jar) }
1359
+ raise "derby jar not found on class-path" unless jar_file
1360
+ jar_file.sub('file:', '')
1361
+ end
1362
+
1363
+ let(:invalid_driver_jar_path) do
1364
+ path = File.join(Dir.mktmpdir, File.basename(driver_jar_path))
1365
+ FileUtils.cp driver_jar_path, path
1366
+ FileUtils.chmod "u=x,go=", path
1367
+ path
1368
+ end
1369
+
1370
+ let(:settings) do
1371
+ { "statement" => "SELECT * from types_table", "jdbc_driver_library" => invalid_driver_jar_path }
1372
+ end
1373
+
1374
+ before do
1375
+ plugin.register
1376
+ end
1377
+
1378
+ after do
1379
+ plugin.stop
1380
+ end
1381
+
1382
+ it "raise a loading error" do
1383
+ expect { plugin.run(queue) }.
1384
+ to raise_error(LogStash::PluginLoadingError, /unable to load .*? from :jdbc_driver_library, file not readable/)
1385
+ end
1386
+ end
1387
+
1294
1388
  context "when using prepared statements" do
1295
1389
  let(:last_run_value) { 250 }
1296
1390
  let(:expected_queue_size) { 100 }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-integration-jdbc
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.0.alpha1
4
+ version: 5.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elastic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-01-07 00:00:00.000000000 Z
11
+ date: 2020-06-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -210,7 +210,6 @@ files:
210
210
  - CONTRIBUTORS
211
211
  - Gemfile
212
212
  - LICENSE
213
- - NOTICE.TXT
214
213
  - README.md
215
214
  - docs/filter-jdbc_static.asciidoc
216
215
  - docs/filter-jdbc_streaming.asciidoc
@@ -242,7 +241,6 @@ files:
242
241
  - lib/logstash/plugin_mixins/jdbc_streaming/cache_payload.rb
243
242
  - lib/logstash/plugin_mixins/jdbc_streaming/parameter_handler.rb
244
243
  - lib/logstash/plugin_mixins/jdbc_streaming/statement_handler.rb
245
- - lib/logstash/plugin_mixins/statement_handler.rb
246
244
  - logstash-integration-jdbc.gemspec
247
245
  - spec/filters/env_helper.rb
248
246
  - spec/filters/integration/jdbc_static_spec.rb
@@ -286,12 +284,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
286
284
  version: '0'
287
285
  required_rubygems_version: !ruby/object:Gem::Requirement
288
286
  requirements:
289
- - - ">"
287
+ - - ">="
290
288
  - !ruby/object:Gem::Version
291
- version: 1.3.1
289
+ version: '0'
292
290
  requirements: []
293
291
  rubyforge_project:
294
- rubygems_version: 2.7.9
292
+ rubygems_version: 2.6.13
295
293
  signing_key:
296
294
  specification_version: 4
297
295
  summary: Integration with JDBC - input and filter plugins
data/NOTICE.TXT DELETED
@@ -1,5 +0,0 @@
1
- Elasticsearch
2
- Copyright 2012-2018 Elasticsearch
3
-
4
- This product includes software developed by The Apache Software
5
- Foundation (http://www.apache.org/).