logstash-output-statsd 1.0.0 → 1.1.0

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: 322eaa3dc699b21da712d6f8e87a29478c12e54f
4
- data.tar.gz: 2caa3d76629ff0105b5784b42ccdd42af7d4578a
3
+ metadata.gz: 5ee8b283b94fd2486d21062eae81d0150b361c94
4
+ data.tar.gz: 775d8a1f5883e3699f4ff1f37bd403c5b13f7ae9
5
5
  SHA512:
6
- metadata.gz: 74d8991d2d49605ffb63e31fc79baea8bed725c86697b29c7c1817d429e84d68e8312a1f4a63146b07527e29f68d9bcfdd829ca757ce60796c07c1c40d6cfc74
7
- data.tar.gz: d297957aa5fceab2b7b7b94bddc5048ce96863b2629cd072b1c50a80f61d1c3a3b0ac8635b5b8601295298a9b1b19be945bce01d21b3fbfb126e99ef025a8de9
6
+ metadata.gz: a6a2b13c8b360b1e486f0e25c7471e31b0a8924c2c952f6dd92943189150307842830cddc324272b40ceb93dfd73310186b38fdc714b4bb834d2ed5996006d78
7
+ data.tar.gz: cf1f332c840b40b1b0cff4a221a64ea5c8fde7e78006563648c4c138404d784550d0b3ce1c3c2f274c1869e74699964c39fb3bedb3342f3ba42b499d9abf43ca
data/CHANGELOG.md CHANGED
@@ -0,0 +1,3 @@
1
+ # 1.1.0
2
+ - improved test design to be more rspec3 friendly, including the usage
3
+ of random ports to avoid colisions in integration test.
@@ -90,7 +90,6 @@ class LogStash::Outputs::Statsd < LogStash::Outputs::Base
90
90
  public
91
91
  def receive(event)
92
92
  return unless output?(event)
93
-
94
93
  @client.namespace = event.sprintf(@namespace) if not @namespace.empty?
95
94
  @logger.debug? and @logger.debug("Original sender: #{@sender}")
96
95
  sender = event.sprintf(@sender)
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
 
3
3
  s.name = 'logstash-output-statsd'
4
- s.version = '1.0.0'
4
+ s.version = '1.1.0'
5
5
  s.licenses = ['Apache License (2.0)']
6
6
  s.summary = "Send metrics to StatsD"
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"
@@ -1,91 +1,47 @@
1
1
  # encoding: utf-8
2
- require "logstash/devutils/rspec/spec_helper"
3
2
  require "logstash/outputs/statsd"
4
- require "socket"
3
+ require_relative "../spec_helper"
5
4
 
6
5
  describe LogStash::Outputs::Statsd do
7
- port = 4399
8
6
 
9
- udp_server = UDPSocket.new
10
- udp_server.bind("127.0.0.1", port)
11
- udp_server
7
+ let(:host) { "localhost" }
8
+ let(:port) { @server.port }
9
+
10
+ describe "registration and teardown" do
11
+
12
+ it "should register without errors" do
13
+ output = LogStash::Plugin.lookup("output", "statsd").new
14
+ expect {output.register}.to_not raise_error
15
+ end
12
16
 
13
- after(:all) do
14
- udp_server.close
15
17
  end
16
18
 
17
- describe "send metric to statsd" do
18
- config <<-CONFIG
19
- input {
20
- generator {
21
- message => "valid"
22
- count => 1
23
- }
24
- }
19
+ describe "#send" do
25
20
 
26
- output {
27
- statsd {
28
- host => "localhost"
29
- sender => "spec"
30
- port => #{port}
31
- count => [ "test.valid", "0.1" ]
32
- }
33
- }
34
- CONFIG
21
+ context "count metrics" do
35
22
 
36
- agent do
37
- metric, *data = udp_server.recvfrom(100)
38
- insist { metric } == "logstash.spec.test.valid:0.1|c"
39
- end
40
- end
23
+ let(:config) do
24
+ { "host" => host, "sender" => "spec", "port" => port, "count" => [ "foo.bar", "0.1" ] }
25
+ end
41
26
 
