logstash-input-heartbeat 0.1.2 → 0.1.4

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: b757212fd17757e1b91e19640b8ffedf91c940c0
4
- data.tar.gz: 0ea012c766294d3741038d3512f5dce730c147fb
3
+ metadata.gz: 0453e13da1d157935c3e73ccf420f85198069d66
4
+ data.tar.gz: ec269a6b10f45da44a83f282d1f7c65dee35c339
5
5
  SHA512:
6
- metadata.gz: bfb320af864cb2d7ad9e70c4fa77fe279d241e6adc868c9e2f1fc070bfd52fc346679dedde98eb8751f5e912cdd4951c88683c908b1a113794eceab86006150a
7
- data.tar.gz: 1d853db489a5b9b98ac06327be2e3e4c13a9a4588b0f922db400225615d5055abc0f935853d0281dd6f449b36cf6f1a736e00d1afcf5a828c38a3a531f6beb7d
6
+ metadata.gz: 467e575a02b9eb6711ed79a233acc6dc4a39f5bf416dd4602488aad96de581bea7dba44d5d34351bf2e4b211928b794ee15cfe492857f2478264c69369638b1d
7
+ data.tar.gz: cb6274d921ca873117b1dc41314425f9513e6f2e5eda041676036af8b33b4517af3c5a5aff6887a52e5b8a14327bd2888c3f5f2bc1fa2e05dbfa1773c15c6f2c
data/Gemfile CHANGED
@@ -1,4 +1,2 @@
1
1
  source 'https://rubygems.org'
2
- gemspec
3
- gem "logstash", :github => "elasticsearch/logstash", :branch => "1.5"
4
-
2
+ gemspec
data/README.md CHANGED
@@ -22,7 +22,7 @@ Need help? Try #logstash on freenode IRC or the logstash-users@googlegroups.com
22
22
  #### Code
23
23
  - To get started, you'll need JRuby with the Bundler gem installed.
24
24
 
