logstash-input-zeromq 1.0.0 → 2.0.0

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: e99f5a681d8837c6a4a11d81daaf4767250b5b70
4
- data.tar.gz: 71826bec5786729dcec1c093b8576800bcbb0c4d
3
+ metadata.gz: eb5f758f8a4c7f6dcb7a17badb293e3d7ee27e16
4
+ data.tar.gz: 725744c65f7c409b55d69c494b5845fe38ee55b5
5
5
  SHA512:
6
- metadata.gz: af8694c4764f3e0d6cc76215601c9961bd48f9094d029de2849fcdbd953e7dd585a26a5665defffc6aa7484c35ebb3bc84b57acf462acda0dbe5f4625c7e82ac
7
- data.tar.gz: e5770e9729ec51ab0c392961a5a3d7b75e25588af3bf2b097ebf7c3653b67815a7efb44976a766cd4fa98f607eadf4a96ae0c6409e6a2e32bb66ac9a7bf70067
6
+ metadata.gz: a78835c6d0c46c02444b9fd84c1d88be967058369b50f20a7cddd1f4d5a09db06c13e3ea19d70fac9494ca8afadabb9e921325fbf03fa278e1b669f87ec66e85
7
+ data.tar.gz: c33dd827a9c5e2f7e33c64323454d0f39a294aeb4b2baf39f8a1c3e02ce021c6d6c91cf92634fc5554efe1cbe3692beb6d01a217813d3cbcc11e4ad7ea04d622
data/CHANGELOG.md CHANGED
@@ -0,0 +1,2 @@
1
+ # 1.1.0
2
+ - Add basic test to the project
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.
@@ -113,9 +113,10 @@ class LogStash::Inputs::ZeroMQ < LogStash::Inputs::Base
113
113
 
114
114
  end # def register
115
115
 
116
- def teardown
116
+ def close
117
117
  error_check(@zsocket.close, "while closing the zmq socket")
118
- end # def teardown
118
+ context.terminate
119
+ end # def close
119
120
 
120
121
  def server?
121
122
  @mode == "server"
@@ -124,12 +125,14 @@ class LogStash::Inputs::ZeroMQ < LogStash::Inputs::Base
124
125
  def run(output_queue)
125
126
  host = Socket.gethostname
126
127
  begin
127
- loop do
128
+ while !stop?
128
129
  # Here's the unified receiver
129
130
  # Get the first part as the msg
130
131
  m1 = ""
131
- rc = @zsocket.recv_string(m1)
132
+ rc = @zsocket.recv_string(m1, ZMQ::DONTWAIT)
133
+ next if rc == -1 && ZMQ::Util.errno == ZMQ::EAGAIN
132
134
  error_check(rc, "in recv_string")
135
+
133
136
  @logger.debug("ZMQ receiving", :event => m1)
134
137
  msg = m1
135
138
  # If we have more parts, we'll eat the first as the topic
@@ -142,16 +145,12 @@ class LogStash::Inputs::ZeroMQ < LogStash::Inputs::Base
142
145
  @logger.debug("ZMQ receiving", :event => m2)
143
146
  msg = m2
144
147
  end
145
-
146
148
  @codec.decode(msg) do |event|
147
149
  event["host"] ||= host
148
150
  decorate(event)
149
151
  output_queue << event
150
152
  end
151
153
  end
152
- rescue LogStash::ShutdownSignal
153
- # shutdown
154
- return
155
154
  rescue => e
156
155
  @logger.debug("ZMQ Error", :subscriber => @zsocket,
157
156
  :exception => e)
@@ -163,4 +162,5 @@ class LogStash::Inputs::ZeroMQ < LogStash::Inputs::Base
163
162
  def build_source_string
164
163
  id = @address.first.clone
165
164
  end
165
+
166
166
  end # class LogStash::Inputs::ZeroMQ
@@ -3,13 +3,12 @@ require 'ffi-rzmq'
3
3
  require "logstash/namespace"
4
4
 
5
5
  module LogStash::Util::ZeroMQ
6
- CONTEXT = ZMQ::Context.new
7
6
  # LOGSTASH-400
8
7
  # see https://github.com/chuckremes/ffi-rzmq/blob/master/lib/ffi-rzmq/socket.rb#L93-117
9
8
  STRING_OPTS = %w{IDENTITY SUBSCRIBE UNSUBSCRIBE}
10
9
 
11
10
  def context
