logstash-output-lumberjack 1.0.1 → 1.0.2

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: 75bed5f35c130740c722189aa544dbe88f12d798
4
- data.tar.gz: 70f3fd8b618bd928a6ed17308678db824ae5d25d
3
+ metadata.gz: 7de0e64427c75281d60a669c7374e8ba2e8d2c24
4
+ data.tar.gz: 34eb43c4342dc6c4f8dc1cb1e6d0f6c32243013f
5
5
  SHA512:
6
- metadata.gz: 92b876a22c31d93a35cd8f2fb1511c0d95eeb24a31d67093db5d266ae152f4c0f8431f86b956050df04cc999fb1d914fef9a41f1b52650a6b5b4047e250bef42
7
- data.tar.gz: a02a9d5ad0d5bc15e3089b2a8f5d5a1ebe7a9897f1da29413ee90f979a243fcbc47a7fe01fceb8b2ad9b7f2938839887528dd1e550ef07662e5827c6dce97d49
6
+ metadata.gz: c415eec32245cce31416af9c575c8612a06f8125c40c26c36db42d0e4b383291ad3f78693f41de22cde49d63e39d702491715eb12e1d19e0592924d4f47609b5
7
+ data.tar.gz: 7a20703d9e80df5d3cc847d269c0c45b7793f424dcaf5ff113f1a3362e52ffda109ca8e1ffb21f826ef3b6fcf71977c94948f5f27d23d3f4d9ae7270064c2857
@@ -1,5 +1,10 @@
1
1
  # encoding: utf-8
2
+ require "logstash/outputs/base"
3
+ require "stud/buffer"
4
+ require "thread"
5
+
2
6
  class LogStash::Outputs::Lumberjack < LogStash::Outputs::Base
7
+ include Stud::Buffer
3
8
 
4
9
  config_name "lumberjack"
5
10
 
@@ -13,22 +18,41 @@ class LogStash::Outputs::Lumberjack < LogStash::Outputs::Base
13
18
  config :ssl_certificate, :validate => :path, :required => true
14
19
 
15
20
  # window size
16
- config :window_size, :validate => :number, :default => 5000
21
+ config :window_size, :validate => :number, :deprecated => "Use `flush_size`", :require => false
22
+
23
+ # To make efficient calls to the lumberjack output we are buffering events locally.
24
+ # if the number of events exceed the number the declared `flush_size` we will
25
+ # send them to the logstash server.
26
+ config :flush_size, :validate => :number, :default => 1024
27
+
28
+ # The amount of time since last flush before a flush is forced.
29
+ #
30
+ # This setting helps ensure slow event rates don't get stuck in Logstash.
31
+ # For example, if your `flush_size` is 100, and you have received 10 events,
32
+ # and it has been more than `idle_flush_time` seconds since the last flush,
33
+ # Logstash will flush those 10 events automatically.
34
+ #
35
+ # This helps keep both fast and slow log streams moving along in
36
+ # near-real-time.
37
+ config :idle_flush_time, :validate => :number, :default => 1
38
+
39
+ RECONNECT_BACKOFF_SLEEP = 0.5
17
40
 
18
41
  public
19
42
  def register
20
43
  require 'lumberjack/client'
44
+
45
+ buffer_initialize(
46
+ :max_items => max_items,
47
+ :max_interval => @idle_flush_time,
48
+ :logger => @logger
49
+ )
50
+
21
51
  connect
22
52
 
23
53
  @codec.on_event do |event, payload|
24
- begin
25
- @client.write({ 'line' => payload })
26
- rescue Exception => e
27
- @logger.error("Client write error, trying connect", :e => e, :backtrace => e.backtrace)
28
- connect
29
- retry
30
- end # begin
31
- end # @codec
54
+ buffer_receive({ "line" => payload })
55
+ end
32
56
  end # def register
33
57
 
34
58
  public
@@ -41,7 +65,23 @@ class LogStash::Outputs::Lumberjack < LogStash::Outputs::Base
41
65
  @codec.encode(event)
42
66
  end # def receive
43
67
 
68
+ def flush(events, teardown = false)
69
+ begin
70
+ @logger.info("Sending events to lumberjack", :size => events.size)
71
+ @client.write(events)
72
+ rescue Exception => e
73
+ @logger.error("Client write error, trying connect", :e => e, :backtrace => e.backtrace)
74
+ sleep(RECONNECT_BACKOFF_SLEEP)
75
+ connect
76
+ retry
77
+ end # begin
78
+ end
79
+
44
80
  private
81
+ def max_items
82
+ @window_size || @flush_size
83
+ end
84
+
45
85
  def connect
46
86
  require 'resolv'
