logstash-output-jdbc 0.2.4 → 0.2.5

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: 11df8d90fc625796c8e26524da7b4e80c1e9a13d
4
- data.tar.gz: cb3028a262a96ce556ff4c2af681261ae433a56e
3
+ metadata.gz: 42579f38d0761b8192520ef41f03c42d501b139a
4
+ data.tar.gz: 1ef31995f6535109cf5caedb1c91a8a90aac6c25
5
5
  SHA512:
6
- metadata.gz: 648f9e2c37443605740417854dbe817043f977ab06bb4596a6b7f0fab11a22d48c8c2a0c6fb266d39a313ac4c696b0936d6305ec0e67c5647ef9b206ceea2706
7
- data.tar.gz: 79c1fc7095eccd42368b09081f9df5f954ccc6dfa03ef272df8d890cfa0b910c8f00a2f5deb01e1fea0684619450143a43d0fc53656d5213320868a743129655
6
+ metadata.gz: 84a86a3afda777d90da998f4b37eebcb7a64bd8704dbc44b7084764d3dba29009506468d107ecd3c6069014da887581369fb1faf714a39572dd8dabd83961f9c
7
+ data.tar.gz: 8b3288422002936ba26d3c3bc125935248690c869d1f687e128f1faf5d2e89ed9c2007f093193c2ec33edc143a367a20a39710b7f4207f5c054a157f175d5779
data/README.md CHANGED
@@ -11,16 +11,14 @@ If you do find this works for a JDBC driver not listed, let me know and provide
11
11
  This plugin does not bundle any JDBC jar files, and does expect them to be in a
12
12
  particular location. Please ensure you read the 4 installation lines below.
13
13
 
14
- ## Headlines
15
- - Support for connection pooling added in 0.2.0
16
- - Support for unsafe statement handling (allowing dynamic queries) in 0.2.0
17
- - Altered exception handling to now count sequential flushes with exceptions thrown in 0.2.0
14
+ ## ChangeLog
15
+ See CHANGELOG.md
18
16
 
19
17
  ## Versions
20
18
  Released versions are are tagged as of v0.2.1, and available via rubygems.
21
19
 
22
20
  For development:
23
- - See master branch for logstash v2+
21
+ - See master branch for logstash v2
24
22
  - See v1.5 branch for logstash v1.5
25
23
  - See v1.4 branch for logstash 1.4
26
24
 
@@ -34,11 +32,14 @@ For development:
34
32
  - And then configure (examples below)
35
33
 
36
34
  ## Running tests
37
- Assuming valid JDBC jar, and jruby is setup and installed, and you have issued `jruby -S bundle install` in the development directory
38
- - `SQL_JAR=path/to/your.jar jruby -S bundle exec rspec`
39
- If you need to provide username and password you may do this via the environment variables `SQL_USERNAME` and `SQL_PASSWORD`.
35
+ At this time tests only run against Derby, in an in-memory database.
36
+ Acceptance tests for individual database engines will be added over time.
40
37
 
41
- Tests are not yet 100% complete.
38
+ Assuming valid jruby is installed
39
+ - First time, issue `jruby -S bundle install` to install dependencies
40
+ - Next, download Derby jar from https://db.apache.org/derby/
41
+ - Run the tests `JDBC_DERBY_JAR=path/to/derby.jar jruby -S rspec`
42
+ - Optionally add the `JDBC_DEBUG=1` env variable to add logging to stdout
42
43
 
43
44
  ## Configuration options
44
45
 
@@ -250,9 +250,12 @@ class LogStash::Outputs::Jdbc < LogStash::Outputs::Base
250
250
  def add_statement_event_params(statement, event)
251
251
  @statement[1..-1].each_with_index do |i, idx|
252
252
  case event[i]
253
- when Time, LogStash::Timestamp
253
+ when Time
254
254
  # Most reliable solution, cross JDBC driver
255
255
  statement.setString(idx + 1, event[i].iso8601())
256
+ when LogStash::Timestamp
257
+ # Most reliable solution, cross JDBC driver
258
+ statement.setString(idx + 1, event[i].to_iso8601())
256
259
  when Fixnum, Integer
257
260
  statement.setInt(idx + 1, event[i])
258
261
  when Float
@@ -4,92 +4,93 @@ require "stud/temporary"
4
4
  require "java"
5
5
 
6
6
  describe LogStash::Outputs::Jdbc do
7
- def fetch_log_table_rowcount
8
- # sleep for a second to let the flush happen
9
- sleep 1
10
-
11
- stmt = @sql.createStatement()
12
- rs = stmt.executeQuery("select count(*) as total from log")
13
- count = 0
14
- while rs.next()
15
- count = rs.getInt("total")
16
- end
17
- stmt.close()
18
7
 
19
- return count
8
+ let(:derby_settings) do
9
+ {
10
+ "driver_class" => "org.apache.derby.jdbc.EmbeddedDriver",
11
+ "connection_string" => "jdbc:derby:memory:testdb;create=true",
12
+ "driver_jar_path" => ENV['JDBC_DERBY_JAR'],
13
+ # Grumble. Grumble.
14
+ # Derby doesn't like 'T' in timestamps as of current writing, so for now
15
+ # we'll just use CURRENT_TIMESTAMP as opposed to the event @timestamp
16
+ "statement" => [ "insert into log (created_at, message) values(CURRENT_TIMESTAMP, ?)", "message" ]
17
+ }
20
18
  end
21
19
 