12
- CONTEXT
11
+ @context ||= ZMQ::Context.new
13
12
  end
14
13
 
15
14
  def setup(socket, address)
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
 
3
3
  s.name = 'logstash-input-zeromq'
4
- s.version = '1.0.0'
4
+ s.version = '2.0.0'
5
5
  s.licenses = ['Apache License (2.0)']
6
6
  s.summary = "$summary"
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,7 +20,7 @@ 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"
24
24
 
25
25
  s.add_runtime_dependency 'logstash-codec-json'
26
26
  s.add_runtime_dependency 'ffi-rzmq', '~> 2.0.4'
@@ -1 +1,27 @@
1
- require "logstash/devutils/rspec/spec_helper"
1
+ # encoding: utf-8
2
+ require_relative "../spec_helper"
3
+ require "logstash/plugin"
4
+ require "logstash/event"
5
+
6
+ describe LogStash::Inputs::ZeroMQ, :zeromq => true do
7
+
8
+ context "when register and close" do
9
+
10
+ let(:plugin) { LogStash::Plugin.lookup("input", "zeromq").new({ "topology" => "pushpull" }) }
11
+
12
+ it "should register and close without errors" do
13
+ expect { plugin.register }.to_not raise_error
14
+ expect { plugin.close }.to_not raise_error
15
+ end
16
+
17
+ context "when interrupting the plugin" do
18
+ it_behaves_like "an interruptible input plugin" do
19
+ let(:config) { { "topology" => "pushpull" } }
20
+ after do
21
+ subject.close
22
+ end
23
+ end
24
+ end
25
+
26
+ end
27
+ end
@@ -0,0 +1,32 @@
1
+ # encoding: utf-8
2
+ require_relative "../spec_helper"
3
+ require "logstash/plugin"
4
+ require "logstash/event"
5
+
6
+ describe LogStash::Inputs::ZeroMQ, :integration => true do
7
+
8
+ describe "receive events" do
9
+
10
+ let(:nevents) { 10 }
11
+ let(:port) { rand(1000)+1025 }
12
+
13
+ let(:conf) do
14
+ { "address" => ["tcp://127.0.0.1:#{port}"],
15
+ "topology" => "pubsub" }
16
+ end
17
+
18
+ let(:events) do
19
+ input(conf, nevents) do
20
+ client = ZeroMQClient.new("127.0.0.1", port)
21
+ nevents.times do |value|
22
+ client.send("data #{value}")
23
+ end
24
+ client.close
25
+ end
26
+ end
27
+
28
+ it "should receive the events" do
29
+ expect(events.count).to be(nevents)
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,37 @@
1
+ # encoding: utf-8
2
+ require "logstash/devutils/rspec/spec_helper"
3
+ require "logstash/inputs/zeromq"
4
+ require_relative "support/client"
5
+
6
+ module ZeroMQHelpers
7
+
8
+ def setup_clients(number_of_clients, port)
9
+ number_of_clients.times.inject([]) do |clients|
10
+ clients << ZeroMQClient.new(localhost, port)
11
+ end
12
+ end
13
+
14
+ def input(config, size, &block)
15
+ plugin = LogStash::Plugin.lookup("input", "zeromq").new(config)
16
+ plugin.register
17
+ queue = Queue.new
18
+
19
+ pipeline_thread = Thread.new { plugin.run(queue) }
20
+ sleep 0.3
21
+ block.call
22
+ sleep 0.1 while queue.size != size
23
+ result = size.times.inject([]) do |acc|
24
+ acc << queue.pop
25
+ end
26
+ plugin.do_stop
27
+ pipeline_thread.join
28
+ result
29
+ end # def input
30
+
31
+ end
32
+
33
+ RSpec.configure do |config|
34
+ config.include ZeroMQHelpers
35
+ config.filter_run_excluding({ :zeromq => true, :integration => true })
36
+ config.order = :random
37
+ end
@@ -0,0 +1,24 @@
1
+ # encoding: utf-8
2
+ require 'ffi-rzmq'
3
+
4
+ class ZeroMQClient
5
+
6
+ attr_reader :addr, :port, :context, :requester
7
+
8
+ def initialize(addr, port)
9
+ @addr = addr
10
+ @port = port
11
+ @context = ZMQ::Context.new(1)
12
+ @requester = context.socket(ZMQ::PUB)
13
+ @requester.connect("tcp://#{addr}:#{port}")
14
+ end
15
+
16
+ def send(data)
17
+ @requester.send_string(data)
18
+ end
19
+
20
+ def close
21
+ @requester.close
22
+ @context.terminate
23
+ end
24
+ end
metadata CHANGED
@@ -1,95 +1,90 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-input-zeromq
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 2.0.0
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-09-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: logstash-core
15
- version_requirements: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - '>='
18
- - !ruby/object:Gem::Version
19
- version: 1.4.0
20
- - - <
21
- - !ruby/object:Gem::Version
22
- version: 2.0.0
23
14
  requirement: !ruby/object:Gem::Requirement