47
87
  @logger.info("Connecting to lumberjack server.", :addresses => @hosts, :port => @port,
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
 
3
3
  s.name = 'logstash-output-lumberjack'
4
- s.version = '1.0.1'
4
+ s.version = '1.0.2'
5
5
  s.licenses = ['Apache License (2.0)']
6
6
  s.summary = "Send events using the lumberjack protocol"
7
7
  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"
@@ -23,8 +23,12 @@ Gem::Specification.new do |s|
23
23
  # Gem dependencies
24
24
  s.add_runtime_dependency "logstash-core", '>= 1.4.0', '< 2.0.0'
25
25
 
26
- s.add_runtime_dependency 'jls-lumberjack', ['>=0.0.23']
26
+ s.add_runtime_dependency 'jls-lumberjack', ['>=0.0.24']
27
+ s.add_runtime_dependency "stud"
27
28
 
28
29
  s.add_development_dependency 'logstash-devutils'
30
+ s.add_development_dependency "logstash-output-lumberjack"
31
+ s.add_development_dependency "logstash-codec-plain"
32
+ s.add_development_dependency "flores"
29
33
  end
30
34
 
@@ -1 +1,76 @@
1
+ # encoding: utf-8
2
+ require "logstash/outputs/lumberjack"
3
+ require "logstash/event"
1
4
  require "logstash/devutils/rspec/spec_helper"
5
+ require "lumberjack/server"
6
+ require "flores/pki"
7
+ require "stud/temporary"
8
+ require "fileutils"
9
+
10
+ describe "Sending events" do
11
+ let(:batch_size) { Flores::Random.integer(20..100) }
12
+ let(:batch_payload) do
13
+ batch_size.times.collect { |n| LogStash::Event.new({ "message" => "foobar #{n}" }) }
14
+ end
15
+
16
+ let(:number_of_crash) { Flores::Random.integer(1..10) }
17
+ let(:certificate) { Flores::PKI.generate }
18
+ let(:certificate_file_crt) { Stud::Temporary.pathname }
19
+ let(:certificate_file_key) { Stud::Temporary.pathname }
20
+ let(:port) { Flores::Random.integer(1024..65535) }
21
+ let(:host) { "127.0.0.1" }
22
+ let(:queue) { [] }
23
+
24
+ let(:client_options) {
25
+ {
26
+ "hosts" => [host],
27
+ "port" => port,
28
+ "ssl_certificate" => certificate_file_crt,
29
+ "flush_size" => batch_size
30
+ }
31
+ }
32
+ let(:output) { LogStash::Outputs::Lumberjack.new(client_options) }
33
+
34
+ context "when the server closes the connection" do
35
+ before do
36
+ File.open(certificate_file_crt, "a") { |f| f.write(certificate.first) }
37
+ File.open(certificate_file_key, "a") { |f| f.write(certificate.last) }
38
+
39
+ server = Lumberjack::Server.new(:port => port,
40
+ :address => host,
41
+ :ssl_certificate => certificate_file_crt,
42
+ :ssl_key => certificate_file_key)
43
+
44
+ crashed_count = 0
45
+ @server = Thread.new do
46
+ begin
47
+ server.run do |data|
48
+ if crashed_count < number_of_crash
49
+ crashed_count += 1
50
+ raise "crashed"
51
+ end
52
+
53
+ queue << data
54
+ end
55
+ rescue
56
+ end
57
+ end
58
+
59
+ output.register
60
+ end
61
+
62
+ after do
63
+ FileUtils.rm_rf(certificate_file_crt)
64
+ FileUtils.rm_rf(certificate_file_key)
65
+ end
66
+
67
+ it "reconnects and resend the payload" do
68
+ # We guarantee at least once,
69
+ # duplicates can happen in this scenario.
70
+ batch_payload.each { |event| output.receive(event) }
71
+
72
+ try(10) { expect(queue.size).to be >= batch_size }
73
+ expect(queue.map { |e| e["line"] }).to include(*batch_payload.map(&:to_s))
74
+ end
75
+ end
76
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-output-lumberjack
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
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-31 00:00:00.000000000 Z
11
+ date: 2015-08-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: logstash-core
@@ -36,12 +36,26 @@ dependencies:
36
36
  requirements:
37
37
  - - '>='
38
38
  - !ruby/object:Gem::Version
39
- version: 0.0.23
39
+ version: 0.0.24
40
40
  requirement: !ruby/object:Gem::Requirement
41
41
  requirements:
42
42
  - - '>='
43
43
  - !ruby/object:Gem::Version
44
- version: 0.0.23
44
+ version: 0.0.24
45
+ prerelease: false
46
+ type: :runtime
47
+ - !ruby/object:Gem::Dependency
48
+ name: stud
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ requirement: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - '>='
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
45
59
  prerelease: false
46
60
  type: :runtime
47
61
  - !ruby/object:Gem::Dependency
@@ -58,6 +72,48 @@ dependencies:
58
72
  version: '0'
59
73
  prerelease: false
60
74
  type: :development
75
+ - !ruby/object:Gem::Dependency
76
+ name: logstash-output-lumberjack
77
+ version_requirements: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - '>='
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ requirement: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - '>='
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ prerelease: false
88
+ type: :development
89
+ - !ruby/object:Gem::Dependency
90
+ name: logstash-codec-plain
91
+ version_requirements: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirement: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - '>='
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ prerelease: false
102
+ type: :development
103
+ - !ruby/object:Gem::Dependency
104
+ name: flores
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ requirement: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - '>='
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ prerelease: false
116
+ type: :development
61
117
  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
62
118
  email: info@elastic.co
63
119
  executables: []