logstash-integration-jdbc 5.0.0 → 5.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/docs/input-jdbc.asciidoc +1 -0
- data/lib/logstash/inputs/jdbc.rb +1 -0
- data/lib/logstash/plugin_mixins/jdbc/jdbc.rb +39 -28
- data/lib/logstash/plugin_mixins/jdbc/value_tracking.rb +1 -1
- data/logstash-integration-jdbc.gemspec +1 -1
- data/spec/inputs/jdbc_spec.rb +85 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a71840d1b072e13fc4ddcc96cee6a6f68e8c12608167a138858c147c11795509
|
4
|
+
data.tar.gz: e782665b9e41de726ccf59e6110d7f2f77fc49127ce4bfe6c5bf16683ab2ffb2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9166b1b3b4e0d461da084d78e5f69ad12ea07d33d61331520bfe755f920df5c406e414f9c60d2209e2432237c6842b1a627b2a852a91cfc250fa4fee0b934f70
|
7
|
+
data.tar.gz: 906d918fd928c2263ec6f1497d7995e7c0f6d9caa8044e23dcc2f8cb020c44c3c83372ed1cf808f3ee86aea33529d7b4378df778fa908ca2c5a97814e45df817
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
## 5.0.1
|
2
|
+
- Fixed tracking_column regression with Postgresql Numeric types [#17](https://github.com/logstash-plugins/logstash-integration-jdbc/pull/17)
|
3
|
+
- Fixed driver loading when file not accessible [#15](https://github.com/logstash-plugins/logstash-integration-jdbc/pull/15)
|
4
|
+
|
1
5
|
## 5.0.0
|
2
6
|
- 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
7
|
[logstash-filter-jdbc_static](https://github.com/logstash-plugins/logstash-filter-jdbc_static)
|
data/docs/input-jdbc.asciidoc
CHANGED
@@ -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`
|
data/lib/logstash/inputs/jdbc.rb
CHANGED
@@ -139,47 +139,58 @@ module LogStash module PluginMixins module Jdbc
|
|
139
139
|
|
140
140
|
private
|
141
141
|
|
142
|
+
def load_driver
|
143
|
+
if @drivers_loaded.false?
|
144
|
+
require "java"
|
145
|
+
require "sequel"
|
146
|
+
require "sequel/adapters/jdbc"
|
147
|
+
|
148
|
+
load_driver_jars
|
149
|
+
begin
|
150
|
+
Sequel::JDBC.load_driver(@jdbc_driver_class)
|
151
|
+
rescue Sequel::AdapterNotFound => e # Sequel::AdapterNotFound, "#{@jdbc_driver_class} not loaded"
|
152
|
+
# fix this !!!
|
153
|
+
message = if jdbc_driver_library_set?
|
154
|
+
"Are you sure you've included the correct jdbc driver in :jdbc_driver_library?"
|
155
|
+
else
|
156
|
+
":jdbc_driver_library is not set, are you sure you included " +
|
157
|
+
"the proper driver client libraries in your classpath?"
|
158
|
+
end
|
159
|
+
raise LogStash::PluginLoadingError, "#{e}. #{message}"
|
160
|
+
end
|
161
|
+
@drivers_loaded.make_true
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
142
165
|
def load_driver_jars
|
143
|
-
|
166
|
+
if jdbc_driver_library_set?
|
144
167
|
@jdbc_driver_library.split(",").each do |driver_jar|
|
168
|
+
@logger.debug("loading #{driver_jar}")
|
169
|
+
# load 'driver.jar' is different than load 'some.rb' as it only causes the file to be added to
|
170
|
+
# JRuby's class-loader lookup (class) path - won't raise a LoadError when file is not readable
|
171
|
+
unless FileTest.readable?(driver_jar)
|
172
|
+
raise LogStash::PluginLoadingError, "unable to load #{driver_jar} from :jdbc_driver_library, " +
|
173
|
+
"file not readable (please check user and group permissions for the path)"
|
174
|
+
end
|
145
175
|
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
176
|
require driver_jar
|
150
177
|
rescue LoadError => e
|
151
178
|
raise LogStash::PluginLoadingError, "unable to load #{driver_jar} from :jdbc_driver_library, #{e.message}"
|
179
|
+
rescue StandardError => e
|
180
|
+
raise LogStash::PluginLoadingError, "unable to load #{driver_jar} from :jdbc_driver_library, #{e}"
|
152
181
|
end
|
153
182
|
end
|
154
183
|
end
|
155
184
|
end
|
156
185
|
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
require "sequel"
|
161
|
-
require "sequel/adapters/jdbc"
|
186
|
+
def jdbc_driver_library_set?
|
187
|
+
!@jdbc_driver_library.nil? && !@jdbc_driver_library.empty?
|
188
|
+
end
|
162
189
|
|
190
|
+
def open_jdbc_connection
|
191
|
+
# at this point driver is already loaded
|
163
192
|
Sequel.application_timezone = @plugin_timezone.to_sym
|
164
|
-
|
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
|
193
|
+
|
183
194
|
@database = jdbc_connect()
|
184
195
|
@database.extension(:pagination)
|
185
196
|
if @jdbc_default_timezone
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'logstash-integration-jdbc'
|
3
|
-
s.version = '5.0.
|
3
|
+
s.version = '5.0.1'
|
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"
|
data/spec/inputs/jdbc_spec.rb
CHANGED
@@ -28,10 +28,11 @@ describe LogStash::Inputs::Jdbc do
|
|
28
28
|
# before body
|
29
29
|
Jdbc::Derby.load_driver
|
30
30
|
db.create_table :test_table do
|
31
|
-
DateTime
|
32
|
-
|
33
|
-
|
34
|
-
|
31
|
+
DateTime :created_at
|
32
|
+
BigDecimal :big_num
|
33
|
+
Integer :num
|
34
|
+
String :string
|
35
|
+
DateTime :custom_time
|
35
36
|
end
|
36
37
|
db << "CREATE TABLE types_table (num INTEGER, string VARCHAR(255), started_at DATE, custom_time TIMESTAMP, ranking DECIMAL(16,6))"
|
37
38
|
db << "CREATE TABLE test1_table (num INTEGER, string VARCHAR(255), custom_time TIMESTAMP, created_at TIMESTAMP)"
|
@@ -545,6 +546,54 @@ describe LogStash::Inputs::Jdbc do
|
|
545
546
|
end
|
546
547
|
end
|
547
548
|
|
549
|
+
context "Test Sql Last Value with a BigDecimal `sqlLastValue`" do
|
550
|
+
let(:mixin_settings) do
|
551
|
+
{ "jdbc_user" => ENV['USER'], "jdbc_driver_class" => "org.apache.derby.jdbc.EmbeddedDriver",
|
552
|
+
"jdbc_connection_string" => "jdbc:derby:memory:testdb;create=true"
|
553
|
+
}
|
554
|
+
end
|
555
|
+
|
556
|
+
let(:settings) do
|
557
|
+
{ "statement" => "SELECT big_num, created_at FROM test_table WHERE big_num > :sql_last_value",
|
558
|
+
"use_column_value" => true,
|
559
|
+
"tracking_column" => "big_num",
|
560
|
+
"last_run_metadata_path" => Stud::Temporary.pathname }
|
561
|
+
end
|
562
|
+
|
563
|
+
let(:nums) { [BigDecimal.new(10), BigDecimal.new(20), BigDecimal.new(30), BigDecimal.new(40), BigDecimal.new(50)] }
|
564
|
+
|
565
|
+
before do
|
566
|
+
plugin.register
|
567
|
+
end
|
568
|
+
|
569
|
+
after do
|
570
|
+
plugin.stop
|
571
|
+
end
|
572
|
+
|
573
|
+
it "should only pick up new values" do
|
574
|
+
test_table = db[:test_table]
|
575
|
+
|
576
|
+
plugin.run(queue)
|
577
|
+
expect(queue.size).to eq(0)
|
578
|
+
test_table.insert(:big_num => nums[0], :created_at => Time.now.utc)
|
579
|
+
test_table.insert(:big_num => nums[1], :created_at => Time.now.utc)
|
580
|
+
queue = []
|
581
|
+
# Stop and restart the plugin to have it read saved value of `sql_last_value`
|
582
|
+
plugin.stop
|
583
|
+
plugin.register
|
584
|
+
plugin.run(queue)
|
585
|
+
expect(queue.size).to eq(2)
|
586
|
+
test_table.insert(:big_num => nums[2], :created_at => Time.now.utc)
|
587
|
+
test_table.insert(:big_num => nums[3], :created_at => Time.now.utc)
|
588
|
+
test_table.insert(:big_num => nums[4], :created_at => Time.now.utc)
|
589
|
+
queue = []
|
590
|
+
plugin.stop
|
591
|
+
plugin.register
|
592
|
+
plugin.run(queue)
|
593
|
+
expect(queue.size).to eq(3)
|
594
|
+
end
|
595
|
+
end
|
596
|
+
|
548
597
|
context "when iteratively running plugin#run with timestamp tracking column with column value" do
|
549
598
|
let(:mixin_settings) do
|
550
599
|
{ "jdbc_user" => ENV['USER'], "jdbc_driver_class" => "org.apache.derby.jdbc.EmbeddedDriver",
|
@@ -1291,6 +1340,38 @@ describe LogStash::Inputs::Jdbc do
|
|
1291
1340
|
end
|
1292
1341
|
end
|
1293
1342
|
|
1343
|
+
context "when an unreadable jdbc_driver_path entry is present" do
|
1344
|
+
let(:driver_jar_path) do
|
1345
|
+
jar_file = $CLASSPATH.find { |name| name.index(Jdbc::Derby.driver_jar) }
|
1346
|
+
raise "derby jar not found on class-path" unless jar_file
|
1347
|
+
jar_file.sub('file:', '')
|
1348
|
+
end
|
1349
|
+
|
1350
|
+
let(:invalid_driver_jar_path) do
|
1351
|
+
path = File.join(Dir.mktmpdir, File.basename(driver_jar_path))
|
1352
|
+
FileUtils.cp driver_jar_path, path
|
1353
|
+
FileUtils.chmod "u=x,go=", path
|
1354
|
+
path
|
1355
|
+
end
|
1356
|
+
|
1357
|
+
let(:settings) do
|
1358
|
+
{ "statement" => "SELECT * from types_table", "jdbc_driver_library" => invalid_driver_jar_path }
|
1359
|
+
end
|
1360
|
+
|
1361
|
+
before do
|
1362
|
+
plugin.register
|
1363
|
+
end
|
1364
|
+
|
1365
|
+
after do
|
1366
|
+
plugin.stop
|
1367
|
+
end
|
1368
|
+
|
1369
|
+
it "raise a loading error" do
|
1370
|
+
expect { plugin.run(queue) }.
|
1371
|
+
to raise_error(LogStash::PluginLoadingError, /unable to load .*? from :jdbc_driver_library, file not readable/)
|
1372
|
+
end
|
1373
|
+
end
|
1374
|
+
|
1294
1375
|
context "when using prepared statements" do
|
1295
1376
|
let(:last_run_value) { 250 }
|
1296
1377
|
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.
|
4
|
+
version: 5.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Elastic
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-02-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|