42
- describe "output a very small float" do
43
- config <<-CONFIG
44
- input {
45
- generator {
46
- message => "valid"
47
- count => 1
48
- }
49
- }
27
+ let(:properties) do
28
+ { "metric" => "foo.bar", "count" => 10 }
29
+ end
50
30
 
51
- output {
52
- statsd {
53
- host => "localhost"
54
- sender => "spec"
55
- port => #{port}
56
- count => [ "test.valid", 0.000001 ]
57
- }
58
- }
59
- CONFIG
31
+ let(:event) { LogStash::Event.new(properties) }
60
32
 
61
- agent do
62
- metric, *data = udp_server.recvfrom(100)
63
- insist { metric } == "logstash.spec.test.valid:0.000001|c"
64
- end
65
- end
33
+ subject { LogStash::Outputs::Statsd.new(config) }
66
34
 
67
- describe "output a very big float" do
68
- config <<-CONFIG
69
- input {
70
- generator {
71
- message => "valid"
72
- count => 1
73
- }
74
- }
35
+ before(:each) do
36
+ subject.register
37
+ end
75
38
 
76
- output {
77
- statsd {
78
- host => "localhost"
79
- sender => "spec"
80
- port => #{port}
81
- count => [ "test.valid", 9999999999999.01 ]
82
- }
83
- }
84
- CONFIG
39
+ it "should receive data send to the server" do
40
+ subject.receive(event)
41
+ expect(@server.received).to include("logstash.spec.foo.bar:0.1|c")
42
+ end
85
43
 
86
- agent do
87
- metric, *data = udp_server.recvfrom(100)
88
- insist { metric } == "logstash.spec.test.valid:9999999999999.01|c"
89
44
  end
90
45
  end
46
+
91
47
  end
@@ -0,0 +1,69 @@
1
+ require "logstash/devutils/rspec/spec_helper"
2
+ require "socket"
3
+
4
+ class StatsdServer
5
+
6
+ attr_reader :received, :port
7
+
8
+ def initialize
9
+ @sync_lock = Mutex.new
10
+ @terminated = false
11
+ @received = []
12
+ end
13
+
14
+ def register(port)
15
+ @port = port
16
+ @socket = UDPSocket.new
17
+ @socket.bind("127.0.0.1", port)
18
+ end
19
+
20
+ def run(port)
21
+ register(port)
22
+ Thread.new do
23
+ while(!closed?)
24
+ metric, _ = @socket.recvfrom(100)
25
+ append(metric)
26
+ end
27
+ end
28
+ self
29
+ end
30
+
31
+ def append(metric)
32
+ @sync_lock.synchronize do
33
+ @received << metric
34
+ end
35
+ end
36
+
37
+ def close
38
+ @sync_lock.synchronize do
39
+ @terminated = true
40
+ end
41
+ end
42
+
43
+ def closed?
44
+ @terminated == true
45
+ end
46
+
47
+ end
48
+
49
+ module StatdHelpers
50
+
51
+ def random_port
52
+ rand(2000..10000)
53
+ end
54
+
55
+ end
56
+
57
+ RSpec.configure do |c|
58
+
59
+ c.include StatdHelpers
60
+
61
+ c.before(:all) do
62
+ srand(c.seed)
63
+ @server = StatsdServer.new.run(random_port)
64
+ end
65
+
66
+ c.after(:all) do
67
+ @server.close
68
+ end
69
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-output-statsd
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.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-08-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: logstash-core
@@ -89,6 +89,7 @@ files:
89
89
  - lib/logstash/outputs/statsd.rb
90
90
  - logstash-output-statsd.gemspec
91
91
  - spec/outputs/statsd_spec.rb
92
+ - spec/spec_helper.rb
92
93
  homepage: http://www.elastic.co/guide/en/logstash/current/index.html
93
94
  licenses:
94
95
  - Apache License (2.0)
@@ -111,9 +112,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
111
112
  version: '0'
112
113
  requirements: []
113
114
  rubyforge_project:
114
- rubygems_version: 2.2.2
115
+ rubygems_version: 2.1.9
115
116
  signing_key:
116
117
  specification_version: 4
117
118
  summary: Send metrics to StatsD
118
119
  test_files:
119
120
  - spec/outputs/statsd_spec.rb
121
+ - spec/spec_helper.rb