logstash-input-jdbc 1.0.0 → 1.0.1

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
  SHA1:
3
- metadata.gz: 9026f853d22bd2451bfe72e0b045318ec605d77b
4
- data.tar.gz: df99f72e2ba6ddffc1f9d40c193189a1941c2dad
3
+ metadata.gz: 27d1a53b69fe6d66633b4cb36874d5ca362dea40
4
+ data.tar.gz: 9e0eddd924c285c712b9bcd4875803275b106ed0
5
5
  SHA512:
6
- metadata.gz: 948d8d265d5b6158daef86e4032958b344f49d0116ca30f6f7d3c697e875b19f69eb12ef63627c6a94c4e8bbcb5c389c9e6f935853ce5552fd2967216fe1cf92
7
- data.tar.gz: e77a3ee5bac991ef164db17776c5e35713c97e4d4667a3f5703d4b09d2a15f7b67d8e6a5732e42ce450cbaa71a1223a9f5f52282d78e7915eb8c234abfef12d5
6
+ metadata.gz: 1be7db7d416179267954031a631b066b8856d1e396772a3f4918cdcd2f6d3e5fcb6b96967a39f16082c749859e06690acaea5cc3b062c11e0e51f8dc6d41908d
7
+ data.tar.gz: 5abb561d1cfe32ffa49dbed2f0358718ace6246841c4051d002580421bfbfcddc7a161500040b6c423c934e4c2ed6898109a7792cc7f26324555870bf42026eb
data/CHANGELOG.md CHANGED
@@ -1,2 +1,6 @@
1
- * 1.0.0
1
+ ## 1.0.1
2
+ - Added ability to configure timeout
3
+ - Added catch-all configuration option for any other options that Sequel lib supports
4
+
5
+ ## 1.0.0
2
6
  - Initial release
data/README.md CHANGED
@@ -1,15 +1,15 @@
1
1
  # Logstash JDBC Input Plugin
2
2
 
