logstash-input-udp 3.2.1 → 3.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/LICENSE +1 -1
- data/lib/logstash/inputs/udp.rb +12 -2
- data/logstash-input-udp.gemspec +1 -1
- data/spec/inputs/udp_spec.rb +29 -16
- data/spec/support/client.rb +9 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 60d650bd7c475a99512a2152b86460f1b8721772b2b2fd280f646027c77af60b
|
4
|
+
data.tar.gz: f99989e62ebfc5854f4c0e98d44b3afc6ca1809d3d61da9d267ffa5c44c69255
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6c66d1e0b1f7a694e0ce447571df4477967a3faff0c6064367343ecf1a52621ab1570e5d34e9fcb6486a99ab953da278a1cf5598eafee62d9ef2e0f20eea8166
|
7
|
+
data.tar.gz: 014d6c60519f8be62db95fbc09469a2afc46a44a9febaad3a03827c240b756a7721d4f7fd9c81cc9d850975e8b10371dea73fa7d41ac81920469401469c1b7ab
|
data/CHANGELOG.md
CHANGED
data/LICENSE
CHANGED
data/lib/logstash/inputs/udp.rb
CHANGED
@@ -46,7 +46,8 @@ class LogStash::Inputs::Udp < LogStash::Inputs::Base
|
|
46
46
|
|
47
47
|
def register
|
48
48
|
@udp = nil
|
49
|
-
|
49
|
+
@metric_errors = metric.namespace(:errors)
|
50
|
+
end # def register
|
50
51
|
|
51
52
|
def run(output_queue)
|
52
53
|
@output_queue = output_queue
|
@@ -56,6 +57,7 @@ class LogStash::Inputs::Udp < LogStash::Inputs::Base
|
|
56
57
|
udp_listener(output_queue)
|
57
58
|
rescue => e
|
58
59
|
@logger.warn("UDP listener died", :exception => e, :backtrace => e.backtrace)
|
60
|
+
@metric_errors.increment(:listener)
|
59
61
|
Stud.stoppable_sleep(5) { stop? }
|
60
62
|
retry unless stop?
|
61
63
|
end
|
@@ -82,7 +84,11 @@ class LogStash::Inputs::Udp < LogStash::Inputs::Base
|
|
82
84
|
@udp.close
|
83
85
|
end
|
84
86
|
|
85
|
-
|
87
|
+
if IPAddr.new(@host).ipv6?
|
88
|
+
@udp = UDPSocket.new(Socket::AF_INET6)
|
89
|
+
elsif IPAddr.new(@host).ipv4?
|
90
|
+
@udp = UDPSocket.new(Socket::AF_INET)
|
91
|
+
end
|
86
92
|
# set socket receive buffer size if configured
|
87
93
|
if @receive_buffer_bytes
|
88
94
|
@udp.setsockopt(Socket::SOL_SOCKET, Socket::SO_RCVBUF, @receive_buffer_bytes)
|
@@ -96,6 +102,8 @@ class LogStash::Inputs::Udp < LogStash::Inputs::Base
|
|
96
102
|
@logger.info("UDP listener started", :address => "#{@host}:#{@port}", :receive_buffer_bytes => "#{rcvbuf}", :queue_size => "#{@queue_size}")
|
97
103
|
|
98
104
|
@input_to_worker = SizedQueue.new(@queue_size)
|
105
|
+
metric.gauge(:queue_size, @queue_size)
|
106
|
+
metric.gauge(:workers, @workers)
|
99
107
|
|
100
108
|
@input_workers = @workers.times do |i|
|
101
109
|
@logger.debug("Starting UDP worker thread", :worker => i)
|
@@ -135,6 +143,7 @@ class LogStash::Inputs::Udp < LogStash::Inputs::Base
|
|
135
143
|
end
|
136
144
|
rescue => e
|
137
145
|
@logger.error("Exception in inputworker", "exception" => e, "backtrace" => e.backtrace)
|
146
|
+
@metric_errors.increment(:worker)
|
138
147
|
end
|
139
148
|
end
|
140
149
|
|
@@ -142,6 +151,7 @@ class LogStash::Inputs::Udp < LogStash::Inputs::Base
|
|
142
151
|
decorate(event)
|
143
152
|
event.set(HOST_FIELD, host) if event.get(HOST_FIELD).nil?
|
144
153
|
@output_queue.push(event)
|
154
|
+
metric.increment(:events)
|
145
155
|
end
|
146
156
|
|
147
157
|
def ignore_close_and_log(e)
|
data/logstash-input-udp.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
|
3
3
|
s.name = 'logstash-input-udp'
|
4
|
-
s.version = '3.
|
4
|
+
s.version = '3.3.0'
|
5
5
|
s.licenses = ['Apache License (2.0)']
|
6
6
|
s.summary = "Reads events over 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/logstash-plugin install gemname. This gem is not a stand-alone program"
|
data/spec/inputs/udp_spec.rb
CHANGED
@@ -11,7 +11,8 @@ describe LogStash::Inputs::Udp do
|
|
11
11
|
let!(:helper) { UdpHelpers.new }
|
12
12
|
let(:client) { LogStash::Inputs::Test::UDPClient.new(port) }
|
13
13
|
let(:port) { rand(1024..65535) }
|
14
|
-
let(:
|
14
|
+
let(:host) { "0.0.0.0" }
|
15
|
+
let(:config) { { "port" => port, "host" => host } }
|
15
16
|
subject { LogStash::Plugin.lookup("input","udp").new(config) }
|
16
17
|
|
17
18
|
after :each do
|
@@ -25,26 +26,38 @@ describe LogStash::Inputs::Udp do
|
|
25
26
|
end
|
26
27
|
|
27
28
|
describe "receive" do
|
28
|
-
|
29
|
+
shared_examples "receiving" do
|
30
|
+
before(:each) do
|
31
|
+
subject.register
|
32
|
+
end
|
29
33
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
+
let(:nevents) { 10 }
|
35
|
+
|
36
|
+
let(:events) do
|
37
|
+
helper.input(subject, nevents) do
|
38
|
+
nevents.times do |i|
|
39
|
+
client.send("msg #{i}")
|
40
|
+
end
|
34
41
|
end
|
35
42
|
end
|
36
|
-
end
|
37
43
|
|
38
|
-
|
39
|
-
|
44
|
+
it "should receive events been generated" do
|
45
|
+
expect(events.size).to be(nevents)
|
46
|
+
messages = events.map { |event| event.get("message")}
|
47
|
+
messages.each do |message|
|
48
|
+
expect(message).to match(/msg \d+/)
|
49
|
+
end
|
50
|
+
end
|
40
51
|
end
|
41
52
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
53
|
+
context "ipv4" do
|
54
|
+
let(:client) { LogStash::Inputs::Test::UDPClient.new(port, "127.0.0.1") }
|
55
|
+
include_examples "receiving"
|
56
|
+
end
|
57
|
+
context "ipv6" do
|
58
|
+
let(:host) { "::1" }
|
59
|
+
let(:client) { LogStash::Inputs::Test::UDPClient.new(port, "::1") }
|
60
|
+
include_examples "receiving"
|
48
61
|
end
|
49
62
|
end
|
50
63
|
|
@@ -74,4 +87,4 @@ describe LogStash::Inputs::Udp do
|
|
74
87
|
it_behaves_like "an interruptible input plugin" do
|
75
88
|
# see https://github.com/elastic/logstash-devutils/blob/9c4a1fbf2b0c4547e428c5a40ed84f60aad17f97/lib/logstash/devutils/rspec/shared_examples.rb
|
76
89
|
end
|
77
|
-
end
|
90
|
+
end
|
data/spec/support/client.rb
CHANGED
@@ -1,21 +1,25 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require "socket"
|
3
|
+
require "ipaddr"
|
3
4
|
|
4
5
|
module LogStash::Inputs::Test
|
5
6
|
|
6
7
|
class UDPClient
|
7
8
|
attr_reader :host, :port, :socket
|
8
9
|
|
9
|
-
def initialize(port)
|
10
|
+
def initialize(port, host = "0.0.0.0")
|
11
|
+
@host = host
|
10
12
|
@port = port
|
11
|
-
@host
|
12
|
-
|
13
|
-
|
13
|
+
if IPAddr.new(@host).ipv6?
|
14
|
+
@socket = UDPSocket.new(Socket::AF_INET6)
|
15
|
+
elsif IPAddr.new(@host).ipv4?
|
16
|
+
@socket = UDPSocket.new(Socket::AF_INET)
|
17
|
+
end
|
18
|
+
@socket.connect(host, port)
|
14
19
|
end
|
15
20
|
|
16
21
|
def send(msg)
|
17
22
|
begin
|
18
|
-
socket.connect(host, port) if socket.closed?
|
19
23
|
socket.send(msg, 0)
|
20
24
|
rescue => e
|
21
25
|
puts("send exception, retrying", e.inspect)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logstash-input-udp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Elastic
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-03-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|