logstash-input-udp 1.0.0 → 2.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: b0019df7ba57bb256f1575bc24e8165993afd26d
4
- data.tar.gz: 9423e0737d5072150a205c1ea864ff9702eb4912
3
+ metadata.gz: ffc5e1f54afba7b7af046de112d9cdd081b2d8c8
4
+ data.tar.gz: 839bf1df40502b1f3fd88c0fef67834556a0bf55
5
5
  SHA512:
6
- metadata.gz: 07626f7e822fd5ced68c7f822cb7096671daceda2c7ad5b474f608b57a9a20a917f76e8755775c2c608a0135a4c2684b515c2a1a7eec22db76533aab54d1adb6
7
- data.tar.gz: fc10ab5d8258f0248b8a9463cd5a8f5102e2b26e53aa9b8cfdee4058314c4a2001dd96913f336ed690ffa9a545dfa9054ad2fe855395a5ab433f4bcc892f4e3b
6
+ metadata.gz: fd988a87f3edd6c2fa305ee67f56acbfc70557e52fb25a725ccdac09a1c5895da2ec5083d6f0bdf6dcb695fc7065bcff3ce268beaf85e4c562ab24d7b3736823
7
+ data.tar.gz: 02afb631b7faea97d073f5a023557ec4e321d5269a6afcc1a1f56dc039229aee86b0304710420086586e0ee1d5c2e27080462675fdaf3078377f1a1495afafd4
data/CHANGELOG.md CHANGED
@@ -0,0 +1,5 @@
1
+ ## 2.0.0
2
+ - Plugins were updated to follow the new shutdown semantic, this mainly allows Logstash to instruct input plugins to terminate gracefully,
3
+ instead of using Thread.raise on the plugins' threads. Ref: https://github.com/elastic/logstash/pull/3895
4
+ - Dependency on logstash-core update to 2.0
5
+
data/README.md CHANGED
@@ -1,15 +1,15 @@
1
1
  # Logstash 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
 
@@ -83,4 +83,4 @@ Programming is not a required skill. Whatever you've seen about open source and
83
83
 
84
84
  It is more important to the community that you are able to contribute.
85
85
 
