logstash-output-jdbc 0.2.6 → 0.2.7
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/lib/com/zaxxer/HikariCP/2.4.2/HikariCP-2.4.2.jar +0 -0
- data/lib/log4j/log4j/1.2.17/log4j-1.2.17.jar +0 -0
- data/lib/logstash/outputs/jdbc.rb +56 -4
- data/lib/org/slf4j/slf4j-api/1.7.12/slf4j-api-1.7.12.jar +0 -0
- data/lib/org/slf4j/slf4j-log4j12/1.7.13/slf4j-log4j12-1.7.13.jar +0 -0
- data/spec/outputs/jdbc_spec.rb +1 -4
- data/vendor/jar-dependencies/runtime-jars/log4j-1.2.17.jar +0 -0
- data/vendor/jar-dependencies/runtime-jars/slf4j-api-1.7.12.jar +0 -0
- data/vendor/jar-dependencies/runtime-jars/slf4j-log4j12-1.7.13.jar +0 -0
- metadata +9 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6fc8ddfe645eb52236a43bd311160e9b1bb6cb13
|
4
|
+
data.tar.gz: e5dbdf7eaa611c69380423ec6e2d318bafd295d0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 738fe21719d3f903744fa61c721ef5ec197416089d04d42be0574234d28a692792c24927bef85dd9e2bb511f0ae63bc09c23b6f161fd33b72cdf3b0c6c8ba5e7
|
7
|
+
data.tar.gz: 18652ad8984829a32fad82e7af6972b34356e6eeb07e01bade6caf71bf148f6bc8e06feb6c7568ac7df8d8328d2017acfe0705c55c30b6d2b14475df2dce781a
|
Binary file
|
Binary file
|
@@ -6,10 +6,33 @@ require "java"
|
|
6
6
|
require "logstash-output-jdbc_jars"
|
7
7
|
require "logstash-output-jdbc_ring-buffer"
|
8
8
|
|
9
|
+
# Write events to a SQL engine, using JDBC.
|
10
|
+
#
|
11
|
+
# It is upto the user of the plugin to correctly configure the plugin. This
|
12
|
+
# includes correctly crafting the SQL statement, and matching the number of
|
13
|
+
# parameters correctly.
|
9
14
|
class LogStash::Outputs::Jdbc < LogStash::Outputs::Base
|
10
15
|
# Adds buffer support
|
11
16
|
include Stud::Buffer
|
12
17
|
|
18
|
+
STRFTIME_FMT = '%Y-%m-%d %T.%L'.freeze
|
19
|
+
|
20
|
+
RETRYABLE_SQLSTATE_CLASSES = [
|
21
|
+
# Classes of retryable SQLSTATE codes
|
22
|
+
# Not all in the class will be retryable. However, this is the best that
|
23
|
+
# we've got right now.
|
24
|
+
# If a custom state code is required, set it in retry_sql_states.
|
25
|
+
'08', # Connection Exception
|
26
|
+
'24', # Invalid Cursor State (Maybe retry-able in some circumstances)
|
27
|
+
'25', # Invalid Transaction State
|
28
|
+
'40', # Transaction Rollback
|
29
|
+
'53', # Insufficient Resources
|
30
|
+
'54', # Program Limit Exceeded (MAYBE)
|
31
|
+
'55', # Object Not In Prerequisite State
|
32
|
+
'57', # Operator Intervention
|
33
|
+
'58', # System Error
|
34
|
+
].freeze
|
35
|
+
|
13
36
|
config_name "jdbc"
|
14
37
|
|
15
38
|
# Driver class - Reintroduced for https://github.com/theangryangel/logstash-output-jdbc/issues/26
|
@@ -196,8 +219,15 @@ class LogStash::Outputs::Jdbc < LogStash::Outputs::Base
|
|
196
219
|
def safe_flush(events, teardown=false)
|
197
220
|
connection = nil
|
198
221
|
statement = nil
|
222
|
+
|
199
223
|
begin
|
200
224
|
connection = @pool.getConnection()
|
225
|
+
rescue => e
|
226
|
+
log_jdbc_exception(e)
|
227
|
+
raise
|
228
|
+
end
|
229
|
+
|
230
|
+
begin
|
201
231
|
statement = connection.prepareStatement(@statement[0])
|
202
232
|
|
203
233
|
events.each do |event|
|
@@ -213,6 +243,9 @@ class LogStash::Outputs::Jdbc < LogStash::Outputs::Base
|
|
213
243
|
@exceptions_tracker << nil
|
214
244
|
rescue => e
|
215
245
|
log_jdbc_exception(e)
|
246
|
+
if retry_exception?(e)
|
247
|
+
raise
|
248
|
+
end
|
216
249
|
ensure
|
217
250
|
statement.close() unless statement.nil?
|
218
251
|
connection.close() unless connection.nil?
|
@@ -224,7 +257,12 @@ class LogStash::Outputs::Jdbc < LogStash::Outputs::Base
|
|
224
257
|
statement = nil
|
225
258
|
begin
|
226
259
|
connection = @pool.getConnection()
|
260
|
+
rescue => e
|
261
|
+
log_jdbc_exception(e)
|
262
|
+
raise
|
263
|
+
end
|
227
264
|
|
265
|
+
begin
|
228
266
|
events.each do |event|
|
229
267
|
next if event.cancelled?
|
230
268
|
|
@@ -240,6 +278,9 @@ class LogStash::Outputs::Jdbc < LogStash::Outputs::Base
|
|
240
278
|
end
|
241
279
|
rescue => e
|
242
280
|
log_jdbc_exception(e)
|
281
|
+
if retry_exception?(e)
|
282
|
+
raise
|
283
|
+
end
|
243
284
|
ensure
|
244
285
|
statement.close() unless statement.nil?
|
245
286
|
connection.close() unless connection.nil?
|
@@ -250,11 +291,17 @@ class LogStash::Outputs::Jdbc < LogStash::Outputs::Base
|
|
250
291
|
@statement[1..-1].each_with_index do |i, idx|
|
251
292
|
case event[i]
|
252
293
|
when Time
|
253
|
-
#
|
254
|
-
statement.setString(idx + 1, event[i].
|
294
|
+
# See LogStash::Timestamp, below, for the why behind strftime.
|
295
|
+
statement.setString(idx + 1, event[i].strftime(STRFTIME_FMT))
|
255
296
|
when LogStash::Timestamp
|
256
|
-
#
|
257
|
-
|
297
|
+
# XXX: Using setString as opposed to setTimestamp, because setTimestamp
|
298
|
+
# doesn't behave correctly in some drivers (Known: sqlite)
|
299
|
+
#
|
300
|
+
# Additionally this does not use `to_iso8601`, since some SQL databases
|
301
|
+
# choke on the 'T' in the string (Known: Derby).
|
302
|
+
#
|
303
|
+
# strftime appears to be the most reliable across drivers.
|
304
|
+
statement.setString(idx + 1, event[i].time.strftime(STRFTIME_FMT))
|
258
305
|
when Fixnum, Integer
|
259
306
|
statement.setInt(idx + 1, event[i])
|
260
307
|
when Float
|
@@ -285,4 +332,9 @@ class LogStash::Outputs::Jdbc < LogStash::Outputs::Base
|
|
285
332
|
break if current_exception == nil
|
286
333
|
end
|
287
334
|
end
|
335
|
+
|
336
|
+
def retry_exception?(exception)
|
337
|
+
return (exception.class != java.sql.SQLException or
|
338
|
+
RETRYABLE_SQLSTATE_CLASSES.include?(e.getSQLState[0,2]))
|
339
|
+
end
|
288
340
|
end # class LogStash::Outputs::jdbc
|
Binary file
|
Binary file
|
data/spec/outputs/jdbc_spec.rb
CHANGED
@@ -10,10 +10,7 @@ describe LogStash::Outputs::Jdbc do
|
|
10
10
|
"driver_class" => "org.apache.derby.jdbc.EmbeddedDriver",
|
11
11
|
"connection_string" => "jdbc:derby:memory:testdb;create=true",
|
12
12
|
"driver_jar_path" => ENV['JDBC_DERBY_JAR'],
|
13
|
-
|
14
|
-
# Derby doesn't like 'T' in timestamps as of current writing, so for now
|
15
|
-
# we'll just use CURRENT_TIMESTAMP as opposed to the event @timestamp
|
16
|
-
"statement" => [ "insert into log (created_at, message) values(CURRENT_TIMESTAMP, ?)", "message" ]
|
13
|
+
"statement" => [ "insert into log (created_at, message) values(?, ?)", "@timestamp" "message" ]
|
17
14
|
}
|
18
15
|
end
|
19
16
|
|
Binary file
|
Binary file
|
Binary file
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logstash-output-jdbc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- the_angry_angel
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-05-
|
11
|
+
date: 2016-05-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: logstash-core
|
@@ -80,11 +80,18 @@ executables: []
|
|
80
80
|
extensions: []
|
81
81
|
extra_rdoc_files: []
|
82
82
|
files:
|
83
|
+
- lib/com/zaxxer/HikariCP/2.4.2/HikariCP-2.4.2.jar
|
84
|
+
- lib/log4j/log4j/1.2.17/log4j-1.2.17.jar
|
83
85
|
- lib/logstash/outputs/jdbc.rb
|
84
86
|
- lib/logstash-output-jdbc_jars.rb
|
85
87
|
- lib/logstash-output-jdbc_ring-buffer.rb
|
88
|
+
- lib/org/slf4j/slf4j-api/1.7.12/slf4j-api-1.7.12.jar
|
89
|
+
- lib/org/slf4j/slf4j-log4j12/1.7.13/slf4j-log4j12-1.7.13.jar
|
86
90
|
- vendor/jar-dependencies/runtime-jars/HikariCP-2.4.2.jar
|
91
|
+
- vendor/jar-dependencies/runtime-jars/log4j-1.2.17.jar
|
92
|
+
- vendor/jar-dependencies/runtime-jars/slf4j-api-1.7.12.jar
|
87
93
|
- vendor/jar-dependencies/runtime-jars/slf4j-api-1.7.13.jar
|
94
|
+
- vendor/jar-dependencies/runtime-jars/slf4j-log4j12-1.7.13.jar
|
88
95
|
- vendor/jar-dependencies/runtime-jars/slf4j-nop-1.7.13.jar
|
89
96
|
- spec/outputs/jdbc_spec.rb
|
90
97
|
- LICENSE.txt
|