logstash-input-jdbc 4.1.3 → 4.2.0
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 +6 -0
- data/lib/logstash/inputs/jdbc.rb +24 -8
- data/lib/logstash/plugin_mixins/jdbc.rb +18 -2
- data/logstash-input-jdbc.gemspec +1 -1
- data/spec/inputs/jdbc_spec.rb +24 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 985a22e0b06671dd557cc71e2174b39c654b15ee
|
4
|
+
data.tar.gz: 47347232f18c67f7f313814cb9663fcca0436d52
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6048835db426fc1aab07e4324b358cd39e5db309144b20a34a90372474a110543c681b98cc5563cc8bc1042277565ca1f26f1420e47bfdba8fe7f6dac9c68a89
|
7
|
+
data.tar.gz: 17751bc5af1d066c19eaa15d2ef81b84b6a7556b88a2a2371b358162ba68f52e6ae0430ae5835bbd61f386974482ce27dc6244e128092fd46094b8e7889de06b
|
data/CHANGELOG.md
CHANGED
data/lib/logstash/inputs/jdbc.rb
CHANGED
@@ -62,7 +62,7 @@ require "yaml" # persistence
|
|
62
62
|
# instruct the plugin to execute this input statement on the minute, every minute.
|
63
63
|
#
|
64
64
|
# [source,ruby]
|
65
|
-
#
|
65
|
+
# ------------------------------------------------------------------------------
|
66
66
|
# input {
|
67
67
|
# jdbc {
|
68
68
|
# jdbc_driver_library => "mysql-connector-java-5.1.36-bin.jar"
|
@@ -74,7 +74,7 @@ require "yaml" # persistence
|
|
74
74
|
# statement => "SELECT * from songs where artist = :favorite_artist"
|
75
75
|
# }
|
76
76
|
# }
|
77
|
-
#
|
77
|
+
# ------------------------------------------------------------------------------
|
78
78
|
#
|
79
79
|
# ==== Configuring SQL statement
|
80
80
|
#
|
@@ -84,6 +84,21 @@ require "yaml" # persistence
|
|
84
84
|
# The file option only supports one SQL statement. The plugin will only accept one of the options.
|
85
85
|
# It cannot read a statement from a file as well as from the `statement` configuration parameter.
|
86
86
|
#
|
87
|
+
# ==== Configuring multiple SQL statements
|
88
|
+
#
|
89
|
+
# Configuring multiple SQL statements is useful when there is a need to query and ingest data
|
90
|
+
# from different database tables or views. It is possible to define separate Logstash
|
91
|
+
# configuration files for each statement or to define multiple statements in a single configuration
|
92
|
+
# file. When using multiple statements in a single Logstash configuration file, each statement
|
93
|
+
# has to be defined as a separate jdbc input (including jdbc driver, connection string and other
|
94
|
+
# required parameters).
|
95
|
+
#
|
96
|
+
# Please note that if any of the statements use the `sql_last_value` parameter (e.g. for
|
97
|
+
# ingesting only data changed since last run), each input should define its own
|
98
|
+
# `last_run_metadata_path` parameter. Failure to do so will result in undesired behaviour, as
|
99
|
+
# all inputs will store their state to the same (default) metadata file, effectively
|
100
|
+
# overwriting each other's `sql_last_value`.
|
101
|
+
#
|
87
102
|
# ==== Predefined Parameters
|
88
103
|
#
|
89
104
|
# Some parameters are built-in and can be used from within your queries.
|
@@ -97,16 +112,16 @@ require "yaml" # persistence
|
|
97
112
|
#
|
98
113
|
# Example:
|
99
114
|
# [source,ruby]
|
100
|
-
#
|
115
|
+
# ---------------------------------------------------------------------------------------------------
|
101
116
|
# input {
|
102
117
|
# jdbc {
|
103
118
|
# statement => "SELECT id, mycolumn1, mycolumn2 FROM my_table WHERE id > :sql_last_value"
|
104
119
|
# use_column_value => true
|
105
|
-
# tracking_column => id
|
120
|
+
# tracking_column => "id"
|
106
121
|
# # ... other configuration bits
|
107
122
|
# }
|
108
123
|
# }
|
109
|
-
#
|
124
|
+
# ---------------------------------------------------------------------------------------------------
|
110
125
|
#
|
111
126
|
class LogStash::Inputs::Jdbc < LogStash::Inputs::Base
|
112
127
|
include LogStash::PluginMixins::Jdbc
|
@@ -121,9 +136,9 @@ class LogStash::Inputs::Jdbc < LogStash::Inputs::Base
|
|
121
136
|
# For example:
|
122
137
|
#
|
123
138
|
# [source, ruby]
|
124
|
-
#
|
139
|
+
# -----------------------------------------------
|
125
140
|
# "SELECT * FROM MYTABLE WHERE id = :target_id"
|
126
|
-
#
|
141
|
+
# -----------------------------------------------
|
127
142
|
#
|
128
143
|
# here, ":target_id" is a named parameter. You can configure named parameters
|
129
144
|
# with the `parameters` setting.
|
@@ -172,7 +187,7 @@ class LogStash::Inputs::Jdbc < LogStash::Inputs::Base
|
|
172
187
|
#
|
173
188
|
# Example:
|
174
189
|
# [source,ruby]
|
175
|
-
#
|
190
|
+
# -------------------------------------------------------
|
176
191
|
# input {
|
177
192
|
# jdbc {
|
178
193
|
# ...
|
@@ -180,6 +195,7 @@ class LogStash::Inputs::Jdbc < LogStash::Inputs::Base
|
|
180
195
|
# ...
|
181
196
|
# }
|
182
197
|
# }
|
198
|
+
# -------------------------------------------------------
|
183
199
|
# this will only convert column0 that has ISO-8859-1 as an original encoding.
|
184
200
|
config :columns_charset, :validate => :hash, :default => {}
|
185
201
|
|
@@ -138,8 +138,8 @@ module LogStash::PluginMixins::Jdbc
|
|
138
138
|
end
|
139
139
|
end
|
140
140
|
|
141
|
-
|
142
|
-
def
|
141
|
+
private
|
142
|
+
def open_jdbc_connection
|
143
143
|
require "java"
|
144
144
|
require "sequel"
|
145
145
|
require "sequel/adapters/jdbc"
|
@@ -170,16 +170,27 @@ module LogStash::PluginMixins::Jdbc
|
|
170
170
|
begin
|
171
171
|
@database.test_connection
|
172
172
|
rescue Sequel::DatabaseConnectionError => e
|
173
|
+
@logger.warn("Failed test_connection.")
|
174
|
+
@database.close_jdbc_connection
|
175
|
+
|
173
176
|
#TODO return false and let the plugin raise a LogStash::ConfigurationError
|
174
177
|
raise e
|
175
178
|
end
|
179
|
+
|
176
180
|
@database.sql_log_level = @sql_log_level.to_sym
|
177
181
|
@database.logger = @logger
|
182
|
+
|
183
|
+
@database.extension :identifier_mangling
|
184
|
+
|
178
185
|
if @lowercase_column_names
|
179
186
|
@database.identifier_output_method = :downcase
|
180
187
|
else
|
181
188
|
@database.identifier_output_method = :to_s
|
182
189
|
end
|
190
|
+
end
|
191
|
+
|
192
|
+
public
|
193
|
+
def prepare_jdbc_connection
|
183
194
|
if @use_column_value
|
184
195
|
case @tracking_column_type
|
185
196
|
when "numeric"
|
@@ -195,6 +206,7 @@ module LogStash::PluginMixins::Jdbc
|
|
195
206
|
public
|
196
207
|
def close_jdbc_connection
|
197
208
|
@database.disconnect if @database
|
209
|
+
@database = nil
|
198
210
|
end
|
199
211
|
|
200
212
|
public
|
@@ -202,6 +214,7 @@ module LogStash::PluginMixins::Jdbc
|
|
202
214
|
success = false
|
203
215
|
begin
|
204
216
|
parameters = symbolized_params(parameters)
|
217
|
+
open_jdbc_connection if @database == nil
|
205
218
|
query = @database[statement, parameters]
|
206
219
|
sql_last_value = @use_column_value ? @sql_last_value : Time.now.utc
|
207
220
|
@tracking_column_warning_sent = false
|
@@ -229,6 +242,9 @@ module LogStash::PluginMixins::Jdbc
|
|
229
242
|
success = true
|
230
243
|
rescue Sequel::DatabaseConnectionError, Sequel::DatabaseError => e
|
231
244
|
@logger.warn("Exception when executing JDBC query", :exception => e)
|
245
|
+
@logger.warn("Attempt reconnection.")
|
246
|
+
close_jdbc_connection()
|
247
|
+
open_jdbc_connection()
|
232
248
|
else
|
233
249
|
@sql_last_value = sql_last_value
|
234
250
|
end
|
data/logstash-input-jdbc.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'logstash-input-jdbc'
|
3
|
-
s.version = '4.
|
3
|
+
s.version = '4.2.0'
|
4
4
|
s.licenses = ['Apache License (2.0)']
|
5
5
|
s.summary = "This example input streams a string at a definable interval."
|
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
@@ -59,6 +59,7 @@ describe LogStash::Inputs::Jdbc do
|
|
59
59
|
mixin_settings['jdbc_driver_library'] = '/foo/bar,/bar/foo'
|
60
60
|
expect(plugin).to receive(:load_drivers).with(['/foo/bar', '/bar/foo'])
|
61
61
|
plugin.register
|
62
|
+
plugin.run(queue) # load when first run
|
62
63
|
plugin.stop
|
63
64
|
end
|
64
65
|
|
@@ -66,6 +67,7 @@ describe LogStash::Inputs::Jdbc do
|
|
66
67
|
mixin_settings['jdbc_driver_library'] = '/foo/bar'
|
67
68
|
expect(plugin).to receive(:load_drivers).with(['/foo/bar'])
|
68
69
|
plugin.register
|
70
|
+
plugin.run(queue) # load when first run
|
69
71
|
plugin.stop
|
70
72
|
end
|
71
73
|
|
@@ -819,7 +821,10 @@ describe LogStash::Inputs::Jdbc do
|
|
819
821
|
end
|
820
822
|
|
821
823
|
it "should fail" do
|
822
|
-
expect
|
824
|
+
expect do
|
825
|
+
plugin.register
|
826
|
+
plugin.run(queue) # load when first run
|
827
|
+
end.to raise_error(LogStash::ConfigurationError)
|
823
828
|
end
|
824
829
|
end
|
825
830
|
|
@@ -837,6 +842,7 @@ describe LogStash::Inputs::Jdbc do
|
|
837
842
|
|
838
843
|
it "should raise PoolTimeout error" do
|
839
844
|
plugin.register
|
845
|
+
plugin.run(queue)
|
840
846
|
db = plugin.instance_variable_get(:@database)
|
841
847
|
expect(db.pool.instance_variable_get(:@timeout)).to eq(0)
|
842
848
|
expect(db.pool.instance_variable_get(:@max_size)).to eq(1)
|
@@ -852,7 +858,10 @@ describe LogStash::Inputs::Jdbc do
|
|
852
858
|
it "should log error message" do
|
853
859
|
allow(Sequel).to receive(:connect).and_raise(Sequel::PoolTimeout)
|
854
860
|
expect(plugin.logger).to receive(:error).with("Failed to connect to database. 0 second timeout exceeded. Tried 1 times.")
|
855
|
-
expect
|
861
|
+
expect do
|
862
|
+
plugin.register
|
863
|
+
plugin.run(queue)
|
864
|
+
end.to raise_error(Sequel::PoolTimeout)
|
856
865
|
end
|
857
866
|
end
|
858
867
|
|
@@ -930,7 +939,10 @@ describe LogStash::Inputs::Jdbc do
|
|
930
939
|
allow(Sequel).to receive(:connect).and_raise(Sequel::PoolTimeout)
|
931
940
|
expect(plugin.logger).to receive(:error).with("Failed to connect to database. 0 second timeout exceeded. Trying again.")
|
932
941
|
expect(plugin.logger).to receive(:error).with("Failed to connect to database. 0 second timeout exceeded. Tried 2 times.")
|
933
|
-
expect
|
942
|
+
expect do
|
943
|
+
plugin.register
|
944
|
+
plugin.run(queue)
|
945
|
+
end.to raise_error(Sequel::PoolTimeout)
|
934
946
|
end
|
935
947
|
|
936
948
|
it "should not fail when passed a non-positive value" do
|
@@ -967,11 +979,14 @@ describe LogStash::Inputs::Jdbc do
|
|
967
979
|
"column1" => "bar".force_encoding(Encoding::ISO_8859_1),
|
968
980
|
"column2" => 3
|
969
981
|
}
|
982
|
+
event = LogStash::Event.new(row)
|
970
983
|
expect(LogStash::Event).to receive(:new) do |row|
|
971
984
|
row.each do |k, v|
|
972
985
|
next unless v.is_a?(String)
|
973
986
|
expect(row[k].encoding).to eq(encoded_row[k].encoding)
|
974
987
|
end
|
988
|
+
|
989
|
+
event
|
975
990
|
end
|
976
991
|
plugin.run(events)
|
977
992
|
end
|
@@ -999,11 +1014,14 @@ describe LogStash::Inputs::Jdbc do
|
|
999
1014
|
"column1" => "bar",
|
1000
1015
|
"column2" => 3
|
1001
1016
|
}
|
1017
|
+
event = LogStash::Event.new(row)
|
1002
1018
|
expect(LogStash::Event).to receive(:new) do |row|
|
1003
1019
|
row.each do |k, v|
|
1004
1020
|
next unless v.is_a?(String)
|
1005
1021
|
expect(row[k].encoding).to eq(encoded_row[k].encoding)
|
1006
1022
|
end
|
1023
|
+
|
1024
|
+
event
|
1007
1025
|
end
|
1008
1026
|
plugin.run(events)
|
1009
1027
|
end
|
@@ -1034,11 +1052,14 @@ describe LogStash::Inputs::Jdbc do
|
|
1034
1052
|
"column2" => 3,
|
1035
1053
|
"column3" => "berlin".force_encoding(Encoding::ASCII_8BIT)
|
1036
1054
|
}
|
1055
|
+
event = LogStash::Event.new(row)
|
1037
1056
|
expect(LogStash::Event).to receive(:new) do |row|
|
1038
1057
|
row.each do |k, v|
|
1039
1058
|
next unless v.is_a?(String)
|
1040
1059
|
expect(row[k].encoding).to eq(encoded_row[k].encoding)
|
1041
1060
|
end
|
1061
|
+
|
1062
|
+
event
|
1042
1063
|
end
|
1043
1064
|
plugin.run(events)
|
1044
1065
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logstash-input-jdbc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Elastic
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-04-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|