22
- let(:base_settings) { {
23
- "driver_jar_path" => @driver_jar_path,
24
- "connection_string" => @test_connection_string,
25
- "username" => ENV['SQL_USERNAME'],
26
- "password" => ENV['SQL_PASSWORD'],
27
- "statement" => [ "insert into log (message) values(?)", "message" ],
28
- "max_pool_size" => 1,
29
- "flush_size" => 1,
30
- "max_flush_exceptions" => 1
31
- } }
32
- let(:test_settings) { {} }
33
- let(:plugin) { LogStash::Outputs::Jdbc.new(base_settings.merge(test_settings)) }
34
- let(:event_fields) { { "message" => "This is a message!" } }
35
- let(:event) { LogStash::Event.new(event_fields) }
36
-
37
- before(:all) do
38
- @driver_jar_path = File.absolute_path(ENV['SQL_JAR'])
39
- @test_db_path = File.join(Stud::Temporary.directory, "test.db")
40
- @test_connection_string = "jdbc:sqlite:#{@test_db_path}"
41
-
42
- require @driver_jar_path
43
-
44
- @sql = java.sql.DriverManager.get_connection(@test_connection_string, ENV['SQL_USERNAME'].to_s, ENV['SQL_PASSWORD'].to_s)
45
- stmt = @sql.createStatement()
46
- stmt.executeUpdate("CREATE table log (host text, timestamp datetime, message text);")
47
- stmt.close()
48
- end
20
+ context 'rspec setup' do
49
21
 
50
- before(:each) do
51
- stmt = @sql.createStatement()
52
- stmt.executeUpdate("delete from log")
53
- stmt.close()
22
+ it 'ensure derby is available' do
23
+ j = ENV['JDBC_DERBY_JAR']
24
+ expect(j).not_to be_nil, "JDBC_DERBY_JAR not defined, required to run tests"
25
+ expect(File.exists?(j)).to eq(true), "JDBC_DERBY_JAR defined, but not valid"
26
+ end
27
+
54
28
  end
55
29
 
56
- after(:all) do
57
- File.unlink(@test_db_path)
58
- Dir.rmdir(File.dirname(@test_db_path))
59
- end
30
+ context 'when initializing' do
60
31
 
61
- describe "safe statement" do
62
- it "should register without errors" do
63
- expect { plugin.register }.to_not raise_error
32
+ it 'shouldn\'t register without a config' do
33
+ expect {
34
+ LogStash::Plugin.lookup("output", "jdbc").new()
35
+ }.to raise_error(LogStash::ConfigurationError)
64
36
  end
65
37
 
66
- it "receive event, without error" do
67
- plugin.register
68
- expect { plugin.receive(event) }.to_not raise_error
38
+ it 'shouldn\'t register with a missing jar file' do
39
+ derby_settings['driver_jar_path'] = nil
40
+ plugin = LogStash::Plugin.lookup("output", "jdbc").new(derby_settings)
41
+ expect { plugin.register }.to raise_error
42
+ end
69
43
 
70
- expect(fetch_log_table_rowcount).to eq(1)
44
+ it 'shouldn\'t register with a missing jar file' do
45
+ derby_settings['connection_string'] = nil
46
+ plugin = LogStash::Plugin.lookup("output", "jdbc").new(derby_settings)
47
+ expect { plugin.register }.to raise_error
71
48
  end
72
49
 
73
50
  end
74
51
 
75
- describe "unsafe statement" do
76
- let(:event_fields) {
77
- { "message" => "This is a message!", "table" => "log" }
78
- }
79
- let(:test_settings) { {
80
- "statement" => [ "insert into %{table} (message) values(?)", "message" ],
81
- "unsafe_statement" => true
82
- } }
83
-
84
- it "should register without errors" do
85
- expect { plugin.register }.to_not raise_error
52
+ context 'when outputting messages' do
53
+
54
+ let(:event_fields) do
55
+ { message: 'test-message' }
86
56
  end
57
+ let(:event) { LogStash::Event.new(event_fields) }
58
+ let(:plugin) {
59
+ # Setup plugin
60
+ output = LogStash::Plugin.lookup("output", "jdbc").new(derby_settings)
61
+ output.register
62
+ if ENV['JDBC_DEBUG'] == '1'
63
+ output.logger.subscribe(STDOUT)
64
+ end
65
+
66
+ # Setup table
67
+ c = output.instance_variable_get(:@pool).getConnection()
68
+ stmt = c.createStatement()
69
+ stmt.executeUpdate("CREATE table log (created_at timestamp, message varchar(512))")
70
+ stmt.close()
71
+ c.close()
72
+
73
+ output
74
+ }
87
75
 
88
- it "receive event, without error" do
89
- plugin.register
90
- plugin.receive(event)
91
- expect(fetch_log_table_rowcount).to eq(1)
76
+ it 'should save a event' do
77
+ expect { plugin.receive(event) }.to_not raise_error
78
+
79
+ # Wait for 1 second, for the buffer to flush
80
+ sleep 1
81
+
82
+ c = plugin.instance_variable_get(:@pool).getConnection()
83
+ stmt = c.createStatement()
84
+ rs = stmt.executeQuery("select count(*) as total from log")
85
+ count = 0
86
+ while rs.next()
87
+ count = rs.getInt("total")
88
+ end
89
+ stmt.close()
90
+ c.close()
91
+ expect(count).to be > 0
92
92
  end
93
-
93
+
94
94
  end
95
+
95
96
  end
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.4
4
+ version: 0.2.5
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: 2016-04-07 00:00:00.000000000 Z
11
+ date: 2016-04-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: logstash-core
@@ -112,7 +112,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
112
112
  version: '0'
113
113
  requirements: []
114
114
  rubyforge_project:
115
- rubygems_version: 2.0.14
115
+ rubygems_version: 2.0.14.1
116
116
  signing_key:
117
117
  specification_version: 4
118
118
  summary: This plugin allows you to output to SQL, via JDBC