logstash-output-jdbc 0.3.2-java → 5.0.0-java

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: fe8c75828cf4838f6cb1df9ed10a067c82686398
4
- data.tar.gz: 49d23e6f1ef4efb45cb6becf33af21a02d41b969
3
+ metadata.gz: 727a931f9b189e29d515b0798e010f276f5def1f
4
+ data.tar.gz: ed78ddac198f7eb2411da80c51893d44bd6fd52b
5
5
  SHA512:
6
- metadata.gz: 726d2e0f254e004614bbe6f21ef9baccc77b382c6afbeffbf9dfd141a378dcb7b0349032c2a9d57b63f49051313cc0c750f2bcfa6432e53c7187602ac33e49b2
7
- data.tar.gz: 20f0098bec13c4401560fdf6ba48391dc2607302a4055a1c5c3e98e50161d7811867fd9c2db7c5dbd3e8926054d74dd0db16629a51ae6418e13427a0b0fbd191
6
+ metadata.gz: 7176a744ec917960465f5c874eeb0f81ede3c89f442822f391b898326004ff92d274e6c08dd7312b26f224a72f353be1e91130200a722642b03fc1c96ca14061
7
+ data.tar.gz: f7597c9e0cf41ad3417ba26d316cfea0e0a9533f2e387f73578dc87e33e6041caedac209bb03e7fe05e2f9dfbf894d0cc749e626f7616ecd9309b866337f7125
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # logstash-output-jdbc
2
2
 