86
- For more information about contributing, see the [CONTRIBUTING](https://github.com/elasticsearch/logstash/blob/master/CONTRIBUTING.md) file.
86
+ For more information about contributing, see the [CONTRIBUTING](https://github.com/elastic/logstash/blob/master/CONTRIBUTING.md) file.
@@ -3,6 +3,7 @@ require "date"
3
3
  require "logstash/inputs/base"
4
4
  require "logstash/namespace"
5
5
  require "socket"
6
+ require "stud/interval"
6
7
 
7
8
  # Read messages as events over the network via udp. The only required
8
9
  # configuration item is `port`, which specifies the udp port logstash
@@ -47,12 +48,10 @@ class LogStash::Inputs::Udp < LogStash::Inputs::Base
47
48
  begin
48
49
  # udp server
49
50
  udp_listener(output_queue)
50
- rescue LogStash::ShutdownSignal
51
- # do nothing, shutdown was requested.
52
51
  rescue => e
53
52
  @logger.warn("UDP listener died", :exception => e, :backtrace => e.backtrace)
54
- sleep(5)
55
- retry
53
+ Stud.stoppable_sleep(5) { stop? }
54
+ retry unless stop?
56
55
  end # begin
57
56
  end # def run
58
57
 
@@ -74,9 +73,11 @@ class LogStash::Inputs::Udp < LogStash::Inputs::Base
74
73
  Thread.new { inputworker(i) }
75
74
  end
76
75
 
77
- while true
76
+ while !stop?
77
+ next if IO.select([@udp], [], [], 0.5).nil?
78
78
  #collect datagram message and add to queue
79
- payload, client = @udp.recvfrom(@buffer_size)
79
+ payload, client = @udp.recvfrom_nonblock(@buffer_size)
80
+ next if payload.empty?
80
81
  @input_to_worker.push([payload, client])
81
82
  end
82
83
  ensure
@@ -104,8 +105,13 @@ class LogStash::Inputs::Udp < LogStash::Inputs::Base
104
105
  end # def inputworker
105
106
 
106
107
  public
107
- def teardown
108
- @udp.close if @udp && !@udp.closed?
108
+ def close
109
+ @udp.close rescue nil
110
+ end
111
+
112
+ public
113
+ def stop
114
+ @udp.close rescue nil
109
115
  end
110
116
 
111
117
  end # class LogStash::Inputs::Udp
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
 
3
3
  s.name = 'logstash-input-udp'
4
- s.version = '1.0.0'
4
+ s.version = '2.0.1'
5
5
  s.licenses = ['Apache License (2.0)']
6
6
  s.summary = "Read messages as events over the network via udp."
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"
@@ -11,7 +11,7 @@ Gem::Specification.new do |s|
11
11
  s.require_paths = ["lib"]
12
12
 
13
13
  # Files
14
- s.files = `git ls-files`.split($\)+::Dir.glob('vendor/*')
14
+ s.files = Dir['lib/**/*','spec/**/*','vendor/**/*','*.gemspec','*.md','CONTRIBUTORS','Gemfile','LICENSE','NOTICE.TXT']
15
15
 
16
16
  # Tests
17
17
  s.test_files = s.files.grep(%r{^(test|spec|features)/})
@@ -20,9 +20,10 @@ Gem::Specification.new do |s|
20
20
  s.metadata = { "logstash_plugin" => "true", "logstash_group" => "input" }
21
21
 
22
22
  # Gem dependencies
23
- s.add_runtime_dependency "logstash-core", '>= 1.4.0', '< 2.0.0'
23
+ s.add_runtime_dependency "logstash-core", ">= 2.0.0.snapshot", "< 3.0.0"
24
24
 
25
25
  s.add_runtime_dependency 'logstash-codec-plain'
26
+ s.add_runtime_dependency 'stud', '~> 0.0.22'
26
27
  s.add_development_dependency 'logstash-devutils'
27
28
  end
28
29
 
@@ -1,6 +1,54 @@
1
1
  # encoding: utf-8
2
- require "logstash/devutils/rspec/spec_helper"
3
- require 'logstash/inputs/udp'
2
+ require_relative "../spec_helper"
3
+ require_relative "../support/client"
4
4
 
5
5
  describe LogStash::Inputs::Udp do
6
+
7
+ before do
8
+ srand(RSpec.configuration.seed)
9
+ end
10
+
11
+ let(:port) { rand(1024..65535) }
12
+ subject { LogStash::Plugin.lookup("input", "udp").new({ "port" => port }) }
13
+
14
+ after :each do
15
+ subject.close rescue nil
16
+ end
17
+
18
+ describe "register" do
19
+ it "should register without errors" do
20
+ expect { subject.register }.to_not raise_error
21
+ end
22
+ end
23
+
24
+ describe "receive" do
25
+
26
+ let(:client) { LogStash::Inputs::Test::UDPClient.new(port) }
27
+ let(:nevents) { 10 }
28
+
29
+ let(:events) do
30
+ input(subject, nevents) do
31
+ nevents.times do |i|
32
+ client.send("msg #{i}")
33
+ end
34
+ end
35
+ end
36
+
37
+ before(:each) do
38
+ subject.register
39
+ end
40
+
41
+ it "should receive events been generated" do
42
+ expect(events.size).to be(nevents)
43
+ messages = events.map { |event| event["message"]}
44
+ messages.each do |message|
45
+ expect(message).to match(/msg \d+/)
46
+ end
47
+ end
48
+
49
+ end
50
+
51
+ it_behaves_like "an interruptible input plugin" do
52
+ let(:config) { { "port" => port } }
53
+ end
6
54
  end
@@ -0,0 +1,34 @@
1
+ # encoding: utf-8
2
+ require "logstash/devutils/rspec/spec_helper"
3
+ require 'logstash/inputs/udp'
4
+
5
+ # expose the udp socket so that we can assert, during
6
+ # a spec, that it is open and we can start sending data
7
+ class LogStash::Inputs::Udp
8
+ attr_reader :udp
9
+ end
10
+
11
+ module UdpHelpers
12
+
13
+ def input(plugin, size, &block)
14
+ queue = Queue.new
15
+ input_thread = Thread.new do
16
+ plugin.run(queue)
17
+ end
18
+ # because the udp socket is created and bound during #run
19
+ # we must ensure that it is open before sending data
20
+ sleep 0.1 until (plugin.udp && !plugin.udp.closed?)
21
+ block.call
22
+ sleep 0.1 while queue.size != size
23
+ result = nevents.times.inject([]) do |acc|
24
+ acc << queue.pop
25
+ end
26
+ plugin.do_stop
27
+ result
28
+ end
29
+
30
+ end
31
+
32
+ RSpec.configure do |c|
33
+ c.include UdpHelpers
34
+ end
@@ -0,0 +1,37 @@
1
+ # encoding: utf-8
2
+ require "socket"
3
+
4
+ module LogStash::Inputs::Test
5
+
6
+ class UDPClient
7
+
8
+ attr_reader :host, :port, :socket
9
+
10
+ def initialize(port)
11
+ @port = port
12
+ @host = "0.0.0.0"
13
+ @socket = UDPSocket.new
14
+ socket.connect(host, port)
15
+ end
16
+
17
+ def send(msg="")
18
+ begin
19
+ send(msg)
20
+ rescue Exception => e
21
+ puts "send.exception", e
22
+ retry
23
+ end
24
+ end
25
+
26
+ def send(msg)
27
+ socket.connect(host, port) if socket.closed?
28
+ socket.send(msg, 0)
29
+ end
30
+
31
+ def close
32
+ socket.close
33
+ end
34
+
35
+ end
36
+
37
+ end
metadata CHANGED
@@ -1,80 +1,94 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-input-udp
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 2.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-06-24 00:00:00.000000000 Z
11
+ date: 2015-10-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - '>='
17
+ - !ruby/object:Gem::Version
18
+ version: 2.0.0.snapshot
19
+ - - <
20
+ - !ruby/object:Gem::Version
21
+ version: 3.0.0
14
22
  name: logstash-core
23
+ prerelease: false
24
+ type: :runtime
15
25
  version_requirements: !ruby/object:Gem::Requirement
16
26
  requirements:
17
27
  - - '>='
18
28
  - !ruby/object:Gem::Version
19
- version: 1.4.0
29
+ version: 2.0.0.snapshot
20
30
  - - <
21
31
  - !ruby/object:Gem::Version
22
- version: 2.0.0
32
+ version: 3.0.0
33
+ - !ruby/object:Gem::Dependency
23
34
  requirement: !ruby/object:Gem::Requirement
24
35
  requirements:
25
36
  - - '>='
26
37
  - !ruby/object:Gem::Version
27
- version: 1.4.0
28
- - - <
29
- - !ruby/object:Gem::Version
30
- version: 2.0.0
38
+ version: '0'
39
+ name: logstash-codec-plain
31
40
  prerelease: false
32
41
  type: :runtime
33
- - !ruby/object:Gem::Dependency
34
- name: logstash-codec-plain
35
42
  version_requirements: !ruby/object:Gem::Requirement
36
43
  requirements:
37
44
  - - '>='
38
45
  - !ruby/object:Gem::Version
39
46
  version: '0'
47
+ - !ruby/object:Gem::Dependency
40
48
  requirement: !ruby/object:Gem::Requirement
41
49
  requirements:
42
- - - '>='
50
+ - - ~>
43
51
  - !ruby/object:Gem::Version
44
- version: '0'
52
+ version: 0.0.22
53
+ name: stud
45
54
  prerelease: false
46
55
  type: :runtime
47
- - !ruby/object:Gem::Dependency
48
- name: logstash-devutils
49
56
  version_requirements: !ruby/object:Gem::Requirement
50
57
  requirements:
51
- - - '>='
58
+ - - ~>
52
59
  - !ruby/object:Gem::Version
53
- version: '0'
60
+ version: 0.0.22
61
+ - !ruby/object:Gem::Dependency
54
62
  requirement: !ruby/object:Gem::Requirement
55
63
  requirements:
56
64
  - - '>='
57
65
  - !ruby/object:Gem::Version
58
66
  version: '0'
67
+ name: logstash-devutils
59
68
  prerelease: false
60
69
  type: :development
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
61
75
  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
76
  email: info@elastic.co
63
77
  executables: []
64
78
  extensions: []
65
79
  extra_rdoc_files: []
66
80
  files:
67
- - .gitignore
68
81
  - CHANGELOG.md
69
82
  - CONTRIBUTORS
70
83
  - Gemfile
71
84
  - LICENSE
72
85
  - NOTICE.TXT
73
86
  - README.md
74
- - Rakefile
75
87
  - lib/logstash/inputs/udp.rb
76
88
  - logstash-input-udp.gemspec
77
89
  - spec/inputs/udp_spec.rb
90
+ - spec/spec_helper.rb
91
+ - spec/support/client.rb
78
92
  homepage: http://www.elastic.co/guide/en/logstash/current/index.html
79
93
  licenses:
80
94
  - Apache License (2.0)
@@ -97,9 +111,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
97
111
  version: '0'
98
112
  requirements: []
99
113
  rubyforge_project:
100
- rubygems_version: 2.2.2
114
+ rubygems_version: 2.4.8
101
115
  signing_key:
102
116
  specification_version: 4
103
117
  summary: Read messages as events over the network via udp.
104
118
  test_files:
105
119
  - spec/inputs/udp_spec.rb
120
+ - spec/spec_helper.rb
121
+ - spec/support/client.rb
data/.gitignore DELETED
@@ -1,4 +0,0 @@
1
- *.gem
2
- Gemfile.lock
3
- .bundle
4
- vendor
data/Rakefile DELETED
@@ -1,7 +0,0 @@
1
- @files=[]
2
-
3
- task :default do
4
- system("rake -T")
5
- end
6
-
7
- require "logstash/devutils/rake"