logstash-integration-jdbc 5.1.1 → 5.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3c88894d9c18905f8b857fb38288708bce49084b62ebbffea3cac41421f33dbb
4
- data.tar.gz: 32eb5bce9ba161d5c500bebe20bbd036ebeb20ba1ee149247fb8b169be790bf9
3
+ metadata.gz: 71904a199b39255cbefb08b1c43a08e0507df8af19be11ae3b57b69519d337f5
4
+ data.tar.gz: 17e4ef460ad1e9d51d0ecada1d94b6d41951a65e65f316e287ad58331f5a4211
5
5
  SHA512:
6
- metadata.gz: 2c36ce3aee724b1ec82ee2ce295fd92485acf8ba97ad5428d0d55263cd72a52a9349a523c7d5b5eb76f057fdbf7e8638bd36a7f27ccf1069fa075b0b03e56717
7
- data.tar.gz: 7441a532d6fbd600239c405220a0efcea6e1eb1aac421287be8b39c2119e907e611f0933e2863aaea3e90e0fb59f095dae9ebbad016fe54563dbcb9808341046
6
+ metadata.gz: 503737f45cfcba0724d533664b14bda25bf9abd0c5de549973857855f00722a666022693d1d22e517b735e6171a06d20cd31e11492c7d60321b3456627eab05f
7
+ data.tar.gz: 78d36bd182723abdc72ebf7809f76b86111d3e8bc4111bb08c5a8363fe88e8fe38c4ab563f1408f60c7b0b491f3802c69a31259e4035e8bebcd4bbfc5e8636d9
data/CHANGELOG.md CHANGED
@@ -1,3 +1,18 @@
1
+ ## 5.1.5
2
+ - Refined ECS support [#82](https://github.com/logstash-plugins/logstash-integration-jdbc/pull/82)
3
+ - Uses shared `target` guidance when ECS compatibility is enabled
4
+ - Uses Logstash's EventFactory instead of instantiating events directly
5
+
6
+ ## 5.1.4
7
+ - [DOC] Update filter-jdbc_static doc to describe ECS compatibility [#79](https://github.com/logstash-plugins/logstash-integration-jdbc/pull/79)
8
+
9
+ ## 5.1.3
10
+ - Improve robustness when handling errors from `sequel` library in jdbc static and streaming
11
+ filters [#78](https://github.com/logstash-plugins/logstash-integration-jdbc/pull/78)
12
+
13
+ ## 5.1.2
14
+ - Fix `prepared_statement_bind_values` in streaming filter to resolve nested event's fields [#76](https://github.com/logstash-plugins/logstash-integration-jdbc/pull/76)
15
+
1
16
  ## 5.1.1
2
17
  - [DOC] Changed docs to indicate that logstash-jdbc-static requires local_table [#56](https://github.com/logstash-plugins/logstash-integration-jdbc/pull/56). Fixes [#55](https://github.com/logstash-plugins/logstash-integration-jdbc/issues/55).
3
18
 
data/NOTICE.TXT ADDED
@@ -0,0 +1,5 @@
1
+ Elasticsearch
2
+ Copyright 2012-2018 Elasticsearch
3
+
4
+ This product includes software developed by The Apache Software
5
+ Foundation (http://www.apache.org/).
@@ -264,8 +264,17 @@ order is in place.
264
264
  ===============================
265
265
 
266
266
 
267
+ [id="plugins-{type}s-{plugin}-ecs"]
268
+ ==== Compatibility with the Elastic Common Schema (ECS)
269
+
270
+ This plugin is compatible with the {ecs-ref}[Elastic Common Schema (ECS)].
271
+ It behaves the same regardless of ECS compatibility, except giving a warning when ECS is enabled and `target` isn't set.
272
+
273
+ TIP: Set the `target` option to avoid potential schema conflicts.
274
+
275
+
267
276
  [id="plugins-{type}s-{plugin}-options"]
268
- ==== Jdbc_static Filter Configuration Options
277
+ ==== Jdbc_static filter configuration options
269
278
 
270
279
  This plugin supports the following configuration options plus the <<plugins-{type}s-{plugin}-common-options>> described later.
271
280
 
@@ -162,8 +162,11 @@ module LogStash module Filters module Jdbc
162
162
  begin
163
163
  logger.debug? && logger.debug("Executing Jdbc query", :lookup_id => @id, :statement => query, :parameters => params)
164
164
  proc.call(local, query, params, result)
165
- rescue ::Sequel::Error => e
166
- # all sequel errors are a subclass of this, let all other standard or runtime errors bubble up
165
+ rescue => e
166
+ # In theory all exceptions in Sequel should be wrapped in Sequel::Error
167
+ # However, there are cases where other errors can occur - a `SQLTransactionRollbackException`
168
+ # may be thrown during `prepareStatement`. Let's handle these cases here, where we can tag and warn
169
+ # appropriately rather than bubble up and potentially crash the plugin.
167
170
  result.failed!
168
171
  logger.warn? && logger.warn("Exception when executing Jdbc query", :lookup_id => @id, :exception => e.message, :backtrace => e.backtrace.take(8))
169
172
  end
@@ -4,8 +4,11 @@ require "logstash/namespace"
4
4
  require "logstash/plugin_mixins/jdbc/common"
5
5
  require "logstash/plugin_mixins/jdbc/jdbc"
6
6
  require "logstash/plugin_mixins/ecs_compatibility_support"
7
+ require "logstash/plugin_mixins/ecs_compatibility_support/target_check"
7
8
  require "logstash/plugin_mixins/validator_support/field_reference_validation_adapter"
8
9
 
10
+ require "logstash/plugin_mixins/event_support/event_factory_adapter"
11
+
9
12
  # this require_relative returns early unless the JRuby version is between 9.2.0.0 and 9.2.8.0
10
13
  require_relative "tzinfo_jruby_patch"
11
14
 
@@ -131,8 +134,14 @@ require_relative "tzinfo_jruby_patch"
131
134
  module LogStash module Inputs class Jdbc < LogStash::Inputs::Base
132
135
  include LogStash::PluginMixins::Jdbc::Common
133
136
  include LogStash::PluginMixins::Jdbc::Jdbc
137
+
134
138
  # adds ecs_compatibility config which could be :disabled or :v1
135
139
  include LogStash::PluginMixins::ECSCompatibilitySupport(:disabled,:v1,:v8 => :v1)
140
+ include LogStash::PluginMixins::ECSCompatibilitySupport::TargetCheck
141
+
142
+ # adds `event_factory` and `targeted_event_factory
143
+ include LogStash::PluginMixins::EventSupport::EventFactoryAdapter
144
+
136
145
  # adds :field_reference validator adapter
137
146
  extend LogStash::PluginMixins::ValidatorSupport::FieldReferenceValidationAdapter
138
147
 
@@ -270,13 +279,6 @@ module LogStash module Inputs class Jdbc < LogStash::Inputs::Base
270
279
  converters[encoding] = converter
271
280
  end
272
281
  end
273
-
274
- # target must be populated if ecs_compatibility is not :disabled
275
- if @target.nil? && ecs_compatibility != :disabled
276
- logger.info('ECS compatibility is enabled but no ``target`` option was specified, it is recommended'\
277
- ' to set the option to avoid potential schema conflicts (if your data is ECS compliant or'\
278
- ' non-conflicting feel free to ignore this message)')
279
- end
280
282
  end # def register
281
283
 
282
284
  # test injection points
@@ -335,12 +337,7 @@ module LogStash module Inputs class Jdbc < LogStash::Inputs::Base
335
337
  ## do the necessary conversions to string elements
336
338
  row = Hash[row.map { |k, v| [k.to_s, convert(k, v)] }]
337
339
  end
338
- if @target
339
- event = LogStash::Event.new
340
- event.set(@target, row)
341
- else
342
- event = LogStash::Event.new(row)
343
- end
340
+ event = targeted_event_factory.new_event(row)
344
341
  decorate(event)
345
342
  queue << event
346
343
  end
@@ -119,8 +119,7 @@ module LogStash module PluginMixins module Jdbc
119
119
  else
120
120
  @logger.error("Failed to connect to database. #{@jdbc_pool_timeout} second timeout exceeded. Trying again.")
121
121
  end
122
- # rescue Java::JavaSql::SQLException, ::Sequel::Error => e
123
- rescue ::Sequel::Error => e
122
+ rescue Java::JavaSql::SQLException, ::Sequel::Error => e
124
123
  if retry_attempts <= 0
125
124
  log_java_exception(e.cause)
126
125
  @logger.error("Unable to connect to database. Tried #{@connection_retry_attempts} times", error_details(e, trace: true))
@@ -26,7 +26,7 @@ module LogStash module PluginMixins module JdbcStreaming
26
26
  return InterpolatedParameter.new(given_value)
27
27
  end
28
28
 
29
- if given_value =~ /\A\s*\[[^\]]+\]\s*\z/
29
+ if given_value =~ /\A(\s*\[[^\]]+\]\s*)*\z/
30
30
  return FieldParameter.new(given_value)
31
31
  end
32
32
 
@@ -38,8 +38,11 @@ module LogStash module PluginMixins module JdbcStreaming
38
38
  begin
39
39
  logger.debug? && logger.debug("Executing JDBC query", :statement => statement, :parameters => params)
40
40
  execute_extract_records(db, params, result)
41
- rescue ::Sequel::Error => e
42
- # all sequel errors are a subclass of this, let all other standard or runtime errors bubble up
41
+ rescue => e
42
+ # In theory all exceptions in Sequel should be wrapped in Sequel::Error
43
+ # However, there are cases where other errors can occur - a `SQLException`may be thrown
44
+ # during `prepareStatement`. Let's handle these cases here, where we can tag and warn
45
+ # appropriately rather than bubble up and potentially crash the plugin.
43
46
  result.failed!
44
47
  logger.warn? && logger.warn("Exception when executing JDBC query", :statement => statement, :parameters => params, :exception => e)
45
48
  end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'logstash-integration-jdbc'
3
- s.version = '5.1.1'
3
+ s.version = '5.1.5'
4
4
  s.licenses = ['Apache License (2.0)']
5
5
  s.summary = "Integration with JDBC - input and filter plugins"
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"
@@ -36,8 +36,9 @@ Gem::Specification.new do |s|
36
36
  s.add_runtime_dependency 'tzinfo-data'
37
37
  # 3.5 limitation is required for jdbc-static loading schedule
38
38
  s.add_runtime_dependency 'rufus-scheduler', '< 3.5'
39
- s.add_runtime_dependency 'logstash-mixin-ecs_compatibility_support', '~>1.2'
39
+ s.add_runtime_dependency 'logstash-mixin-ecs_compatibility_support', '~>1.3'
40
40
  s.add_runtime_dependency "logstash-mixin-validator_support", '~> 1.0'
41
+ s.add_runtime_dependency "logstash-mixin-event_support", '~> 1.0'
41
42
 
42
43
  s.add_development_dependency "childprocess"
43
44
  s.add_development_dependency 'logstash-devutils'
@@ -249,6 +249,41 @@ module LogStash module Filters module Jdbc
249
249
  end
250
250
  end
251
251
 
252
+ describe "lookup operations when prepareStatement throws" do
253
+ let(:local_db) { double("local_db") }
254
+ let(:lookup_hash) do
255
+ {
256
+ "query" => "select * from servers WHERE ip LIKE ? AND os LIKE ?",
257
+ "prepared_parameters" => ["%%{[ip]}"],
258
+ "target" => "server",
259
+ "tag_on_failure" => ["_jdbcstaticfailure_server"]
260
+ }
261
+ end
262
+ let(:event) { LogStash::Event.new()}
263
+ let(:records) { [{"name" => "ldn-1-23", "rack" => "2:1:6"}] }
264
+ let(:prepared_statement) { double("prepared_statement")}
265
+
266
+ subject(:lookup) { described_class.new(lookup_hash, {}, "lookup-1") }
267
+
268
+ before(:each) do
269
+ allow(local_db).to receive(:prepare).once.and_return(prepared_statement)
270
+ allow(prepared_statement).to receive(:call).once.and_raise(Java::JavaSql::SQLTransactionRollbackException.new)
271
+ end
272
+
273
+ it "must not be valid" do
274
+ expect(subject.valid?).to be_falsey
275
+ end
276
+
277
+ it "should tag event as failed" do
278
+ event.set("ip", "20.20")
279
+ event.set("os", "MacOS")
280
+ subject.prepare(local_db)
281
+ subject.enhance(local_db, event)
282
+ expect(event.get("tags")).to eq(["_jdbcstaticfailure_server"])
283
+ expect(event.get("server")).to be_nil
284
+ end
285
+ end
286
+
252
287
  describe "validation of target option" do
253
288
  let(:lookup_hash) do
254
289
  {
@@ -364,7 +364,7 @@ describe LogStash::Inputs::Jdbc do
364
364
  end
365
365
 
366
366
  it "should log a warn of missed target usage" do
367
- expect(plugin.logger).to receive(:info).once.with(/ECS compatibility is enabled but no .*?target.*? was specified/)
367
+ expect(plugin.logger).to receive(:info).once.with(a_string_including("ECS compatibility is enabled").and(including("target")))
368
368
 
369
369
  plugin.register
370
370
  end
@@ -0,0 +1,23 @@
1
+ # encoding: utf-8
2
+ require "logstash/devutils/rspec/spec_helper"
3
+ require "logstash/plugin_mixins/jdbc_streaming/parameter_handler"
4
+
5
+
6
+ describe LogStash::PluginMixins::JdbcStreaming::ParameterHandler do
7
+ context "resolve field reference" do
8
+ let(:event) { ::LogStash::Event.new("field" => "field_value") }
9
+
10
+ it "should resolve root field" do
11
+ handler = LogStash::PluginMixins::JdbcStreaming::ParameterHandler.build_bind_value_handler "[field]"
12
+ handler.extract_from(event)
13
+ expect(handler.extract_from(event)).to eq "field_value"
14
+ end
15
+
16
+ it "should resolve nested field" do
17
+ event = ::LogStash::Event.from_json("{\"field\": {\"nested\": \"nested_field\"}}").first
18
+ handler = LogStash::PluginMixins::JdbcStreaming::ParameterHandler.build_bind_value_handler "[field][nested]"
19
+ handler.extract_from(event)
20
+ expect(handler.extract_from(event)).to eq "nested_field"
21
+ end
22
+ end
23
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-integration-jdbc
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.1.1
4
+ version: 5.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elastic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-05-26 00:00:00.000000000 Z
11
+ date: 2021-08-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -147,7 +147,7 @@ dependencies:
147
147
  requirements:
148
148
  - - "~>"
149
149
  - !ruby/object:Gem::Version
150
- version: '1.2'
150
+ version: '1.3'
151
151
  name: logstash-mixin-ecs_compatibility_support
152
152
  prerelease: false
153
153
  type: :runtime
@@ -155,7 +155,7 @@ dependencies:
155
155
  requirements:
156
156
  - - "~>"
157
157
  - !ruby/object:Gem::Version
158
- version: '1.2'
158
+ version: '1.3'
159
159
  - !ruby/object:Gem::Dependency
160
160
  requirement: !ruby/object:Gem::Requirement
161
161
  requirements:
@@ -170,6 +170,20 @@ dependencies:
170
170
  - - "~>"
171
171
  - !ruby/object:Gem::Version
172
172
  version: '1.0'
173
+ - !ruby/object:Gem::Dependency
174
+ requirement: !ruby/object:Gem::Requirement
175
+ requirements:
176
+ - - "~>"
177
+ - !ruby/object:Gem::Version
178
+ version: '1.0'
179
+ name: logstash-mixin-event_support
180
+ prerelease: false
181
+ type: :runtime
182
+ version_requirements: !ruby/object:Gem::Requirement
183
+ requirements:
184
+ - - "~>"
185
+ - !ruby/object:Gem::Version
186
+ version: '1.0'
173
187
  - !ruby/object:Gem::Dependency
174
188
  requirement: !ruby/object:Gem::Requirement
175
189
  requirements:
@@ -238,6 +252,7 @@ files:
238
252
  - CONTRIBUTORS
239
253
  - Gemfile
240
254
  - LICENSE
255
+ - NOTICE.TXT
241
256
  - README.md
242
257
  - docs/filter-jdbc_static.asciidoc
243
258
  - docs/filter-jdbc_streaming.asciidoc
@@ -292,6 +307,7 @@ files:
292
307
  - spec/helpers/derbyrun.jar
293
308
  - spec/inputs/integration/integ_spec.rb
294
309
  - spec/inputs/jdbc_spec.rb
310
+ - spec/plugin_mixins/jdbc_streaming/parameter_handler_spec.rb
295
311
  - vendor/jar-dependencies/org/apache/derby/derby/10.14.1.0/derby-10.14.1.0.jar
296
312
  - vendor/jar-dependencies/org/apache/derby/derbyclient/10.14.1.0/derbyclient-10.14.1.0.jar
297
313
  homepage: http://www.elastic.co/guide/en/logstash/current/index.html
@@ -317,8 +333,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
317
333
  - !ruby/object:Gem::Version
318
334
  version: '0'
319
335
  requirements: []
320
- rubyforge_project:
321
- rubygems_version: 2.6.13
336
+ rubygems_version: 3.1.6
322
337
  signing_key:
323
338
  specification_version: 4
324
339
  summary: Integration with JDBC - input and filter plugins
@@ -344,3 +359,4 @@ test_files:
344
359
  - spec/helpers/derbyrun.jar
345
360
  - spec/inputs/integration/integ_spec.rb
346
361
  - spec/inputs/jdbc_spec.rb
362
+ - spec/plugin_mixins/jdbc_streaming/parameter_handler_spec.rb