Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
da5a3d8be3 | ||
|
|
b10462dacd | ||
|
|
61c7a1307e |
@@ -1,6 +1,10 @@
|
||||
# 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
|
||||
|
||||
@@ -286,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)
|
||||
@@ -298,44 +307,44 @@ 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)
|
||||
statement.setString(idx + 1, value)
|
||||
when true, false
|
||||
statement.setBoolean(idx + 1, value)
|
||||
else
|
||||
if event[i].nil? and i =~ /%\{/
|
||||
statement.setString(idx + 1, event.sprintf(i))
|
||||
else
|
||||
statement.setString(idx + 1, nil)
|
||||
end
|
||||
statement.setString(idx + 1, nil)
|
||||
end
|
||||
end
|
||||
|
||||
statement
|
||||
end
|
||||
|
||||
|
||||
def log_jdbc_exception(exception, retrying)
|
||||
current_exception = exception
|
||||
log_text = 'JDBC - Exception. ' + (retrying ? 'Retrying' : 'Not retrying') + '.'
|
||||
log_method = (retrying ? 'warn' : 'error')
|
||||
|
||||
loop do
|
||||
if retrying
|
||||
@logger.error("JDBC Exception. Retrying.", :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
|
||||
@logger.error("JDBC Exception. No retry.", :exception => current_exception)
|
||||
current_exception = nil
|
||||
end
|
||||
current_exception = current_exception.getNextException()
|
||||
|
||||
break if current_exception == nil
|
||||
end
|
||||
end
|
||||
|
||||
def retry_exception?(exception)
|
||||
retrying = (exception.respond_to? 'getSQLState' and RETRYABLE_SQLSTATE_CLASSES.include?(exception.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
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
Gem::Specification.new do |s|
|
||||
s.name = 'logstash-output-jdbc'
|
||||
s.version = "0.2.9"
|
||||
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