logstash-integration-jdbc 5.1.5 → 5.1.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +19 -0
- data/lib/logstash/plugin_mixins/jdbc/common.rb +34 -11
- data/lib/logstash/plugin_mixins/jdbc/jdbc.rb +2 -4
- data/logstash-integration-jdbc.gemspec +2 -2
- data/spec/inputs/integration/integ_spec.rb +6 -8
- data/spec/inputs/jdbc_spec.rb +42 -9
- metadata +4 -5
- data/NOTICE.TXT +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9f3116d5abaa413fd73af725208c422a1cf98961ce7095c4d88fd7f14cb6c59d
|
4
|
+
data.tar.gz: 0ef2f5fd309236b8ec0e14bb38d275e26b3d2002cdb172a2d30d53682606ddec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d701317b4edbe221b2dd9a66d6e2591a0a78e8b9502373860656a5d95f552eee06ae752904687b58b2dfda274dc7c20e5da3e5bebbefbd98c538c107f49bec7a
|
7
|
+
data.tar.gz: 22a9383f113f01025ba2f694cd61845aa4ed08474efc70cb37694993babb9ec7d6ac3d95291bbf2fe5b22835a8923ab1802061d861da2e59d5b0e3041f7b18ed
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,22 @@
|
|
1
|
+
## 5.1.10
|
2
|
+
- Refactor: to explicit Java (driver) class name loading [#96](https://github.com/logstash-plugins/logstash-integration-jdbc/pull/96),
|
3
|
+
the change is expected to provide a more robust fix for the driver loading issue [#83](https://github.com/logstash-plugins/logstash-integration-jdbc/issues/83).
|
4
|
+
|
5
|
+
- Fix: regression due returning the Java driver class [#98](https://github.com/logstash-plugins/logstash-integration-jdbc/pull/98)
|
6
|
+
|
7
|
+
## 5.1.9 (yanked)
|
8
|
+
- Refactor: to explicit Java (driver) class name loading [#96](https://github.com/logstash-plugins/logstash-integration-jdbc/pull/96),
|
9
|
+
the change is expected to provide a more robust fix for the driver loading issue [#83](https://github.com/logstash-plugins/logstash-integration-jdbc/issues/83).
|
10
|
+
|
11
|
+
## 5.1.8
|
12
|
+
- Fix the blocking pipeline reload and shutdown when connectivity issues happen [#85](https://github.com/logstash-plugins/logstash-integration-jdbc/pull/85)
|
13
|
+
|
14
|
+
## 5.1.7
|
15
|
+
- Normalize jdbc_driver_class loading to support any top-level java packages [#86](https://github.com/logstash-plugins/logstash-integration-jdbc/pull/86)
|
16
|
+
|
17
|
+
## 5.1.6
|
18
|
+
- Fix, serialize the JDBC driver loading steps to avoid concurrency issues [#84](https://github.com/logstash-plugins/logstash-integration-jdbc/pull/84)
|
19
|
+
|
1
20
|
## 5.1.5
|
2
21
|
- Refined ECS support [#82](https://github.com/logstash-plugins/logstash-integration-jdbc/pull/82)
|
3
22
|
- Uses shared `target` guidance when ECS compatibility is enabled
|
@@ -1,9 +1,14 @@
|
|
1
|
+
require 'jruby'
|
1
2
|
|
2
3
|
module LogStash module PluginMixins module Jdbc
|
3
4
|
module Common
|
4
5
|
|
5
6
|
private
|
6
7
|
|
8
|
+
# NOTE: using the JRuby mechanism to load classes (through JavaSupport)
|
9
|
+
# makes the lock redundant although it does not hurt to have it around.
|
10
|
+
DRIVERS_LOADING_LOCK = java.util.concurrent.locks.ReentrantLock.new()
|
11
|
+
|
7
12
|
def complete_sequel_opts(defaults = {})
|
8
13
|
sequel_opts = @sequel_opts.
|
9
14
|
map { |key,val| [key.is_a?(String) ? key.to_sym : key, val] }.
|
@@ -22,18 +27,25 @@ module LogStash module PluginMixins module Jdbc
|
|
22
27
|
require "sequel"
|
23
28
|
require "sequel/adapters/jdbc"
|
24
29
|
|
25
|
-
|
30
|
+
# execute all the driver loading related duties in a serial fashion to avoid
|
31
|
+
# concurrency related problems with multiple pipelines and multiple drivers
|
32
|
+
DRIVERS_LOADING_LOCK.lock()
|
26
33
|
begin
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
34
|
+
load_driver_jars
|
35
|
+
begin
|
36
|
+
@driver_impl = load_jdbc_driver_class
|
37
|
+
rescue => e # catch java.lang.ClassNotFoundException, potential errors
|
38
|
+
# (e.g. ExceptionInInitializerError or LinkageError) won't get caught
|
39
|
+
message = if jdbc_driver_library_set?
|
40
|
+
"Are you sure you've included the correct jdbc driver in :jdbc_driver_library?"
|
41
|
+
else
|
42
|
+
":jdbc_driver_library is not set, are you sure you included " +
|
43
|
+
"the proper driver client libraries in your classpath?"
|
44
|
+
end
|
45
|
+
raise LogStash::PluginLoadingError, "#{e.inspect}. #{message}"
|
46
|
+
end
|
47
|
+
ensure
|
48
|
+
DRIVERS_LOADING_LOCK.unlock()
|
37
49
|
end
|
38
50
|
end
|
39
51
|
|
@@ -62,5 +74,16 @@ module LogStash module PluginMixins module Jdbc
|
|
62
74
|
!@jdbc_driver_library.nil? && !@jdbc_driver_library.empty?
|
63
75
|
end
|
64
76
|
|
77
|
+
def load_jdbc_driver_class
|
78
|
+
# sub a potential: 'Java::org::my.Driver' to 'org.my.Driver'
|
79
|
+
klass = @jdbc_driver_class.gsub('::', '.').sub(/^Java\./, '')
|
80
|
+
# NOTE: JRuby's Java::JavaClass.for_name which considers the custom class-loader(s)
|
81
|
+
# in 9.3 the API changed and thus to avoid surprises we go down to the Java API :
|
82
|
+
klass = JRuby.runtime.getJavaSupport.loadJavaClass(klass) # throws ClassNotFoundException
|
83
|
+
# unfortunately we can not simply return the wrapped java.lang.Class instance as
|
84
|
+
# Sequel assumes to be able to do a `driver_class.new` which only works on the proxy,
|
85
|
+
org.jruby.javasupport.Java.getProxyClass(JRuby.runtime, klass)
|
86
|
+
end
|
87
|
+
|
65
88
|
end
|
66
89
|
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.
|
3
|
+
s.version = '5.1.10'
|
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"
|
@@ -41,7 +41,7 @@ Gem::Specification.new do |s|
|
|
41
41
|
s.add_runtime_dependency "logstash-mixin-event_support", '~> 1.0'
|
42
42
|
|
43
43
|
s.add_development_dependency "childprocess"
|
44
|
-
s.add_development_dependency 'logstash-devutils'
|
44
|
+
s.add_development_dependency 'logstash-devutils', '>= 2.3'
|
45
45
|
s.add_development_dependency 'timecop'
|
46
46
|
s.add_development_dependency 'jdbc-derby'
|
47
47
|
end
|
@@ -66,13 +66,13 @@ describe LogStash::Inputs::Jdbc, :integration => true do
|
|
66
66
|
)
|
67
67
|
end
|
68
68
|
|
69
|
-
it "
|
69
|
+
it "log warning msg when plugin run" do
|
70
70
|
plugin.register
|
71
|
-
|
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
|
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
|
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
|
data/spec/inputs/jdbc_spec.rb
CHANGED
@@ -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" =>
|
21
|
+
"jdbc_driver_class" => jdbc_driver_class,
|
21
22
|
"jdbc_connection_string" => connection_string
|
22
23
|
}
|
23
24
|
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
|
1396
|
-
expect(event.get("
|
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
|
1445
|
-
expect(event.get("
|
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,40 @@ 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" do
|
1624
|
+
expect { plugin.send(:load_driver) }.not_to raise_error
|
1625
|
+
end
|
1626
|
+
end
|
1627
|
+
context "when prefixed with Java::" do
|
1628
|
+
let(:jdbc_driver_class) { "Java::org.apache.derby.jdbc.EmbeddedDriver" }
|
1629
|
+
it "loads the class" do
|
1630
|
+
expect { plugin.send(:load_driver) }.not_to raise_error
|
1631
|
+
end
|
1632
|
+
end
|
1633
|
+
context "when prefixed with Java." do
|
1634
|
+
let(:jdbc_driver_class) { "Java.org::apache::derby::jdbc.EmbeddedDriver" }
|
1635
|
+
it "loads the class" do
|
1636
|
+
expect { plugin.send(:load_driver) }.not_to raise_error
|
1637
|
+
end
|
1638
|
+
|
1639
|
+
it "can instantiate the returned driver class" do
|
1640
|
+
# for drivers where the path through DriverManager fails, Sequel assumes
|
1641
|
+
# having a proxied Java class instance (instead of a java.lang.Class) and
|
1642
|
+
# does a driver.new.connect https://git.io/JDV6M
|
1643
|
+
driver = plugin.send(:load_driver)
|
1644
|
+
expect { driver.new }.not_to raise_error
|
1645
|
+
end
|
1646
|
+
end
|
1647
|
+
context "when class name invalid" do
|
1648
|
+
let(:jdbc_driver_class) { "org.apache.NonExistentDriver" }
|
1649
|
+
it "raises a loading error" do
|
1650
|
+
expect { plugin.send(:load_driver) }.to raise_error LogStash::PluginLoadingError,
|
1651
|
+
/java.lang.ClassNotFoundException: org.apache.NonExistentDriver/
|
1652
|
+
end
|
1653
|
+
end
|
1654
|
+
end
|
1622
1655
|
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
|
+
version: 5.1.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Elastic
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-12-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|
@@ -203,7 +203,7 @@ dependencies:
|
|
203
203
|
requirements:
|
204
204
|
- - ">="
|
205
205
|
- !ruby/object:Gem::Version
|
206
|
-
version: '
|
206
|
+
version: '2.3'
|
207
207
|
name: logstash-devutils
|
208
208
|
prerelease: false
|
209
209
|
type: :development
|
@@ -211,7 +211,7 @@ dependencies:
|
|
211
211
|
requirements:
|
212
212
|
- - ">="
|
213
213
|
- !ruby/object:Gem::Version
|
214
|
-
version: '
|
214
|
+
version: '2.3'
|
215
215
|
- !ruby/object:Gem::Dependency
|
216
216
|
requirement: !ruby/object:Gem::Requirement
|
217
217
|
requirements:
|
@@ -252,7 +252,6 @@ files:
|
|
252
252
|
- CONTRIBUTORS
|
253
253
|
- Gemfile
|
254
254
|
- LICENSE
|
255
|
-
- NOTICE.TXT
|
256
255
|
- README.md
|
257
256
|
- docs/filter-jdbc_static.asciidoc
|
258
257
|
- docs/filter-jdbc_streaming.asciidoc
|