logstash-output-jdbc 0.2.0.rc1 → 0.2.0.rc2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f4fb996001ccfc6faabb63f7d242ab88e176a8c1
4
- data.tar.gz: e843a30f504af936835909f388dc7fe74c5e3d19
3
+ metadata.gz: e5d20a2e81aa5a05d7c63f205a9cf17ec4c694e8
4
+ data.tar.gz: 4fae148aa988fad70a15e62893e8a2a614ca13a3
5
5
  SHA512:
6
- metadata.gz: 6da31e801e832f0e9150a468fc07e8126a457069b9536f1add378baf8121f146a17fb08e83be87a6c2cb667b27ed2812262eace113059030537d58655ce06c7c
7
- data.tar.gz: d5a84a95b71c98a512c6bf66135c3f8b3e68260da9d777a0be2c0628e649f9a7b8fc1cfdb8febdd22a6180090cf807c153b74b45f3fb6445d5f9fb699fc0e447
6
+ metadata.gz: 0095e183425171cf0215fd8dd839ae28281a04664a8e70ae6330fbc77433f1641a3436e82a7cc8ef55d3d84cbb70244287b6f4e78f1b46d855052bda3fa38d6c
7
+ data.tar.gz: 546451f10d576dbcf585d9b27ba200a296039c2b4ea1f93bfe8431e96408cbd80504545d848d7227bb7588c3453a414022ee75b6b9a42ca1def85c847204be6f
@@ -30,6 +30,12 @@ class LogStash::Outputs::Jdbc < LogStash::Outputs::Base
30
30
  # [ "insert into table (message) values(?)", "%{message}" ]
31
31
  config :statement, :validate => :array, :required => true
32
32
 
33
+ # If this is an unsafe statement, use event.sprintf
34
+ # This also has potential performance penalties due to having to create a
35
+ # new statement for each event, rather than adding to the batch and issuing
36
+ # multiple inserts in 1 go
37
+ config :unsafe_statement, :validate => :boolean, :default => false
38
+
33
39
  # Number of connections in the pool to maintain
34
40
  config :max_pool_size, :validate => :number, :default => 5
35
41
 
@@ -72,7 +78,7 @@ class LogStash::Outputs::Jdbc < LogStash::Outputs::Base
72
78
 
73
79
  @pool = Java::ComZaxxerHikari::HikariDataSource.new
74
80
  @pool.setJdbcUrl(@connection_string)
75
-
81
+
76
82
  @pool.setUsername(@username) if @username
77
83
  @pool.setPassword(@password) if @password
78
84
 
@@ -105,50 +111,10 @@ class LogStash::Outputs::Jdbc < LogStash::Outputs::Base
105
111
  end
106
112
 
107
113
  def flush(events, teardown=false)
108
- connection = @pool.getConnection()
109
-
110
- statement = connection.prepareStatement(@statement[0])
111
-
112
- events.each do |event|
113
- next if @statement.length < 2
114
-
115
- @statement[1..-1].each_with_index do |i, idx|
116
- case event[i]
117
- when Time, LogStash::Timestamp
118
- # Most reliable solution, cross JDBC driver
119
- statement.setString(idx + 1, event[i].iso8601())
120
- when Fixnum, Integer
121
- statement.setInt(idx + 1, event[i])
122
- when Float
123
- statement.setFloat(idx + 1, event[i])
124
- when String
125
- statement.setString(idx + 1, event[i])
126
- when true
127
- statement.setBoolean(idx + 1, true)
128
- when false
129
- statement.setBoolean(idx + 1, false)
130
- else
131
- statement.setString(idx + 1, event.sprintf(i))
132
- end
133
- end
134
-
135
- statement.addBatch()
136
- end
137
-
138
- begin
139
- @logger.debug("JDBC - Sending SQL", :sql => statement.toString())
140
- statement.executeBatch()
141
- statement.close()
142
- rescue => e
143
- # Raising an exception will incur a retry from Stud::Buffer.
144
- # Since the exceutebatch failed this should mean any events failed to be
145
- # inserted will be re-run. We're going to log it for the lols anyway.
146
- @logger.warn("JDBC - Exception. Will automatically retry", :exception => e)
147
- if e.getNextException() != nil
148
- @logger.warn("JDBC - Exception. Will automatically retry", :exception => e.getNextException())
149
- end
150
- ensure
151
- connection.close();
114
+ if @unsafe_statement == true
115
+ unsafe_flush(events, teardown)
116
+ else
117
+ safe_flush(events, teardown)
152
118
  end
153
119
  end
154
120
 
@@ -204,4 +170,71 @@ class LogStash::Outputs::Jdbc < LogStash::Outputs::Base
204
170
  require jar
205
171
  end
206
172
  end
173
+
174
+ def safe_flush(events, teardown=false)
175
+ connection = @pool.getConnection()
176
+
177
+ statement = connection.prepareStatement(@statement[0])
178
+
179
+ events.each do |event|
180
+ next if @statement.length < 2
181
+ statement = add_statement_event_params(statement, event)
182
+
183
+ statement.addBatch()
184
+ end
185
+
186
+ begin
187
+ @logger.debug("JDBC - Sending SQL", :sql => statement.toString())
188
+ statement.executeBatch()
189
+ statement.close()
190
+ rescue => e
191
+ # Raising an exception will incur a retry from Stud::Buffer.
192
+ # Since the exceutebatch failed this should mean any events failed to be
193
+ # inserted will be re-run. We're going to log it for the lols anyway.
194
+ @logger.warn("JDBC - Exception. Will automatically retry", :exception => e)
195
+ if e.getNextException() != nil
196
+ @logger.warn("JDBC - Exception. Will automatically retry", :exception => e.getNextException())
197
+ end
198
+ ensure
199
+ connection.close();
200
+ end
201
+ end
202
+
203
+ def unsafe_flush(events, teardown=false)
204
+ connection = @pool.getConnection()
205
+
206
+ events.each do |event|
207
+ statement = connection.prepareStatement(event.sprintf(@statement[0]))
208
+
209
+ statement = add_statement_event_params(statement, event) if @statement.length > 1
210
+
211
+ statement.execute()
212
+ statement.close()
213
+ connection.close()
214
+ end
215
+ end
216
+
217
+ def add_statement_event_params(statement, event)
218
+ @statement[1..-1].each_with_index do |i, idx|
219
+ case event[i]
220
+ when Time, LogStash::Timestamp
221
+ # Most reliable solution, cross JDBC driver
222
+ statement.setString(idx + 1, event[i].iso8601())
223
+ when Fixnum, Integer
224
+ statement.setInt(idx + 1, event[i])
225
+ when Float
226
+ statement.setFloat(idx + 1, event[i])
227
+ when String
228
+ statement.setString(idx + 1, event[i])
229
+ when true
230
+ statement.setBoolean(idx + 1, true)
231
+ when false
232
+ statement.setBoolean(idx + 1, false)
233
+ else
234
+ statement.setString(idx + 1, event.sprintf(i))
235
+ end
236
+ end
237
+
238
+ statement
239
+ end
207
240
  end # class LogStash::Outputs::jdbc
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'logstash-output-jdbc'
3
- s.version = "0.2.0.rc1"
3
+ s.version = "0.2.0.rc2"
4
4
  s.licenses = [ "Apache License (2.0)" ]
5
5
  s.summary = "This plugin allows you to output to SQL, via JDBC"
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/plugin install gemname. This gem is not a stand-alone program"
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.0.rc1
4
+ version: 0.2.0.rc2
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: 2015-11-14 00:00:00.000000000 Z
11
+ date: 2015-11-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: logstash-core