logstash-integration-jdbc 5.1.4 → 5.1.8

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: 624847dd498ef4c1cabb3623b33d6caae518d482b5e6cdab4d7aa97f79e9a0bf
4
- data.tar.gz: 7fc2d7f3ebb36aa50db73c074c2f3b183f7378089a35d49bf9e581617c765cb7
3
+ metadata.gz: 70e445fd000df9ba4c631d3574d67826aaafcb22bb2b4c00f9e30aa386415ed0
4
+ data.tar.gz: 2fc2cef288fa7fa2f342db6096e79e49617c012e5ce9f5c4a5d94cc1f79b0838
5
5
  SHA512:
6
- metadata.gz: d8d468fe9bd6c8d54f2aaffb17088bdc957d104e55c7b456f44afb8a581fe82dd7494ac18b768af575a95d634dc887615035be0f4a3a68261394a20254db47e6
7
- data.tar.gz: b252ac776f43ea2d2a3db414d5e787fc1e8f480aeeaf73f81513ecee8c207851d7d557a9fa7878c1a9db6105891b05056f47ead3d7dddd23f49eedfcdd3a8497
6
+ metadata.gz: e9fd72a1ebd12db838330101716032fbe125a9dab866bd552e61eeca37d51222f1f22e29cb8cdcc1b27bba8d1e5b59e8ff22de6aba29587e3811543a23860e79
7
+ data.tar.gz: ae0322899fdbc65f3be931f1e2fbc2cbb82ac7d3e9980c1aa1a404085a0d4e7218944567e4750260fd638506e6f43dceb6a477c4762fe856d3c262e152988920
data/CHANGELOG.md CHANGED
@@ -1,12 +1,26 @@
1
+ ## 5.1.8
2
+ - Fix the blocking pipeline reload and shutdown when connectivity issues happen [#85](https://github.com/logstash-plugins/logstash-integration-jdbc/pull/85)
3
+
4
+ ## 5.1.7
5
+ - Normalize jdbc_driver_class loading to support any top-level java packages [#86](https://github.com/logstash-plugins/logstash-integration-jdbc/pull/86)
6
+
7
+ ## 5.1.6
8
+ - Fix, serialize the JDBC driver loading steps to avoid concurrency issues [#84](https://github.com/logstash-plugins/logstash-integration-jdbc/pull/84)
9
+
10
+ ## 5.1.5
11
+ - Refined ECS support [#82](https://github.com/logstash-plugins/logstash-integration-jdbc/pull/82)
12
+ - Uses shared `target` guidance when ECS compatibility is enabled
13
+ - Uses Logstash's EventFactory instead of instantiating events directly
14
+
1
15
  ## 5.1.4
2
16
  - [DOC] Update filter-jdbc_static doc to describe ECS compatibility [#79](https://github.com/logstash-plugins/logstash-integration-jdbc/pull/79)
3
17
 
4
18
  ## 5.1.3
5
19
  - Improve robustness when handling errors from `sequel` library in jdbc static and streaming
6
- filters[#78](https://github.com/logstash-plugins/logstash-integration-jdbc/pull/78)
20
+ filters [#78](https://github.com/logstash-plugins/logstash-integration-jdbc/pull/78)
7
21
 
8
22
  ## 5.1.2
9
- - 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)
23
+ - 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)
10
24
 
11
25
  ## 5.1.1
12
26
  - [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).
@@ -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(normalized_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
 
@@ -62,5 +71,16 @@ module LogStash module PluginMixins module Jdbc
62
71
  !@jdbc_driver_library.nil? && !@jdbc_driver_library.empty?
63
72
  end
64
73
 
74
+ # normalizing the class name to always have a Java:: prefix
75
+ # is helpful since JRuby is only able to directly load class names
76
+ # whose top-level package is com, org, java, javax
77
+ # There are many jdbc drivers that use cc, io, net, etc.
78
+ def normalized_driver_class
79
+ if @jdbc_driver_class.start_with?("Java::", "Java.")
80
+ @jdbc_driver_class
81
+ else
82
+ "Java::#{@jdbc_driver_class}"
83
+ end
84
+ end
65
85
  end
66
86
  end end end
@@ -168,8 +168,6 @@ module LogStash module PluginMixins module Jdbc
168
168
  @logger.warn("Failed test_connection with java.sql.SQLException.", :exception => e)
169
169
  rescue Sequel::DatabaseConnectionError => e
170
170
  @logger.warn("Failed test_connection.", :exception => e)
171
- close_jdbc_connection
172
-
173
171
  #TODO return false and let the plugin raise a LogStash::ConfigurationError
174
172
  raise e
175
173
  end
@@ -208,9 +206,9 @@ module LogStash module PluginMixins module Jdbc
208
206
  public
209
207
  def execute_statement
210
208
  success = false
211
- @connection_lock.lock
212
- open_jdbc_connection
213
209
  begin
210
+ @connection_lock.lock
211
+ open_jdbc_connection
214
212
  sql_last_value = @use_column_value ? @value_tracker.value : Time.now.utc
215
213
  @tracking_column_warning_sent = false
216
214
  @statement_handler.perform_query(@database, @value_tracker.value, @jdbc_paging_enabled, @jdbc_page_size) do |row|
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'logstash-integration-jdbc'
3
- s.version = '5.1.4'
3
+ s.version = '5.1.8'
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,11 +36,12 @@ 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
- s.add_development_dependency 'logstash-devutils'
44
+ s.add_development_dependency 'logstash-devutils', '>= 2.3'
44
45
  s.add_development_dependency 'timecop'
45
46
  s.add_development_dependency 'jdbc-derby'
46
47
  end
@@ -66,13 +66,13 @@ describe LogStash::Inputs::Jdbc, :integration => true do
66
66
  )
67
67
  end
68
68
 
69
- it "should not register correctly" do
69
+ it "log warning msg when plugin run" do
70
70
  plugin.register
71
- allow( plugin ).to receive(:log_java_exception)
71
+ expect( plugin ).to receive(:log_java_exception)
72
+ expect(plugin.logger).to receive(:warn).once.with("Exception when executing JDBC query",
73
+ hash_including(:exception => instance_of(String)))
72
74
  q = Queue.new
73
- expect do
74
- plugin.run(q)
75
- end.to raise_error(::Sequel::DatabaseConnectionError)
75
+ expect{ plugin.run(q) }.not_to raise_error
76
76
  end
77
77
 
78
78
  it "should log (native) Java driver error" do
@@ -85,9 +85,7 @@ describe LogStash::Inputs::Jdbc, :integration => true do
85
85
  logger
86
86
  end
87
87
  q = Queue.new
88
- expect do
89
- plugin.run(q)
90
- end.to raise_error(::Sequel::DatabaseConnectionError)
88
+ expect{ plugin.run(q) }.not_to raise_error
91
89
  end
92
90
  end
93
91
  end
@@ -14,10 +14,11 @@ require "date"
14
14
 
15
15
  describe LogStash::Inputs::Jdbc do
16
16
  let(:connection_string) { "jdbc:derby:memory:testdb;create=true" }
17
+ let(:jdbc_driver_class) { "org.apache.derby.jdbc.EmbeddedDriver" }
17
18
  let(:mixin_settings) do
18
19
  {
19
20
  "jdbc_user" => ENV['USER'],
20
- "jdbc_driver_class" => "org.apache.derby.jdbc.EmbeddedDriver",
21
+ "jdbc_driver_class" => jdbc_driver_class,
21
22
  "jdbc_connection_string" => connection_string
22
23
  }
23
24
  end
@@ -364,7 +365,7 @@ describe LogStash::Inputs::Jdbc do
364
365
  end
365
366
 
366
367
  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/)
368
+ expect(plugin.logger).to receive(:info).once.with(a_string_including("ECS compatibility is enabled").and(including("target")))
368
369
 
369
370
  plugin.register
370
371
  end
@@ -1392,10 +1393,8 @@ describe LogStash::Inputs::Jdbc do
1392
1393
  event = queue.pop
1393
1394
  expect(event.get("num")).to eq(1)
1394
1395
  expect(event.get("string")).to eq("A test")
1395
- expect(event.get("started_at")).to be_a(LogStash::Timestamp)
1396
- expect(event.get("started_at").to_s).to eq("1999-12-31T00:00:00.000Z")
1397
- expect(event.get("custom_time")).to be_a(LogStash::Timestamp)
1398
- expect(event.get("custom_time").to_s).to eq("1999-12-31T23:59:59.000Z")
1396
+ expect(event.get("started_at")).to be_a_logstash_timestamp_equivalent_to("1999-12-31T00:00:00.000Z")
1397
+ expect(event.get("custom_time")).to be_a_logstash_timestamp_equivalent_to("1999-12-31T23:59:59.000Z")
1399
1398
  expect(event.get("ranking").to_f).to eq(95.67)
1400
1399
  end
1401
1400
  end
@@ -1441,10 +1440,8 @@ describe LogStash::Inputs::Jdbc do
1441
1440
  event = queue.pop
1442
1441
  expect(event.get("num")).to eq(1)
1443
1442
  expect(event.get("string")).to eq("A test")
1444
- expect(event.get("started_at")).to be_a(LogStash::Timestamp)
1445
- expect(event.get("started_at").to_s).to eq("1999-12-31T00:00:00.000Z")
1446
- expect(event.get("custom_time")).to be_a(LogStash::Timestamp)
1447
- expect(event.get("custom_time").to_s).to eq("1999-12-31T23:59:59.000Z")
1443
+ expect(event.get("started_at")).to be_a_logstash_timestamp_equivalent_to("1999-12-31T00:00:00.000Z")
1444
+ expect(event.get("custom_time")).to be_a_logstash_timestamp_equivalent_to("1999-12-31T23:59:59.000Z")
1448
1445
  expect(event.get("ranking").to_f).to eq(95.67)
1449
1446
  end
1450
1447
  end
@@ -1619,4 +1616,21 @@ describe LogStash::Inputs::Jdbc do
1619
1616
  end
1620
1617
  end
1621
1618
  end
1619
+
1620
+ describe "jdbc_driver_class" do
1621
+ context "when not prefixed with Java::" do
1622
+ let(:jdbc_driver_class) { "org.apache.derby.jdbc.EmbeddedDriver" }
1623
+ it "loads the class prefixed with Java::" do
1624
+ expect(Sequel::JDBC).to receive(:load_driver).with(/^Java::/)
1625
+ plugin.send(:load_driver)
1626
+ end
1627
+ end
1628
+ context "when prefixed with Java::" do
1629
+ let(:jdbc_driver_class) { "Java::org.apache.derby.jdbc.EmbeddedDriver" }
1630
+ it "loads the class as-is" do
1631
+ expect(Sequel::JDBC).to receive(:load_driver).with(jdbc_driver_class)
1632
+ plugin.send(:load_driver)
1633
+ end
1634
+ end
1635
+ end
1622
1636
  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.4
4
+ version: 5.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elastic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-07-09 00:00:00.000000000 Z
11
+ date: 2021-11-02 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:
@@ -189,7 +203,7 @@ dependencies:
189
203
  requirements:
190
204
  - - ">="
191
205
  - !ruby/object:Gem::Version
192
- version: '0'
206
+ version: '2.3'
193
207
  name: logstash-devutils
194
208
  prerelease: false
195
209
  type: :development
@@ -197,7 +211,7 @@ dependencies:
197
211
  requirements:
198
212
  - - ">="
199
213
  - !ruby/object:Gem::Version
200
- version: '0'
214
+ version: '2.3'
201
215
  - !ruby/object:Gem::Dependency
202
216
  requirement: !ruby/object:Gem::Requirement
203
217
  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