logstash-output-statsd 3.1.5 → 3.2.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
  SHA256:
3
- metadata.gz: 9375255d0cc0ec934c5317143c293d8ac15f7bac3ab91975abdc1c770f8cc755
4
- data.tar.gz: cf939fb95644f3f3b086e3d51b7b1642880f0ca32389196ab9686a406a51250b
3
+ metadata.gz: 964258cd9a1aae17bd03ba061ee09d438f738920a7d4876fe4f4b135f198cace
4
+ data.tar.gz: 49733d6030a54c8af5ca28160674c5864fb987a854b42d5217d58cdb7e5e94b7
5
5
  SHA512:
6
- metadata.gz: 3875ed72d511e73b68e6096e9e645b4842c15b9a93e75d075f871180269fe1aaad4ee28dec2866c6bb5f72c654f4dc9333e136a5fac314a689866345fa72dfaf
7
- data.tar.gz: 58674d330177bc186d0e47f6743405ee1849b4caa7553a904e27a251ec85d7100cb6aa415d474e59c6e7e4869946811e7b41d7f55df4f4dce47141cc75a04255
6
+ metadata.gz: 4655cb2492410e1fa87f025e48e34a2d783485fd0f915d53d6af5b240a56375061851b99b3aeb647d9c7e51000fcd34da9f11410d34543bf37febd3332f80366
7
+ data.tar.gz: b8350eb84ba61eda26d06cca47dec6c28c1736b18f32e1475e9f67be6eed97847d133558d002907e3348282522f3860710df7b3c744cf446c08ae31c4ef730d2
@@ -1,3 +1,7 @@
1
+ ## 3.2.0
2
+ - Added TCP support [30](https://github.com/logstash-plugins/logstash-output-statsd/pull/30)
3
+ - Changed test code for cleanups [31](https://github.com/logstash-plugins/logstash-output-statsd/pull/31)
4
+
1
5
  ## 3.1.5
2
6
  - Docs: Set the default_codec doc attribute.
3
7
 
@@ -153,6 +153,15 @@ allowed.
153
153
 
154
154
  The port to connect to on your statsd server.
155
155
 
156
+ [id="plugins-{type}s-{plugin}-protocol"]
157
+
158
+ ===== `protocol`
159
+
160
+ * Value type is <<string,string>>
161
+ * Default value is `"udp"`
162
+
163
+ The protocol to connect to on your statsd server.
164
+
156
165
  [id="plugins-{type}s-{plugin}-sample_rate"]
157
166
  ===== `sample_rate`
158
167
 
@@ -193,4 +202,4 @@ are allowed in the metric names.
193
202
  [id="plugins-{type}s-{plugin}-common-options"]
194
203
  include::{include_path}/{type}.asciidoc[]
195
204
 
196
- :default_codec!:
205
+ :default_codec!:
@@ -57,6 +57,9 @@ class LogStash::Outputs::Statsd < LogStash::Outputs::Base
57
57
  # The port to connect to on your statsd server.
58
58
  config :port, :validate => :number, :default => 8125
59
59
 
60
+ # The protocol to use for the connection.
61
+ config :protocol, :validate => ['udp', 'tcp'], :default => "udp"
62
+
60
63
  # The statsd namespace to use for this metric. `%{fieldname}` substitutions are
61
64
  # allowed.
62
65
  config :namespace, :validate => :string, :default => "logstash"
@@ -95,7 +98,7 @@ class LogStash::Outputs::Statsd < LogStash::Outputs::Base
95
98
  public
96
99
  def register
97
100
  require "statsd"
98
- @client = Statsd.new(@host, @port)
101
+ @client = Statsd.new(@host, @port, @protocol.to_sym)
99
102
  end # def register
100
103
 
101
104
  public
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
 
3
3
  s.name = 'logstash-output-statsd'
4
- s.version = '3.1.5'
4
+ s.version = '3.2.0'
5
5
  s.licenses = ['Apache License (2.0)']
6
6
  s.summary = "Sends metrics using the `statsd` network daemon"
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/logstash-plugin install gemname. This gem is not a stand-alone program"
@@ -23,7 +23,7 @@ Gem::Specification.new do |s|
23
23
  s.add_runtime_dependency "logstash-core-plugin-api", ">= 1.60", "<= 2.99"
24
24
  s.add_runtime_dependency 'logstash-input-generator'
25
25
 
26
- s.add_runtime_dependency 'statsd-ruby', ['1.2.0']
26
+ s.add_runtime_dependency 'statsd-ruby', ['1.4.0']
27
27
 
28
28
  s.add_development_dependency 'logstash-devutils'
29
29
  end
@@ -1,57 +1,60 @@
1
1
  # encoding: utf-8
2
2
  require_relative "../spec_helper"
3
3
  require "logstash/outputs/statsd"
4
+ require "socket"
4
5
 
5
6
  describe LogStash::Outputs::Statsd do
6
7
 
7
- let(:host) { "localhost" }
8
- let(:port) { rand(2000..10000) }
9
- let!(:server) { StatsdServer.new.run(port) }
10
-
11
- after(:each) do
12
- server.close
13
- end
14
-
15
8
  describe "registration and close" do
16
-
17
9
  it "should register without errors" do
18
10
  output = LogStash::Plugin.lookup("output", "statsd").new
19
11
  expect {output.register}.to_not raise_error
20
12
  end
21
-
22
13
  end
23
14
 
24
- describe "#send" do
15
+ describe "IO" do
16
+ let(:host) { "localhost" }
17
+ let(:port) { rand(2000..10000) }
18
+ let!(:server) { StatsdServer.new.run(port, protocol) }
25
19
 
26
- context "count metrics" do
20
+ after(:each) { server.close }
27
21
 
22
+ shared_examples "it receives sent data" do
28
23
  let(:config) do
29
- { "host" => host, "sender" => "spec", "port" => port, "count" => [ "foo.bar", "0.1" ] }
24
+ { "host" => host, "sender" => "spec", "port" => port, "protocol" => protocol, "count" => [ "foo.bar", "0.1" ] }
30
25
  end
31
-
32
26
  let(:properties) do
33
27
  { "metric" => "foo.bar", "count" => 10 }
34
28
  end
35
-
36
29
  let(:event) { LogStash::Event.new(properties) }
37
30
 
38
31
  subject { LogStash::Outputs::Statsd.new(config) }
39
32
 
40
- before(:each) do
41
- subject.register
42
- end
33
+ before(:each) { subject.register }
43
34
 
44
35
  it "should receive data send to the server" do
45
36
  subject.receive(event)
46
- # Since we are dealing with threads and networks,
37
+ # Since we are dealing with threads and networks,
47
38
  # we might experience delays or timing issues.
48
39
  # lets try a few times before giving up completely.
49
- try {
50
- expect(server.received).to include("logstash.spec.foo.bar:0.1|c")
51
- }
40
+ try { expect(server.received).to include("logstash.spec.foo.bar:0.1|c") }
52
41
  end
42
+ end
43
+
44
+ describe "UDP" do
45
+ let(:protocol) { "udp" }
53
46
 
47
+ context "#send" do
48
+ include_examples "it receives sent data"
49
+ end
54
50
  end
55
- end
56
51
 
52
+ describe "TCP" do
53
+ let(:protocol) { "tcp" }
54
+
55
+ context "#send" do
56
+ include_examples "it receives sent data"
57
+ end
58
+ end
59
+ end
57
60
  end
@@ -11,20 +11,28 @@ class StatsdServer
11
11
  @received = []
12
12
  end
13
13
 
14
- def register(port)
15
- @port = port
16
- @socket = UDPSocket.new
17
- @socket.bind("127.0.0.1", port)
14
+ def register(port, protocol)
15
+ @port = port
16
+ if protocol == "udp"
17
+ @socket = UDPSocket.new
18
+ @socket.bind("127.0.0.1", port)
19
+ else
20
+ @socket = TCPserver.new("127.0.0.1", port)
21
+ end
18
22
  end
19
23
 
20
- def run(port)
21
- register(port)
24
+
25
+ def run(port, protocol = "udp")
26
+ register(port, protocol)
27
+
22
28
  Thread.new do
23
- while(!closed?)
24
- metric, _ = @socket.recvfrom(100)
25
- append(metric)
29
+ if protocol == "udp"
30
+ udp_receive
31
+ else
32
+ tcp_receive
26
33
  end
27
34
  end
35
+
28
36
  self
29
37
  end
30
38
 
@@ -43,7 +51,23 @@ class StatsdServer
43
51
  def closed?
44
52
  @terminated == true
45
53
  end
54
+ end
46
55
 
56
+ private
57
+
58
+ def tcp_receive
59
+ client = @socket.accept
60
+ Timeout.timeout(5) { sleep(0.1) while client.nil? }
61
+ metric = client.recvfrom(100).first
62
+ append(metric)
63
+ client.close
64
+ end
65
+
66
+ def udp_receive
67
+ while(!closed?)
68
+ metric, _ = @socket.recvfrom(100)
69
+ append(metric)
70
+ end
47
71
  end
48
72
 
49
73
  RSpec.configure do |c|
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: 3.1.5
4
+ version: 3.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elastic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-06 00:00:00.000000000 Z
11
+ date: 2018-06-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -49,7 +49,7 @@ dependencies:
49
49
  requirements:
50
50
  - - '='
51
51
  - !ruby/object:Gem::Version
52
- version: 1.2.0
52
+ version: 1.4.0
53
53
  name: statsd-ruby
54
54
  prerelease: false
55
55
  type: :runtime
@@ -57,7 +57,7 @@ dependencies:
57
57
  requirements:
58
58
  - - '='
59
59
  - !ruby/object:Gem::Version
60
- version: 1.2.0
60
+ version: 1.4.0
61
61
  - !ruby/object:Gem::Dependency
62
62
  requirement: !ruby/object:Gem::Requirement
63
63
  requirements:
@@ -113,7 +113,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
113
113
  version: '0'
114
114
  requirements: []
115
115
  rubyforge_project:
116
- rubygems_version: 2.6.11
116
+ rubygems_version: 2.6.13
117
117
  signing_key:
118
118
  specification_version: 4
119
119
  summary: Sends metrics using the `statsd` network daemon