24
15
  requirements:
25
- - - '>='
26
- - !ruby/object:Gem::Version
27
- version: 1.4.0
28
- - - <
16
+ - - ~>
29
17
  - !ruby/object:Gem::Version
30
- version: 2.0.0
18
+ version: 2.0.0.snapshot
19
+ name: logstash-core
31
20
  prerelease: false
32
21
  type: :runtime
33
- - !ruby/object:Gem::Dependency
34
- name: logstash-codec-json
35
22
  version_requirements: !ruby/object:Gem::Requirement
36
23
  requirements:
37
- - - '>='
24
+ - - ~>
38
25
  - !ruby/object:Gem::Version
39
- version: '0'
26
+ version: 2.0.0.snapshot
27
+ - !ruby/object:Gem::Dependency
40
28
  requirement: !ruby/object:Gem::Requirement
41
29
  requirements:
42
30
  - - '>='
43
31
  - !ruby/object:Gem::Version
44
32
  version: '0'
33
+ name: logstash-codec-json
45
34
  prerelease: false
46
35
  type: :runtime
47
- - !ruby/object:Gem::Dependency
48
- name: ffi-rzmq
49
36
  version_requirements: !ruby/object:Gem::Requirement
50
37
  requirements:
51
- - - ~>
38
+ - - '>='
52
39
  - !ruby/object:Gem::Version
53
- version: 2.0.4
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
54
42
  requirement: !ruby/object:Gem::Requirement
55
43
  requirements:
56
44
  - - ~>
57
45
  - !ruby/object:Gem::Version
58
46
  version: 2.0.4
47
+ name: ffi-rzmq
59
48
  prerelease: false
60
49
  type: :runtime
61
- - !ruby/object:Gem::Dependency
62
- name: logstash-devutils
63
50
  version_requirements: !ruby/object:Gem::Requirement
64
51
  requirements:
65
- - - '>='
52
+ - - ~>
66
53
  - !ruby/object:Gem::Version
67
- version: '0'
54
+ version: 2.0.4
55
+ - !ruby/object:Gem::Dependency
68
56
  requirement: !ruby/object:Gem::Requirement
69
57
  requirements:
70
58
  - - '>='
71
59
  - !ruby/object:Gem::Version
72
60
  version: '0'
61
+ name: logstash-devutils
73
62
  prerelease: false
74
63
  type: :development
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
75
69
  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
76
70
  email: info@elastic.co
77
71
  executables: []
78
72
  extensions: []
79
73
  extra_rdoc_files: []
80
74
  files:
81
- - .gitignore
82
75
  - CHANGELOG.md
83
76
  - CONTRIBUTORS
84
77
  - Gemfile
85
78
  - LICENSE
86
79
  - NOTICE.TXT
87
80
  - README.md
88
- - Rakefile
89
81
  - lib/logstash/inputs/zeromq.rb
90
82
  - lib/logstash/util/zeromq.rb
91
83
  - logstash-input-zeromq.gemspec
92
84
  - spec/inputs/zeromq_spec.rb
85
+ - spec/integration/zeromq_spec.rb
86
+ - spec/spec_helper.rb
87
+ - spec/support/client.rb
93
88
  homepage: http://www.elastic.co/guide/en/logstash/current/index.html
94
89
  licenses:
95
90
  - Apache License (2.0)
@@ -112,9 +107,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
112
107
  version: '0'
113
108
  requirements: []
114
109
  rubyforge_project:
115
- rubygems_version: 2.2.2
110
+ rubygems_version: 2.4.8
116
111
  signing_key:
117
112
  specification_version: 4
118
113
  summary: $summary
119
114
  test_files:
120
115
  - spec/inputs/zeromq_spec.rb
116
+ - spec/integration/zeromq_spec.rb
117
+ - spec/spec_helper.rb
118
+ - 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"