3
- [![Build Status](https://travis-ci.org/theangryangel/logstash-output-jdbc.svg?branch=v2.x)](https://travis-ci.org/theangryangel/logstash-output-jdbc)
3
+ [![Build Status](https://travis-ci.org/theangryangel/logstash-output-jdbc.svg?branch=master)](https://travis-ci.org/theangryangel/logstash-output-jdbc)
4
4
 
5
5
  This plugin is provided as an external plugin and is not part of the Logstash project.
6
6
 
@@ -21,7 +21,7 @@ See CHANGELOG.md
21
21
  Released versions are available via rubygems, and typically tagged.
22
22
 
23
23
  For development:
24
- - See master branch for logstash v5 (currently **development only**)
24
+ - See master branch for logstash v5
25
25
  - See v2.x branch for logstash v2
26
26
  - See v1.5 branch for logstash v1.5
27
27
  - See v1.4 branch for logstash 1.4
@@ -47,8 +47,8 @@ For development:
47
47
  | username | String | JDBC username - this is optional as it may be included in the connection string, for many drivers | No | |
48
48
  | password | String | JDBC password - this is optional as it may be included in the connection string, for many drivers | No | |
49
49
  | statement | Array | An array of strings representing the SQL statement to run. Index 0 is the SQL statement that is prepared, all other array entries are passed in as parameters (in order). A parameter may either be a property of the event (i.e. "@timestamp", or "host") or a formatted string (i.e. "%{host} - %{message}" or "%{message}"). If a key is passed then it will be automatically converted as required for insertion into SQL. If it's a formatted string then it will be passed in verbatim. | Yes | |
50
- | unsafe_statement | Boolean | If yes, the statement is evaluated for event fields - this allows you to use dynamic table names, etc. **This is highly dangerous** and you should **not** use this unless you are 100% sure that the field(s) you are passing in are 100% safe. Failure to do so will result in possible SQL injections. Please be aware that there is also a potential performance penalty as each event must be evaluated and inserted into SQL one at a time, where as when this is false multiple events are inserted at once. Example statement: [ "insert into %{table_name_field} (column) values(?)", "fieldname" ] | No | False |
51
- | max_pool_size | Number | Maximum number of connections to open to the SQL server at any 1 time. Default set to same as Logstash default number of workers | No | 24 |
50
+ | unsafe_statement | Boolean | If yes, the statement is evaluated for event fields - this allows you to use dynamic table names, etc. **This is highly dangerous** and you should **not** use this unless you are 100% sure that the field(s) you are passing in are 100% safe. Failure to do so will result in possible SQL injections. Example statement: [ "insert into %{table_name_field} (column) values(?)", "fieldname" ] | No | False |
51
+ | max_pool_size | Number | Maximum number of connections to open to the SQL server at any 1 time | No | 5 |
52
52
  | connection_timeout | Number | Number of seconds before a SQL connection is closed | No | 2800 |
53
53
  | flush_size | Number | Maximum number of entries to buffer before sending to SQL - if this is reached before idle_flush_time | No | 1000 |
54
54
  | max_flush_exceptions | Number | Number of sequential flushes which cause an exception, before the set of events are discarded. Set to a value less than 1 if you never want it to stop. This should be carefully configured with respect to retry_initial_interval and retry_max_interval, if your SQL server is not highly available | No | 10 |
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
  require 'logstash/environment'
3
3
 
4
- root_dir = File.expand_path(File.join(File.dirname(__FILE__), ".."))
5
- LogStash::Environment.load_runtime_jars! File.join(root_dir, "vendor")
4
+ root_dir = File.expand_path(File.join(File.dirname(__FILE__), '..'))
5
+ LogStash::Environment.load_runtime_jars! File.join(root_dir, 'vendor')
@@ -12,7 +12,7 @@ require 'logstash-output-jdbc_jars'
12
12
  # includes correctly crafting the SQL statement, and matching the number of
13
13
  # parameters correctly.
14
14
  class LogStash::Outputs::Jdbc < LogStash::Outputs::Base
15
- declare_threadsafe! if self.respond_to?(:declare_threadsafe!)
15
+ concurrency :shared
16
16
 
17
17
  STRFTIME_FMT = '%Y-%m-%d %T.%L'.freeze
18
18
 
@@ -98,7 +98,6 @@ class LogStash::Outputs::Jdbc < LogStash::Outputs::Base
98
98
  def register
99
99
  @logger.info('JDBC - Starting up')
100
100
 
101
- LogStash::Logger.setup_log4j(@logger)
102
101
  load_jar_files!
103
102
 
104
103
  @stopping = Concurrent::AtomicBoolean.new(false)
@@ -122,10 +121,6 @@ class LogStash::Outputs::Jdbc < LogStash::Outputs::Base
122
121
  end
123
122
  end
124
123
 
125
- def receive(event)
126
- retrying_submit([event])
127
- end
128
-
129
124
  def close
130
125
  @stopping.make_true
131
126
  @pool.close
@@ -156,7 +151,7 @@ class LogStash::Outputs::Jdbc < LogStash::Outputs::Base
156
151
  # Test connection
157
152
  test_connection = @pool.getConnection
158
153
  unless test_connection.isValid(validate_connection_timeout)
159
- @logger.error('JDBC - Connection is not reporting as validate. Either connection is invalid, or driver is not getting the appropriate response.')
154
+ @logger.warn('JDBC - Connection is not reporting as validate. Either connection is invalid, or driver is not getting the appropriate response.')
160
155
  end
161
156
  test_connection.close
162
157
  end
@@ -177,13 +172,13 @@ class LogStash::Outputs::Jdbc < LogStash::Outputs::Base
177
172
  File.join(File.dirname(__FILE__), '../../../vendor/jar/jdbc/*.jar')
178
173
  end
179
174
 
180
- @logger.debug('JDBC - jarpath', path: jarpath)
175
+ @logger.trace('JDBC - jarpath', path: jarpath)
181
176
 
182
177
  jars = Dir[jarpath]
183
178
  raise LogStash::ConfigurationError, 'JDBC - No jars found. Have you read the README?' if jars.empty?
184
179
 
185
180
  jars.each do |jar|
186
- @logger.debug('JDBC - Loaded jar', jar: jar)
181
+ @logger.trace('JDBC - Loaded jar', jar: jar)
187
182
  require jar
188
183
  end
189
184
  end
@@ -258,14 +253,14 @@ class LogStash::Outputs::Jdbc < LogStash::Outputs::Base
258
253
  def add_statement_event_params(statement, event)
259
254
  @statement[1..-1].each_with_index do |i, idx|
260
255
  if i.is_a? String
261
- value = event[i]
256
+ value = event.get(i)
262
257
  if value.nil? and i =~ /%\{/
263
258
  value = event.sprintf(i)
264
259
  end
265
260
  else
266
261
  value = i
267
262
  end
268
-
263
+
269
264
  case value
270
265
  when Time
271
266
  # See LogStash::Timestamp, below, for the why behind strftime.
@@ -280,8 +275,6 @@ class LogStash::Outputs::Jdbc < LogStash::Outputs::Base
280
275
  # strftime appears to be the most reliable across drivers.
281
276
  statement.setString(idx + 1, value.time.strftime(STRFTIME_FMT))
282
277
  when Fixnum, Integer
283
- # bit_length doesn't exist in the current version of ruby/jruby logstash targets
284
- # and this seems quicker than doing some Math.log2(value < 0 ? -value : value+1).ceil shit
285
278
  if value > 2147483647 or value < -2147483648
286
279
  statement.setLong(idx + 1, value)
287
280
  else
@@ -314,7 +307,7 @@ class LogStash::Outputs::Jdbc < LogStash::Outputs::Base
314
307
  log_method = (retrying ? 'warn' : 'error')
315
308
 
316
309
  loop do
317
- @logger.send(log_method, log_text, :exception => current_exception, :backtrace => current_exception.backtrace)
310
+ @logger.send(log_method, log_text, :exception => current_exception)
318
311
 
319
312
  if current_exception.respond_to? 'getNextException'
320
313
  current_exception = current_exception.getNextException()
@@ -4,6 +4,32 @@ require 'stud/temporary'
4
4
  require 'java'
5
5
  require 'securerandom'
6
6
 
7
+ RSpec.configure do |c|
8
+
9
+ def start_service(name)
10
+ cmd = "sudo /etc/init.d/#{name}* start"
11
+
12
+ `which systemctl`
13
+ if $?.success?
14
+ cmd = "sudo systemctl start #{name}"
15
+ end
16
+
17
+ `#{cmd}`
18
+ end
19
+
20
+ def stop_service(name)
21
+ cmd = "sudo /etc/init.d/#{name}* stop"
22
+
23
+ `which systemctl`
24
+ if $?.success?
25
+ cmd = "sudo systemctl stop #{name}"
26
+ end
27
+
28
+ `#{cmd}`
29
+ end
30
+
31
+ end
32
+
7
33
  RSpec.shared_context 'rspec setup' do
8
34
  it 'ensure jar is available' do
9
35
  expect(ENV[jdbc_jar_env]).not_to be_nil, "#{jdbc_jar_env} not defined, required to run tests"
@@ -20,7 +46,9 @@ RSpec.shared_context 'when initializing' do
20
46
  end
21
47
 
22
48
  RSpec.shared_context 'when outputting messages' do
23
- let(:logger) { double("logger") }
49
+ let(:logger) {
50
+ double("logger")
51
+ }
24
52
 
25
53
  let(:jdbc_test_table) do
26
54
  'logstash_output_jdbc_test'
@@ -43,16 +71,27 @@ RSpec.shared_context 'when outputting messages' do
43
71
  end
44
72
 
45
73
  let(:event_fields) do
46
- { 'message' => "test-message #{SecureRandom.uuid}" }
74
+ { message: "test-message #{SecureRandom.uuid}" }
47
75
  end
48
76
 
49
77
  let(:event) { LogStash::Event.new(event_fields) }
50
78
 
51
79
  let(:plugin) do
80
+ # Setup logger
81
+ allow(LogStash::Outputs::Jdbc).to receive(:logger).and_return(logger)
82
+
83
+ # XXX: Suppress reflection logging. There has to be a better way around this.
84
+ allow(logger).to receive(:debug).with(/config LogStash::/)
85
+
86
+ # Suppress beta warnings.
87
+ allow(logger).to receive(:info).with(/Please let us know if you find bugs or have suggestions on how to improve this plugin./)
88
+
89
+ # Suppress start up messages.
90
+ expect(logger).to receive(:info).once.with(/JDBC - Starting up/)
91
+
52
92
  # Setup plugin
53
93
  output = LogStash::Plugin.lookup('output', 'jdbc').new(jdbc_settings)
54
94
  output.register
55
- output.logger = logger
56
95
 
57
96
  # Setup table
58
97
  c = output.instance_variable_get(:@pool).getConnection
@@ -82,7 +121,7 @@ RSpec.shared_context 'when outputting messages' do
82
121
  # Verify the number of items in the output table
83
122
  c = plugin.instance_variable_get(:@pool).getConnection
84
123
  stmt = c.prepareStatement("select count(*) as total from #{jdbc_test_table} where message = ?")
85
- stmt.setString(1, event['message'])
124
+ stmt.setString(1, event.get('message'))
86
125
  rs = stmt.executeQuery
87
126
  count = 0
88
127
  count = rs.getInt('total') while rs.next
@@ -93,10 +132,14 @@ RSpec.shared_context 'when outputting messages' do
93
132
  end
94
133
 
95
134
  it 'should not save event, and log an unretryable exception' do
96
- e = LogStash::Event.new({})
135
+ e = event
136
+ original_event = e.get('message')
137
+ e.set('message', nil)
97
138
 
98
139
  expect(logger).to receive(:error).once.with(/JDBC - Exception. Not retrying/, Hash)
99
- expect { plugin.multi_receive([e]) }.to_not raise_error
140
+ expect { plugin.multi_receive([event]) }.to_not raise_error
141
+
142
+ e.set('message', original_event)
100
143
  end
101
144
 
102
145
  it 'it should retry after a connection loss, and log a warning' do
@@ -107,29 +150,21 @@ RSpec.shared_context 'when outputting messages' do
107
150
  # Check that everything is fine right now
108
151
  expect { p.multi_receive([event]) }.not_to raise_error
109
152
 
110
- # Start a thread to stop and restart the service.
111
- t = Thread.new(systemd_database_service) { |systemd_database_service|
112
- start_stop_cmd = 'sudo /etc/init.d/%<service>s* %<action>s'
113
-
114
- `which systemctl`
115
- if $?.success?
116
- start_stop_cmd = 'sudo systemctl %<action>s %<service>s'
117
- end
118
-
119
- cmd = start_stop_cmd % { action: 'stop', service: systemd_database_service }
120
- `#{cmd}`
121
- sleep 10
153
+ stop_service(systemd_database_service)
122
154
 
123
- cmd = start_stop_cmd % { action: 'start', service: systemd_database_service }
124
- `#{cmd}`
155
+ # Start a thread to restart the service after the fact.
156
+ t = Thread.new(systemd_database_service) { |systemd_database_service|
157
+ sleep 20
158
+
159
+ start_service(systemd_database_service)
125
160
  }
126
161
 
127
- # Wait a few seconds to the service to stop
128
- sleep 5
129
-
162
+ t.run
163
+
130
164
  expect(logger).to receive(:warn).at_least(:once).with(/JDBC - Exception. Retrying/, Hash)
131
165
  expect { p.multi_receive([event]) }.to_not raise_error
132
166
 
167
+ # Wait for the thread to finish
133
168
  t.join
134
169
  end
135
170
  end
metadata CHANGED
@@ -1,160 +1,164 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-output-jdbc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 5.0.0
5
5
  platform: java
6
6
  authors:
7
7
  - the_angry_angel
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-15 00:00:00.000000000 Z
11
+ date: 2016-11-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: logstash-core-plugin-api
15
14
  requirement: !ruby/object:Gem::Requirement
16
15
  requirements:
17
- - - ~>
16
+ - - ">="
18
17
  - !ruby/object:Gem::Version
19
- version: '1.0'
20
- type: :runtime
18
+ version: '1.60'
19
+ - - "<="
20
+ - !ruby/object:Gem::Version
21
+ version: '2.99'
22
+ name: logstash-core-plugin-api
21
23
  prerelease: false
24
+ type: :runtime
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
- - - ~>
27
+ - - ">="
25
28
  - !ruby/object:Gem::Version
26
- version: '1.0'
29
+ version: '1.60'
30
+ - - "<="
31
+ - !ruby/object:Gem::Version
32
+ version: '2.99'
27
33
  - !ruby/object:Gem::Dependency
28
- name: stud
29
34
  requirement: !ruby/object:Gem::Requirement
30
35
  requirements:
31
- - - '>='
36
+ - - ">="
32
37
  - !ruby/object:Gem::Version
33
38
  version: '0'
34
- type: :runtime
39
+ name: stud
35
40
  prerelease: false
41
+ type: :runtime
36
42
  version_requirements: !ruby/object:Gem::Requirement
37
43
  requirements:
38
- - - '>='
44
+ - - ">="
39
45
  - !ruby/object:Gem::Version
40
46
  version: '0'
41
47
  - !ruby/object:Gem::Dependency
42
- name: logstash-codec-plain
43
48
  requirement: !ruby/object:Gem::Requirement
44
49
  requirements:
45
- - - '>='
50
+ - - ">="
46
51
  - !ruby/object:Gem::Version
47
52
  version: '0'
48
- type: :runtime
53
+ name: logstash-codec-plain
49
54
  prerelease: false
55
+ type: :runtime
50
56
  version_requirements: !ruby/object:Gem::Requirement
51
57
  requirements:
52
- - - '>='
58
+ - - ">="
53
59
  - !ruby/object:Gem::Version
54
60
  version: '0'
55
61
  - !ruby/object:Gem::Dependency
56
- name: jar-dependencies
57
62
  requirement: !ruby/object:Gem::Requirement
58
63
  requirements:
59
- - - '>='
64
+ - - ">="
60
65
  - !ruby/object:Gem::Version
61
66
  version: '0'
62
- type: :development
67
+ name: jar-dependencies
63
68
  prerelease: false
69
+ type: :development
64
70
  version_requirements: !ruby/object:Gem::Requirement
65
71
  requirements:
66
- - - '>='
72
+ - - ">="
67
73
  - !ruby/object:Gem::Version
68
74
  version: '0'
69
75
  - !ruby/object:Gem::Dependency
70
- name: ruby-maven
71
76
  requirement: !ruby/object:Gem::Requirement
72
77
  requirements:
73
- - - ~>
78
+ - - "~>"
74
79
  - !ruby/object:Gem::Version
75
80
  version: '3.3'
76
- type: :development
81
+ name: ruby-maven
77
82
  prerelease: false
83
+ type: :development
78
84
  version_requirements: !ruby/object:Gem::Requirement
79
85
  requirements:
80
- - - ~>
86
+ - - "~>"
81
87
  - !ruby/object:Gem::Version
82
88
  version: '3.3'
83
89
  - !ruby/object:Gem::Dependency
84
- name: logstash-devutils
85
90
  requirement: !ruby/object:Gem::Requirement
86
91
  requirements:
87
- - - '>='
92
+ - - ">="
88
93
  - !ruby/object:Gem::Version
89
94
  version: '0'
90
- type: :development
95
+ name: logstash-devutils
91
96
  prerelease: false
97
+ type: :development
92
98
  version_requirements: !ruby/object:Gem::Requirement
93
99
  requirements:
94
- - - '>='
100
+ - - ">="
95
101
  - !ruby/object:Gem::Version
96
102
  version: '0'
97
103
  - !ruby/object:Gem::Dependency
98
- name: rubocop
99
104
  requirement: !ruby/object:Gem::Requirement
100
105
  requirements:
101
106
  - - '='
102
107
  - !ruby/object:Gem::Version
103
108
  version: 0.41.2
104
- type: :development
109
+ name: rubocop
105
110
  prerelease: false
111
+ type: :development
106
112
  version_requirements: !ruby/object:Gem::Requirement
107
113
  requirements:
108
114
  - - '='
109
115
  - !ruby/object:Gem::Version
110
116
  version: 0.41.2
111
- description: This gem is a logstash plugin required to be installed on top of the
112
- Logstash core pipeline using $LS_HOME/bin/plugin install gemname. This gem is not
113
- a stand-alone program
117
+ 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 'logstash-output-jdbc'. This gem is not a stand-alone program
114
118
  email: karl+github@theangryangel.co.uk
115
119
  executables: []
116
120
  extensions: []
117
121
  extra_rdoc_files: []
118
122
  files:
119
- - lib/logstash/outputs/jdbc.rb
123
+ - LICENSE.txt
124
+ - README.md
120
125
  - lib/logstash-output-jdbc_jars.rb
126
+ - lib/logstash/outputs/jdbc.rb
121
127
  - spec/jdbc_spec_helper.rb
122
128
  - spec/outputs/jdbc_derby_spec.rb
123
129
  - spec/outputs/jdbc_mysql_spec.rb
124
130
  - spec/outputs/jdbc_spec.rb
125
131
  - spec/outputs/jdbc_sqlite_spec.rb
126
- - vendor/jar-dependencies/runtime-jars/HikariCP-2.4.2.jar
132
+ - vendor/jar-dependencies/runtime-jars/HikariCP-2.4.7.jar
127
133
  - vendor/jar-dependencies/runtime-jars/log4j-1.2.17.jar
128
- - vendor/jar-dependencies/runtime-jars/slf4j-api-1.7.12.jar
134
+ - vendor/jar-dependencies/runtime-jars/slf4j-api-1.7.21.jar
129
135
  - vendor/jar-dependencies/runtime-jars/slf4j-log4j12-1.7.21.jar
130
- - LICENSE.txt
131
- - README.md
132
136
  homepage: https://github.com/theangryangel/logstash-output-jdbc
133
137
  licenses:
134
138
  - Apache License (2.0)
135
139
  metadata:
136
140
  logstash_plugin: 'true'
137
141
  logstash_group: output
138
- post_install_message:
142
+ post_install_message:
139
143
  rdoc_options: []
140
144
  require_paths:
141
145
  - lib
142
146
  required_ruby_version: !ruby/object:Gem::Requirement
143
147
  requirements:
144
- - - '>='
148
+ - - ">="
145
149
  - !ruby/object:Gem::Version
146
150
  version: '0'
147
151
  required_rubygems_version: !ruby/object:Gem::Requirement
148
152
  requirements:
149
- - - '>='
153
+ - - ">="
150
154
  - !ruby/object:Gem::Version
151
155
  version: '0'
152
156
  requirements:
153
- - jar 'com.zaxxer:HikariCP', '2.4.2'
157
+ - jar 'com.zaxxer:HikariCP', '2.4.7'
154
158
  - jar 'org.slf4j:slf4j-log4j12', '1.7.21'
155
- rubyforge_project:
156
- rubygems_version: 2.0.14.1
157
- signing_key:
159
+ rubyforge_project:
160
+ rubygems_version: 2.4.8
161
+ signing_key:
158
162
  specification_version: 4
159
163
  summary: This plugin allows you to output to SQL, via JDBC
160
164
  test_files: