Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
da5a3d8be3 | ||
|
|
b10462dacd | ||
|
|
61c7a1307e | ||
|
|
b5419813ba | ||
|
|
ded1106b13 |
@@ -1,6 +1,14 @@
|
||||
# Change Log
|
||||
All notable changes to this project will be documented in this file, from 0.2.0.
|
||||
|
||||
## [0.2.10] - 2016-07-07
|
||||
- Support non-string entries in statement array
|
||||
- Adds backtrace to exception logging
|
||||
|
||||
## [0.2.9] - 2016-06-29
|
||||
- Fix NameError exception.
|
||||
- Moved log_jdbc_exception calls
|
||||
|
||||
## [0.2.7] - 2016-05-29
|
||||
- Backport retry exception logic from v5 branch
|
||||
- Backport improved timestamp compatibility from v5 branch
|
||||
|
||||
@@ -151,7 +151,6 @@ class LogStash::Outputs::Jdbc < LogStash::Outputs::Base
|
||||
|
||||
if @exceptions_tracker.reject { |i| i.nil? }.count >= @max_flush_exceptions
|
||||
@logger.error("JDBC - max_flush_exceptions has been reached")
|
||||
log_jdbc_exception(e)
|
||||
raise LogStash::ShutdownSignal.new
|
||||
end
|
||||
end
|
||||
@@ -223,7 +222,7 @@ class LogStash::Outputs::Jdbc < LogStash::Outputs::Base
|
||||
begin
|
||||
connection = @pool.getConnection()
|
||||
rescue => e
|
||||
log_jdbc_exception(e)
|
||||
log_jdbc_exception(e, true)
|
||||
raise
|
||||
end
|
||||
|
||||
@@ -242,7 +241,6 @@ class LogStash::Outputs::Jdbc < LogStash::Outputs::Base
|
||||
statement.close()
|
||||
@exceptions_tracker << nil
|
||||
rescue => e
|
||||
log_jdbc_exception(e)
|
||||
if retry_exception?(e)
|
||||
raise
|
||||
end
|
||||
@@ -258,7 +256,7 @@ class LogStash::Outputs::Jdbc < LogStash::Outputs::Base
|
||||
begin
|
||||
connection = @pool.getConnection()
|
||||
rescue => e
|
||||
log_jdbc_exception(e)
|
||||
log_jdbc_exception(e, true)
|
||||
raise
|
||||
end
|
||||
|
||||
@@ -277,7 +275,6 @@ class LogStash::Outputs::Jdbc < LogStash::Outputs::Base
|
||||
@exceptions_tracker << nil
|
||||
end
|
||||
rescue => e
|
||||
log_jdbc_exception(e)
|
||||
if retry_exception?(e)
|
||||
raise
|
||||
end
|
||||
@@ -289,10 +286,19 @@ class LogStash::Outputs::Jdbc < LogStash::Outputs::Base
|
||||
|
||||
def add_statement_event_params(statement, event)
|
||||
@statement[1..-1].each_with_index do |i, idx|
|
||||
case event[i]
|
||||
if i.is_a? String
|
||||
value = event[i]
|
||||
if value.nil? and i =~ /%\{/
|
||||
value = event.sprintf(i)
|
||||
end
|
||||
else
|
||||
value = i
|
||||
end
|
||||
|
||||
case value
|
||||
when Time
|
||||
# See LogStash::Timestamp, below, for the why behind strftime.
|
||||
statement.setString(idx + 1, event[i].strftime(STRFTIME_FMT))
|
||||
statement.setString(idx + 1, value.strftime(STRFTIME_FMT))
|
||||
when LogStash::Timestamp
|
||||
# XXX: Using setString as opposed to setTimestamp, because setTimestamp
|
||||
# doesn't behave correctly in some drivers (Known: sqlite)
|
||||
@@ -301,40 +307,46 @@ class LogStash::Outputs::Jdbc < LogStash::Outputs::Base
|
||||
# choke on the 'T' in the string (Known: Derby).
|
||||
#
|
||||
# strftime appears to be the most reliable across drivers.
|
||||
statement.setString(idx + 1, event[i].time.strftime(STRFTIME_FMT))
|
||||
statement.setString(idx + 1, value.time.strftime(STRFTIME_FMT))
|
||||
when Fixnum, Integer
|
||||
statement.setInt(idx + 1, event[i])
|
||||
statement.setInt(idx + 1, value)
|
||||
when Float
|
||||
statement.setFloat(idx + 1, event[i])
|
||||
statement.setFloat(idx + 1, value)
|
||||
when String
|
||||
statement.setString(idx + 1, event[i])
|
||||
when true
|
||||
statement.setBoolean(idx + 1, true)
|
||||
when false
|
||||
statement.setBoolean(idx + 1, false)
|
||||
else
|
||||
if event[i].nil? and i =~ /%\{/
|
||||
statement.setString(idx + 1, event.sprintf(i))
|
||||
statement.setString(idx + 1, value)
|
||||
when true, false
|
||||
statement.setBoolean(idx + 1, value)
|
||||
else
|
||||
statement.setString(idx + 1, nil)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
statement
|
||||
end
|
||||
|
||||
def log_jdbc_exception(exception)
|
||||
|
||||
def log_jdbc_exception(exception, retrying)
|
||||
current_exception = exception
|
||||
log_text = 'JDBC - Exception. ' + (retrying ? 'Retrying' : 'Not retrying') + '.'
|
||||
log_method = (retrying ? 'warn' : 'error')
|
||||
|
||||
loop do
|
||||
@logger.error("JDBC Exception encountered: Will automatically retry.", :exception => current_exception)
|
||||
@logger.send(log_method, log_text, :exception => current_exception, :backtrace => current_exception.backtrace)
|
||||
|
||||
if current_exception.respond_to? 'getNextException'
|
||||
current_exception = current_exception.getNextException()
|
||||
else
|
||||
current_exception = nil
|
||||
end
|
||||
|
||||
break if current_exception == nil
|
||||
end
|
||||
end
|
||||
|
||||
def retry_exception?(exception)
|
||||
return (exception.class != java.sql.SQLException or
|
||||
RETRYABLE_SQLSTATE_CLASSES.include?(e.getSQLState[0,2]))
|
||||
retrying = (exception.respond_to? 'getSQLState' and RETRYABLE_SQLSTATE_CLASSES.include?(exception.getSQLState.to_s[0,2]))
|
||||
log_jdbc_exception(exception, retrying)
|
||||
|
||||
retrying
|
||||
end
|
||||
end # class LogStash::Outputs::jdbc
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
Gem::Specification.new do |s|
|
||||
s.name = 'logstash-output-jdbc'
|
||||
s.version = "0.2.7"
|
||||
s.version = "0.2.10"
|
||||
s.licenses = [ "Apache License (2.0)" ]
|
||||
s.summary = "This plugin allows you to output to SQL, via JDBC"
|
||||
s.description = "This gem is a logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/plugin install gemname. This gem is not a stand-alone program"
|
||||
@@ -19,11 +19,11 @@ Gem::Specification.new do |s|
|
||||
s.metadata = { "logstash_plugin" => "true", "logstash_group" => "output" }
|
||||
|
||||
# Gem dependencies
|
||||
s.add_runtime_dependency "logstash-core", ">= 2.0.0.beta2", "< 3.0.0"
|
||||
s.add_runtime_dependency 'stud'
|
||||
|
||||
s.add_runtime_dependency "logstash-core", ">= 2.0.0", "< 3.0.0"
|
||||
s.add_runtime_dependency "logstash-codec-plain"
|
||||
|
||||
s.add_development_dependency "logstash-devutils"
|
||||
|
||||
s.post_install_message = "logstash-output-jdbc 0.2.0 introduces several new features - please ensure you check the documentation in the README file"
|
||||
# https://github.com/elastic/logstash-devutils/issues/48
|
||||
s.add_development_dependency "logstash-devutils", '0.0.18'
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user