25
- - Create a new plugin or clone and existing from the GitHub [logstash-plugins](https://github.com/logstash-plugins) organization.
25
+ - Create a new plugin or clone and existing from the GitHub [logstash-plugins](https://github.com/logstash-plugins) organization. We also provide [example plugins](https://github.com/logstash-plugins?query=example).
26
26
 
27
27
  - Install dependencies
28
28
  ```sh
@@ -31,26 +31,15 @@ bundle install
31
31
 
32
32
  #### Test
33
33
 
34
- ```sh
35
- bundle exec rspec
36
- ```
34
+ - Update your dependencies
37
35
 
38
- The Logstash code required to run the tests/specs is specified in the `Gemfile` by the line similar to:
39
- ```ruby
40
- gem "logstash", :github => "elasticsearch/logstash", :branch => "1.5"
41
- ```
42
- To test against another version or a local Logstash, edit the `Gemfile` to specify an alternative location, for example:
43
- ```ruby
44
- gem "logstash", :github => "elasticsearch/logstash", :ref => "master"
45
- ```
46
- ```ruby
47
- gem "logstash", :path => "/your/local/logstash"
36
+ ```sh
37
+ bundle install
48
38
  ```
49
39
 
50
- Then update your dependencies and run your tests:
40
+ - Run tests
51
41
 
52
42
  ```sh
53
- bundle install
54
43
  bundle exec rspec
55
44
  ```
56
45
 
@@ -58,13 +47,13 @@ bundle exec rspec
58
47
 
59
48
  #### 2.1 Run in a local Logstash clone
60
49
 
61
- - Edit Logstash `tools/Gemfile` and add the local plugin path, for example:
50
+ - Edit Logstash `Gemfile` and add the local plugin path, for example:
62
51
  ```ruby
63
52
  gem "logstash-filter-awesome", :path => "/your/local/logstash-filter-awesome"
64
53
  ```
65
- - Update Logstash dependencies
54
+ - Install plugin
66
55
  ```sh
67
- rake vendor:gems
56
+ bin/plugin install --no-verify
68
57
  ```
69
58
  - Run Logstash with your plugin
70
59
  ```sh
@@ -74,6 +63,8 @@ At this point any modifications to the plugin code will be applied to this local
74
63
 
75
64
  #### 2.2 Run in an installed Logstash
76
65
 
66
+ You can use the same **2.1** method to run your plugin in an installed Logstash by editing its `Gemfile` and pointing the `:path` to your local plugin development directory or you can build the gem and install it using:
67
+
77
68
  - Build your plugin gem
78
69
  ```sh
79
70
  gem build logstash-filter-awesome.gemspec
@@ -90,6 +81,6 @@ All contributions are welcome: ideas, patches, documentation, bug reports, compl
90
81
 
91
82
  Programming is not a required skill. Whatever you've seen about open source and maintainers or community members saying "send patches or die" - you will not see that here.
92
83
 
93
- It is more important to me that you are able to contribute.
84
+ It is more important to the community that you are able to contribute.
94
85
 
95
- 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/elasticsearch/logstash/blob/master/CONTRIBUTING.md) file.
@@ -6,7 +6,7 @@ require "socket" # for Socket.gethostname
6
6
 
7
7
  # Generate heartbeat messages.
8
8
  #
9
- # The general intention of this is to test the performance and
9
+ # The general intention of this is to test the performance and
10
10
  # availability of Logstash.
11
11
  #
12
12
 
@@ -20,8 +20,8 @@ class LogStash::Inputs::Heartbeat < LogStash::Inputs::Threadable
20
20
  # If you set this to `epoch` then this plugin will use the current
21
21
  # timestamp in unix timestamp (which is by definition, UTC). It will
22
22
  # output this value into a field called `clock`
23
- #
24
- # If you set this to `sequence` then this plugin will send a sequence of
23
+ #
24
+ # If you set this to `sequence` then this plugin will send a sequence of
25
25
  # numbers beginning at 0 and incrementing each interval. It will
26
26
  # output this value into a field called `clock`
27
27
  #
@@ -34,6 +34,10 @@ class LogStash::Inputs::Heartbeat < LogStash::Inputs::Threadable
34
34
  # The default, `60`, means send a message every 60 seconds.
35
35
  config :interval, :validate => :number, :default => 60
36
36
 
37
+ # How many times to iterate.
38
+ # This is typically used only for testing purposes.
39
+ config :count, :validate => :number, :default => -1
40
+
37
41
  public
38
42
  def register
39
43
  @host = Socket.gethostname
@@ -43,23 +47,24 @@ class LogStash::Inputs::Heartbeat < LogStash::Inputs::Threadable
43
47
  sequence = 0
44
48
 
45
49
  Stud.interval(@interval) do
46
- if @message == "epoch"
47
- event = LogStash::Event.new("clock" => Time.now.to_i, "host" => @host)
48
- elsif @message == "sequence"
49
- event = LogStash::Event.new("clock" => sequence, "host" => @host)
50
- sequence += 1
51
- else
52
- event = LogStash::Event.new("message" => @message, "host" => @host)
53
- end
54
-
50
+ sequence += 1
51
+ event = generate_message(sequence)
55
52
  decorate(event)
56
53
  queue << event
57
-
54
+ break if sequence == @count
58
55
  end # loop
59
56
 
60
57
  end # def run
61
58
 
62
59
  public
63
- def teardown
64
- end # def teardown
60
+ def generate_message(sequence)
61
+ if @message == "epoch"
62
+ LogStash::Event.new("clock" => Time.now.to_i, "host" => @host)
63
+ elsif @message == "sequence"
64
+ LogStash::Event.new("clock" => sequence, "host" => @host)
65
+ else
66
+ LogStash::Event.new("message" => @message, "host" => @host)
67
+ end
68
+ end
69
+
65
70
  end # class LogStash::Inputs::Heartbeat
@@ -1,10 +1,10 @@
1
1
  Gem::Specification.new do |s|
2
2
 
3
3
  s.name = 'logstash-input-heartbeat'
4
- s.version = '0.1.2'
4
+ s.version = '0.1.4'
5
5
  s.licenses = ['Apache License (2.0)']
6
6
  s.summary = "This input generates a heartbeat pattern to aid in monitoring Logstash performance & availability"
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"
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"
8
8
  s.authors = ["Elasticsearch"]
9
9
  s.email = 'info@elasticsearch.com'
10
10
  s.homepage = "http://www.elasticsearch.org/guide/en/logstash/current/index.html"
@@ -20,11 +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', '>= 1.4.0', '< 2.0.0'
23
+ s.add_runtime_dependency "logstash-core", '>= 1.4.0', '< 2.0.0'
24
24
  s.add_runtime_dependency 'logstash-codec-plain'
25
25
  s.add_runtime_dependency 'stud'
26
26
 
27
27
  s.add_development_dependency 'logstash-devutils'
28
28
 
29
29
  end
30
-
@@ -1 +1,71 @@
1
1
  require "logstash/devutils/rspec/spec_helper"
2
+ require "logstash/inputs/heartbeat"
3
+
4
+ def fetch_event(config, number)
5
+ pipeline = LogStash::Pipeline.new(config)
6
+ queue = Queue.new
7
+ pipeline.instance_eval do
8
+ @output_func = lambda { |event| queue << event }
9
+ end
10
+ pipeline_thread = Thread.new { pipeline.run }
11
+ counter = 0
12
+ begin
13
+ event = queue.pop
14
+ pipeline_thread.join
15
+ counter += 1
16
+ end until counter == number
17
+ return event
18
+ end
19
+
20
+ describe LogStash::Inputs::Heartbeat do
21
+ sequence = 1
22
+ context "Default message test" do
23
+ subject { LogStash::Inputs::Heartbeat.new({}) }
24
+
25
+ it "should generate an 'ok' message" do
26
+ expect(subject.generate_message(sequence)['message']).to eq('ok')
27
+ end # it "should generate an 'ok' message"
28
+ end # context "Default message test"
29
+
30
+ context "Simple message test" do
31
+ subject { LogStash::Inputs::Heartbeat.new({"message" => "my_message"}) }
32
+
33
+ it "should generate a message containing 'my_message'" do
34
+ expect(subject.generate_message(sequence)['message']).to eq('my_message')
35
+ end # it "should generate a message containing 'my_message'"
36
+ end # context "Simple message test" do
37
+
38
+ context "Sequence test" do
39
+ subject { LogStash::Inputs::Heartbeat.new({"message" => "sequence"}) }
40
+
41
+ it "should return an event with the appropriate sequence value" do
42
+ expect(subject.generate_message(sequence)['clock']).to eq(sequence)
43
+ end # it "should return an event with the appropriate sequence value"
44
+ end # context "Sequence test"
45
+
46
+ context "Epoch test" do
47
+ subject { LogStash::Inputs::Heartbeat.new({"message" => "epoch"}) }
48
+
49
+ it "should return an event with the current time (as epoch)" do
50
+ now = Time.now.to_i
51
+ # Give it a second, just in case
52
+ expect(subject.generate_message(sequence)['clock'] - now).to be < 2
53
+ end # it "should return an event with the current time (as epoch)"
54
+ end # context "Epoch test"
55
+
56
+ it "should generate a fixed number of events then stop" do
57
+ count = 4
58
+ config = <<-CONFIG
59
+ input {
60
+ heartbeat {
61
+ interval => 1
62
+ message => "sequence"
63
+ count => #{count}
64
+ }
65
+ }
66
+ CONFIG
67
+
68
+ event = fetch_event(config, count)
69
+ expect(event['clock']).to eq(count)
70
+ end
71
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-input-heartbeat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elasticsearch
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-27 00:00:00.000000000 Z
11
+ date: 2015-02-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -19,7 +19,7 @@ dependencies:
19
19
  - - <
20
20
  - !ruby/object:Gem::Version
21
21
  version: 2.0.0
22
- name: logstash
22
+ name: logstash-core
23
23
  prerelease: false
24
24
  type: :runtime
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -110,7 +110,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
110
110
  version: '0'
111
111
  requirements: []
112
112
  rubyforge_project:
113
- rubygems_version: 2.1.9
113
+ rubygems_version: 2.4.5
114
114
  signing_key:
115
115
  specification_version: 4
116
116
  summary: This input generates a heartbeat pattern to aid in monitoring Logstash performance & availability