3
- This is a plugin for [Logstash](https://github.com/elasticsearch/logstash).
3
+ This is a plugin for [Logstash](https://github.com/elastic/logstash).
4
4
 
5
5
  It is fully free and fully open source. The license is Apache 2.0, meaning you are pretty much free to use it however you want in whatever way.
6
6
 
7
7
  ## Documentation
8
8
 
9
- Logstash provides infrastructure to automatically generate documentation for this plugin. We use the asciidoc format to write documentation so any comments in the source code will be first converted into asciidoc and then into html. All plugin documentation are placed under one [central location](http://www.elasticsearch.org/guide/en/logstash/current/).
9
+ Logstash provides infrastructure to automatically generate documentation for this plugin. We use the asciidoc format to write documentation so any comments in the source code will be first converted into asciidoc and then into html. All plugin documentation are placed under one [central location](http://www.elastic.co/guide/en/logstash/current/).
10
10
 
11
11
  - For formatting code or config example, you can use the asciidoc `[source,ruby]` directive
12
- - For more asciidoc formatting tips, see the excellent reference here https://github.com/elasticsearch/docs#asciidoc-guide
12
+ - For more asciidoc formatting tips, see the excellent reference here https://github.com/elastic/docs#asciidoc-guide
13
13
 
14
14
  ## Need Help?
15
15
 
@@ -123,4 +123,4 @@ Programming is not a required skill. Whatever you've seen about open source and
123
123
 
124
124
  It is more important to me that you are able to contribute.
125
125
 
126
- For more information about contributing, see the [CONTRIBUTING](https://github.com/elasticsearch/logstash/blob/master/CONTRIBUTING.md) file.
126
+ For more information about contributing, see the [CONTRIBUTING](https://github.com/elastic/logstash/blob/master/CONTRIBUTING.md) file.
@@ -19,19 +19,19 @@ require "yaml" # persistence
19
19
  # ==== Scheduling
20
20
  #
21
21
  # Input from this plugin can be scheduled to run periodically according to a specific
22
- # schedule. This scheduling syntax is powered by [rufus-scheduler](https://github.com/jmettraux/rufus-scheduler).
22
+ # schedule. This scheduling syntax is powered by https://github.com/jmettraux/rufus-scheduler[rufus-scheduler].
23
23
  # The syntax is cron-like with some extensions specific to Rufus (e.g. timezone support ).
24
24
  #
25
25
  # Examples:
26
26
  #
27
27
  # |==========================================================
28
- # | * 5 * 1-3 * | will execute every minute of 5am every day of January through March.
29
- # | 0 * * * * | will execute on the 0th minute of every hour every day.
30
- # | 0 6 * * * America/Chicago | will execute at 6:00am (UTC/GMT -5) every day.
28
+ # | `* 5 * 1-3 *` | will execute every minute of 5am every day of January through March.
29
+ # | `0 * * * *` | will execute on the 0th minute of every hour every day.
30
+ # | `0 6 * * * America/Chicago` | will execute at 6:00am (UTC/GMT -5) every day.
31
31
  # |==========================================================
32
32
  #
33
33
  #
34
- # Further documentation describing this syntax can be found [here](https://github.com/jmettraux/rufus-scheduler#parsing-cronlines-and-time-strings)
34
+ # Further documentation describing this syntax can be found https://github.com/jmettraux/rufus-scheduler#parsing-cronlines-and-time-strings[here].
35
35
  #
36
36
  # ==== State
37
37
  #
@@ -90,9 +90,8 @@ require "yaml" # persistence
90
90
  # Here is the list:
91
91
  #
92
92
  # |==========================================================
93
- # |sql_last_start | The last time a statement was executed. This is set to
94
- # | | Thursday, 1 January 1970 before any query is run, and updated
95
- # | | accordingly after first query is run.
93
+ # |sql_last_start | The last time a statement was executed. This is set to Thursday, 1 January 1970
94
+ # before any query is run, and updated accordingly after first query is run.
96
95
  # |==========================================================
97
96
  #
98
97
  class LogStash::Inputs::Jdbc < LogStash::Inputs::Base
@@ -57,6 +57,37 @@ module LogStash::PluginMixins::Jdbc
57
57
  # Connection pool configuration.
58
58
  # How often to validate a connection (in seconds)
59
59
  config :jdbc_validation_timeout, :validate => :number, :default => 3600
60
+
61
+ # Connection pool configuration.
62
+ # The amount of seconds to wait to acquire a connection before raising a PoolTimeoutError (default 5)
63
+ config :jdbc_pool_timeout, :validate => :number, :default => 5
64
+
65
+ # General/Vendor-specific Sequel configuration options.
66
+ #
67
+ # An example of an optional connection pool configuration
68
+ # max_connections - The maximum number of connections the connection pool
69
+ #
70
+ # examples of vendor-specific options can be found in this
71
+ # documentation page: https://github.com/jeremyevans/sequel/blob/master/doc/opening_databases.rdoc
72
+ config :sequel_opts, :validate => :hash, :default => {}
73
+ end
74
+
75
+ private
76
+ def jdbc_connect
77
+ opts = {
78
+ :user => @jdbc_user,
79
+ :password => @jdbc_password,
80
+ :pool_timeout => @jdbc_pool_timeout
81
+ }.merge(@sequel_opts)
82
+ begin
83
+ Sequel.connect(@jdbc_connection_string, opts=opts)
84
+ rescue Sequel::PoolTimeout => e
85
+ @logger.error("Failed to connect to database. #{@jdbc_pool_timeout} second timeout exceeded.")
86
+ raise e
87
+ rescue Sequel::Error => e
88
+ @logger.error("Unable to connect to database", :error_message => e.message)
89
+ raise e
90
+ end
60
91
  end
61
92
 
62
93
  public
@@ -76,7 +107,7 @@ module LogStash::PluginMixins::Jdbc
76
107
  end
77
108
  raise LogStash::ConfigurationError, "#{e}. #{message}"
78
109
  end
79
- @database = Sequel.connect(@jdbc_connection_string, :user=> @jdbc_user, :password=> @jdbc_password.nil? ? nil : @jdbc_password.value)
110
+ @database = jdbc_connect()
80
111
  @database.extension(:pagination)
81
112
  if @jdbc_validate_connection
82
113
  @database.extension(:connection_validator)
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'logstash-input-jdbc'
3
- s.version = '1.0.0'
3
+ s.version = '1.0.1'
4
4
  s.licenses = ['Apache License (2.0)']
5
5
  s.summary = "This example input streams a string at a definable interval."
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"
@@ -301,4 +301,37 @@ describe "jdbc" do
301
301
  expect { plugin.register }.to raise_error(LogStash::ConfigurationError)
302
302
  end
303
303
  end
304
+
305
+ context "when timing out on connection" do
306
+ let(:settings) do
307
+ {
308
+ "statement" => "SELECT * FROM test_table",
309
+ "jdbc_pool_timeout" => 0,
310
+ "jdbc_connection_string" => 'mock://localhost:1527/db',
311
+ "sequel_opts" => {
312
+ "max_connections" => 1
313
+ }
314
+ }
315
+ end
316
+
317
+ it "should raise PoolTimeout error" do
318
+ plugin.register
319
+ db = plugin.instance_variable_get(:@database)
320
+ expect(db.pool.instance_variable_get(:@timeout)).to eq(0)
321
+ expect(db.pool.instance_variable_get(:@max_size)).to eq(1)
322
+
323
+ q, q1 = Queue.new, Queue.new
324
+ t = Thread.new{db.pool.hold{|c| q1.push nil; q.pop}}
325
+ q1.pop
326
+ expect{db.pool.hold {|c|}}.to raise_error(Sequel::PoolTimeout)
327
+ q.push nil
328
+ t.join
329
+ end
330
+
331
+ it "should log error message" do
332
+ allow(Sequel).to receive(:connect).and_raise(Sequel::PoolTimeout)
333
+ expect(plugin.logger).to receive(:error).with("Failed to connect to database. 0 second timeout exceeded.")
334
+ expect { plugin.register }.to raise_error(Sequel::PoolTimeout)
335
+ end
336
+ end
304
337
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-input-jdbc
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elastic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-16 00:00:00.000000000 Z
11
+ date: 2015-10-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: logstash-core
@@ -167,7 +167,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
167
167
  version: '0'
168
168
  requirements: []
169
169
  rubyforge_project:
170
- rubygems_version: 2.1.9
170
+ rubygems_version: 2.4.5
171
171
  signing_key:
172
172
  specification_version: 4
173
173
  summary: This example input streams a string at a definable interval.