logstash-integration-jdbc 5.1.2 → 5.1.6

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: 34dbd968b687896da6407942201421c91970d025814596b7229609493b8bbcdc
4
- data.tar.gz: a5155f4d11413ae5440c1c3ec4da5215c3cdd6febd4cb6d6376b2a03bdcbad42
3
+ metadata.gz: ef9180da50049c113170083c54826d75aadc91883fdca644bd82b5802ccd7234
4
+ data.tar.gz: 55b6adf668a1aac55c7a5883ae02de29431bcdf1e58d2177ab6004524bd99780
5
5
  SHA512:
6
- metadata.gz: dec5e76bf0354e7d46fafcb56725ba581ad31c54d475269faf5562e658f3723426a14011d961d6aedaf6ba921b9a654dbe05b2707bdfad38e6b3ca34f1934b56
7
- data.tar.gz: 65eb85f0e25e73f2e63de44c3d9e64ad6d834c5af316208acb445efcf1aa8d4443de00f2dcf68e66c90057a46fbddb9c7ff451b80bc46ce03bcf32b43c7a6c4a
6
+ metadata.gz: 22e48f5ac21bde7821142cc77accd458dd695a8895941bed7d7a495459d06663c2166c94c91f9592f1621f119a9c796c186401542a8085f01abd6544b3345376
7
+ data.tar.gz: 3f0a613c6bd1d4a9c8b272ec6b344bc0f791f5a137f25adbee547fbece9d7a5a01028f125641255186266d47714bb47e499325c21700d865c4cc9bf22dd529f2
data/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
+ ## 5.1.6
2
+ - Fix, serialize the JDBC driver loading steps to avoid concurrency issues [#84](https://github.com/logstash-plugins/logstash-integration-jdbc/pull/84)
3
+
4
+ ## 5.1.5
5
+ - Refined ECS support [#82](https://github.com/logstash-plugins/logstash-integration-jdbc/pull/82)
6
+ - Uses shared `target` guidance when ECS compatibility is enabled
7
+ - Uses Logstash's EventFactory instead of instantiating events directly
8
+
9
+ ## 5.1.4
10
+ - [DOC] Update filter-jdbc_static doc to describe ECS compatibility [#79](https://github.com/logstash-plugins/logstash-integration-jdbc/pull/79)
11
+
12
+ ## 5.1.3
13
+ - Improve robustness when handling errors from `sequel` library in jdbc static and streaming
14
+ filters [#78](https://github.com/logstash-plugins/logstash-integration-jdbc/pull/78)
15
+
1
16
  ## 5.1.2
2
- - Fix `prepared_statement_bind_values` in streaming filter to resolve nested event's fields[#76](https://github.com/logstash-plugins/logstash-integration-jdbc/pull/76)
17
+ - Fix `prepared_statement_bind_values` in streaming filter to resolve nested event's fields [#76](https://github.com/logstash-plugins/logstash-integration-jdbc/pull/76)
3
18
 
4
19
  ## 5.1.1
5
20
  - [DOC] Changed docs to indicate that logstash-jdbc-static requires local_table [#56](https://github.com/logstash-plugins/logstash-integration-jdbc/pull/56). Fixes [#55](https://github.com/logstash-plugins/logstash-integration-jdbc/issues/55).
@@ -264,8 +264,17 @@ order is in place.
264
264
  ===============================
265
265
 
266
266
 
267
+ [id="plugins-{type}s-{plugin}-ecs"]
268
+ ==== Compatibility with the Elastic Common Schema (ECS)
269
+
270
+ This plugin is compatible with the {ecs-ref}[Elastic Common Schema (ECS)].
271
+ It behaves the same regardless of ECS compatibility, except giving a warning when ECS is enabled and `target` isn't set.
272
+
273
+ TIP: Set the `target` option to avoid potential schema conflicts.
274
+
275
+
267
276
  [id="plugins-{type}s-{plugin}-options"]
268
- ==== Jdbc_static Filter Configuration Options
277
+ ==== Jdbc_static filter configuration options
269
278
 
270
279
  This plugin supports the following configuration options plus the <<plugins-{type}s-{plugin}-common-options>> described later.
271
280
 
@@ -162,8 +162,11 @@ module LogStash module Filters module Jdbc
162
162
  begin
163
163
  logger.debug? && logger.debug("Executing Jdbc query", :lookup_id => @id, :statement => query, :parameters => params)
164
164
  proc.call(local, query, params, result)
165
- rescue ::Sequel::Error => e
166
- # all sequel errors are a subclass of this, let all other standard or runtime errors bubble up
165
+ rescue => e
166
+ # In theory all exceptions in Sequel should be wrapped in Sequel::Error
167
+ # However, there are cases where other errors can occur - a `SQLTransactionRollbackException`
168
+ # may be thrown during `prepareStatement`. Let's handle these cases here, where we can tag and warn
169
+ # appropriately rather than bubble up and potentially crash the plugin.
167
170
  result.failed!
168
171
  logger.warn? && logger.warn("Exception when executing Jdbc query", :lookup_id => @id, :exception => e.message, :backtrace => e.backtrace.take(8))
169
172
  end
@@ -4,8 +4,11 @@ require "logstash/namespace"
4
4
  require "logstash/plugin_mixins/jdbc/common"
5
5
  require "logstash/plugin_mixins/jdbc/jdbc"
6
6
  require "logstash/plugin_mixins/ecs_compatibility_support"
7
+ require "logstash/plugin_mixins/ecs_compatibility_support/target_check"
7
8
  require "logstash/plugin_mixins/validator_support/field_reference_validation_adapter"
8
9
 
10
+ require "logstash/plugin_mixins/event_support/event_factory_adapter"
11
+
9
12
  # this require_relative returns early unless the JRuby version is between 9.2.0.0 and 9.2.8.0
10
13
  require_relative "tzinfo_jruby_patch"
11
14
 
@@ -131,8 +134,14 @@ require_relative "tzinfo_jruby_patch"
131
134
  module LogStash module Inputs class Jdbc < LogStash::Inputs::Base
132
135
  include LogStash::PluginMixins::Jdbc::Common
133
136
  include LogStash::PluginMixins::Jdbc::Jdbc
137
+
134
138
  # adds ecs_compatibility config which could be :disabled or :v1
135
139
  include LogStash::PluginMixins::ECSCompatibilitySupport(:disabled,:v1,:v8 => :v1)
140
+ include LogStash::PluginMixins::ECSCompatibilitySupport::TargetCheck
141
+
142
+ # adds `event_factory` and `targeted_event_factory
143
+ include LogStash::PluginMixins::EventSupport::EventFactoryAdapter
144
+
136
145
  # adds :field_reference validator adapter
137
146
  extend LogStash::PluginMixins::ValidatorSupport::FieldReferenceValidationAdapter
138
147
 
@@ -270,13 +279,6 @@ module LogStash module Inputs class Jdbc < LogStash::Inputs::Base
270
279
  converters[encoding] = converter
271
280
  end
272
281
  end
273
-
274
- # target must be populated if ecs_compatibility is not :disabled
275
- if @target.nil? && ecs_compatibility != :disabled
276
- logger.info('ECS compatibility is enabled but no ``target`` option was specified, it is recommended'\
277
- ' to set the option to avoid potential schema conflicts (if your data is ECS compliant or'\
278
- ' non-conflicting feel free to ignore this message)')
279
- end
280
282
  end # def register
281
283
 
282
284
  # test injection points
@@ -335,12 +337,7 @@ module LogStash module Inputs class Jdbc < LogStash::Inputs::Base
335
337
  ## do the necessary conversions to string elements
336
338
  row = Hash[row.map { |k, v| [k.to_s, convert(k, v)] }]
337
339
  end
338
- if @target
339
- event = LogStash::Event.new
340
- event.set(@target, row)
341
- else
342
- event = LogStash::Event.new(row)
343
- end
340
+ event = targeted_event_factory.new_event(row)
344
341
  decorate(event)
345
342
  queue << event
346
343
  end
@@ -4,6 +4,8 @@ module LogStash module PluginMixins module Jdbc
4
4
 
5
5
  private
6
6
 
7
+ DRIVERS_LOADING_LOCK = java.util.concurrent.locks.ReentrantLock.new()
8
+
7
9
  def complete_sequel_opts(defaults = {})
8
10
  sequel_opts = @sequel_opts.
9
11
  map { |key,val| [key.is_a?(String) ? key.to_sym : key, val] }.
@@ -22,18 +24,25 @@ module LogStash module PluginMixins module Jdbc
22
24
  require "sequel"
23
25
  require "sequel/adapters/jdbc"
24
26
 
25
- load_driver_jars
27
+ # execute all the driver loading related duties in a serial fashion to avoid
28
+ # concurrency related problems with multiple pipelines and multiple drivers
29
+ DRIVERS_LOADING_LOCK.lock()
26
30
  begin
27
- @driver_impl = Sequel::JDBC.load_driver(@jdbc_driver_class)
28
- rescue Sequel::AdapterNotFound => e # Sequel::AdapterNotFound, "#{@jdbc_driver_class} not loaded"
29
- # fix this !!!
30
- message = if jdbc_driver_library_set?
31
- "Are you sure you've included the correct jdbc driver in :jdbc_driver_library?"
32
- else
33
- ":jdbc_driver_library is not set, are you sure you included " +
34
- "the proper driver client libraries in your classpath?"
35
- end
36
- raise LogStash::PluginLoadingError, "#{e}. #{message}"
31
+ load_driver_jars
32
+ begin
33
+ @driver_impl = Sequel::JDBC.load_driver(@jdbc_driver_class)
34
+ rescue Sequel::AdapterNotFound => e # Sequel::AdapterNotFound, "#{@jdbc_driver_class} not loaded"
35
+ # fix this !!!
36
+ message = if jdbc_driver_library_set?
37
+ "Are you sure you've included the correct jdbc driver in :jdbc_driver_library?"
38
+ else
39
+ ":jdbc_driver_library is not set, are you sure you included " +
40
+ "the proper driver client libraries in your classpath?"
41
+ end
42
+ raise LogStash::PluginLoadingError, "#{e}. #{message} #{e.backtrace}"
43
+ end
44
+ ensure
45
+ DRIVERS_LOADING_LOCK.unlock()
37
46
  end
38
47
  end
39
48
 
@@ -119,8 +119,7 @@ module LogStash module PluginMixins module Jdbc
119
119
  else
120
120
  @logger.error("Failed to connect to database. #{@jdbc_pool_timeout} second timeout exceeded. Trying again.")
121
121
  end
122
- # rescue Java::JavaSql::SQLException, ::Sequel::Error => e
123
- rescue ::Sequel::Error => e
122
+ rescue Java::JavaSql::SQLException, ::Sequel::Error => e
124
123
  if retry_attempts <= 0
125
124
  log_java_exception(e.cause)
126
125
  @logger.error("Unable to connect to database. Tried #{@connection_retry_attempts} times", error_details(e, trace: true))
@@ -38,8 +38,11 @@ module LogStash module PluginMixins module JdbcStreaming
38
38
  begin
39
39
  logger.debug? && logger.debug("Executing JDBC query", :statement => statement, :parameters => params)
40
40
  execute_extract_records(db, params, result)
41
- rescue ::Sequel::Error => e
42
- # all sequel errors are a subclass of this, let all other standard or runtime errors bubble up
41
+ rescue => e
42
+ # In theory all exceptions in Sequel should be wrapped in Sequel::Error
43
+ # However, there are cases where other errors can occur - a `SQLException`may be thrown
44
+ # during `prepareStatement`. Let's handle these cases here, where we can tag and warn
45
+ # appropriately rather than bubble up and potentially crash the plugin.
43
46
  result.failed!
44
47
  logger.warn? && logger.warn("Exception when executing JDBC query", :statement => statement, :parameters => params, :exception => e)
45
48
  end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'logstash-integration-jdbc'
3
- s.version = '5.1.2'
3
+ s.version = '5.1.6'
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"
@@ -36,8 +36,9 @@ Gem::Specification.new do |s|
36
36
  s.add_runtime_dependency 'tzinfo-data'
37
37
  # 3.5 limitation is required for jdbc-static loading schedule
38
38
  s.add_runtime_dependency 'rufus-scheduler', '< 3.5'
39
- s.add_runtime_dependency 'logstash-mixin-ecs_compatibility_support', '~>1.2'
39
+ s.add_runtime_dependency 'logstash-mixin-ecs_compatibility_support', '~>1.3'
40
40
  s.add_runtime_dependency "logstash-mixin-validator_support", '~> 1.0'
41
+ s.add_runtime_dependency "logstash-mixin-event_support", '~> 1.0'
41
42
 
42
43
  s.add_development_dependency "childprocess"
43
44
  s.add_development_dependency 'logstash-devutils'
@@ -249,6 +249,41 @@ module LogStash module Filters module Jdbc
249
249
  end
250
250
  end
251
251
 
252
+ describe "lookup operations when prepareStatement throws" do
253
+ let(:local_db) { double("local_db") }
254
+ let(:lookup_hash) do
255
+ {
256
+ "query" => "select * from servers WHERE ip LIKE ? AND os LIKE ?",
257
+ "prepared_parameters" => ["%%{[ip]}"],
258
+ "target" => "server",
259
+ "tag_on_failure" => ["_jdbcstaticfailure_server"]
260
+ }
261
+ end
262
+ let(:event) { LogStash::Event.new()}
263
+ let(:records) { [{"name" => "ldn-1-23", "rack" => "2:1:6"}] }
264
+ let(:prepared_statement) { double("prepared_statement")}
265
+
266
+ subject(:lookup) { described_class.new(lookup_hash, {}, "lookup-1") }
267
+
268
+ before(:each) do
269
+ allow(local_db).to receive(:prepare).once.and_return(prepared_statement)
270
+ allow(prepared_statement).to receive(:call).once.and_raise(Java::JavaSql::SQLTransactionRollbackException.new)
271
+ end
272
+
273
+ it "must not be valid" do
274
+ expect(subject.valid?).to be_falsey
275
+ end
276
+
277
+ it "should tag event as failed" do
278
+ event.set("ip", "20.20")
279
+ event.set("os", "MacOS")
280
+ subject.prepare(local_db)
281
+ subject.enhance(local_db, event)
282
+ expect(event.get("tags")).to eq(["_jdbcstaticfailure_server"])
283
+ expect(event.get("server")).to be_nil
284
+ end
285
+ end
286
+
252
287
  describe "validation of target option" do
253
288
  let(:lookup_hash) do
254
289
  {
@@ -364,7 +364,7 @@ describe LogStash::Inputs::Jdbc do
364
364
  end
365
365
 
366
366
  it "should log a warn of missed target usage" do
367
- expect(plugin.logger).to receive(:info).once.with(/ECS compatibility is enabled but no .*?target.*? was specified/)
367
+ expect(plugin.logger).to receive(:info).once.with(a_string_including("ECS compatibility is enabled").and(including("target")))
368
368
 
369
369
  plugin.register
370
370
  end
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.1.2
4
+ version: 5.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elastic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-06-28 00:00:00.000000000 Z
11
+ date: 2021-10-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -147,7 +147,7 @@ dependencies:
147
147
  requirements:
148
148
  - - "~>"
149
149
  - !ruby/object:Gem::Version
150
- version: '1.2'
150
+ version: '1.3'
151
151
  name: logstash-mixin-ecs_compatibility_support
152
152
  prerelease: false
153
153
  type: :runtime
@@ -155,7 +155,7 @@ dependencies:
155
155
  requirements:
156
156
  - - "~>"
157
157
  - !ruby/object:Gem::Version
158
- version: '1.2'
158
+ version: '1.3'
159
159
  - !ruby/object:Gem::Dependency
160
160
  requirement: !ruby/object:Gem::Requirement
161
161
  requirements:
@@ -170,6 +170,20 @@ dependencies:
170
170
  - - "~>"
171
171
  - !ruby/object:Gem::Version
172
172
  version: '1.0'
173
+ - !ruby/object:Gem::Dependency
174
+ requirement: !ruby/object:Gem::Requirement
175
+ requirements:
176
+ - - "~>"
177
+ - !ruby/object:Gem::Version
178
+ version: '1.0'
179
+ name: logstash-mixin-event_support
180
+ prerelease: false
181
+ type: :runtime
182
+ version_requirements: !ruby/object:Gem::Requirement
183
+ requirements:
184
+ - - "~>"
185
+ - !ruby/object:Gem::Version
186
+ version: '1.0'
173
187
  - !ruby/object:Gem::Dependency
174
188
  requirement: !ruby/object:Gem::Requirement
175
189
  requirements:
@@ -318,8 +332,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
318
332
  - !ruby/object:Gem::Version
319
333
  version: '0'
320
334
  requirements: []
321
- rubyforge_project:
322
- rubygems_version: 2.6.13
335
+ rubygems_version: 3.1.6
323
336
  signing_key:
324
337
  specification_version: 4
325
338
  summary: Integration with JDBC - input and filter plugins