fluent-plugin-nats 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -1
- data/Gemfile.lock +2 -2
- data/README.md +2 -1
- data/VERSION +1 -1
- data/lib/fluent/plugin/in_nats.rb +26 -7
- data/test/plugin/in_nats.rb +144 -7
- metadata +2 -2
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
fluent-plugin-nats (0.0.
|
4
|
+
fluent-plugin-nats (0.0.5)
|
5
5
|
eventmachine (= 0.12.10)
|
6
6
|
fluentd (>= 0.10.7)
|
7
7
|
nats (>= 0.4.22)
|
8
8
|
|
9
9
|
GEM
|
10
|
-
remote:
|
10
|
+
remote: https://rubygems.org/
|
11
11
|
specs:
|
12
12
|
cool.io (1.1.0)
|
13
13
|
iobuffer (>= 1.0.0)
|
data/README.md
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.5
|
@@ -8,6 +8,9 @@ module Fluent
|
|
8
8
|
config_param :port, :integer, :default => 4222
|
9
9
|
config_param :queue, :string, :default => "fluent.>"
|
10
10
|
config_param :tag, :string, :default => "nats"
|
11
|
+
config_param :ssl, :bool, :default => false
|
12
|
+
config_param :max_reconnect_attempts, :integer, :default => 150
|
13
|
+
config_param :reconnect_time_wait, :integer, :default => 2
|
11
14
|
|
12
15
|
def initialize
|
13
16
|
require "nats/client"
|
@@ -19,10 +22,18 @@ module Fluent
|
|
19
22
|
def configure(conf)
|
20
23
|
super
|
21
24
|
@conf = conf
|
22
|
-
@uri = "nats://#{@user}:#{@password}@#{@host}:#{@port}"
|
23
25
|
unless @host && @queue
|
24
26
|
raise ConfigError, "'host' and 'queue' must be all specified."
|
25
27
|
end
|
28
|
+
|
29
|
+
@nats_config = {
|
30
|
+
:uri => "nats://#{@host}:#{@port}",
|
31
|
+
:ssl => @ssl,
|
32
|
+
:user => @user,
|
33
|
+
:pass => @password,
|
34
|
+
:reconnect_time_wait => @reconnect_time_wait,
|
35
|
+
:max_reconnect_attempts => @max_reconnect_attempts,
|
36
|
+
}
|
26
37
|
end
|
27
38
|
|
28
39
|
def start
|
@@ -41,13 +52,21 @@ module Fluent
|
|
41
52
|
end
|
42
53
|
|
43
54
|
def run
|
55
|
+
queues = @queue.split(',')
|
44
56
|
EM.next_tick {
|
45
|
-
@nats_conn = NATS.connect(
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
57
|
+
@nats_conn = NATS.connect(@nats_config) {
|
58
|
+
queues.each do |queue|
|
59
|
+
@nats_conn.subscribe(queue) do |msg, reply, sub|
|
60
|
+
tag = "#{@tag}.#{sub}"
|
61
|
+
begin
|
62
|
+
msg_json = JSON.parse(msg)
|
63
|
+
rescue JSON::ParserError => e
|
64
|
+
$log.error "Failed parsing JSON #{e.inspect}. Passing as a normal string"
|
65
|
+
msg_json = msg
|
66
|
+
end
|
67
|
+
time = Engine.now
|
68
|
+
Engine.emit(tag, time, msg_json)
|
69
|
+
end
|
51
70
|
end
|
52
71
|
}
|
53
72
|
}
|
data/test/plugin/in_nats.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'test/unit'
|
2
2
|
require 'fluent/test'
|
3
|
-
require 'lib/fluent/plugin/in_nats'
|
3
|
+
require 'lib/fluent/plugin/in_nats.rb'
|
4
4
|
require 'nats/client'
|
5
5
|
require 'test_helper'
|
6
6
|
|
@@ -12,16 +12,32 @@ class NATSInputTest < Test::Unit::TestCase
|
|
12
12
|
host localhost
|
13
13
|
user nats
|
14
14
|
password nats
|
15
|
-
queue fluent.>
|
16
15
|
]
|
17
16
|
|
18
|
-
|
17
|
+
def basic_queue_conf
|
18
|
+
conf = CONFIG + %[
|
19
|
+
queue fluent.>
|
20
|
+
]
|
21
|
+
end
|
22
|
+
|
23
|
+
def multiple_queue_conf
|
24
|
+
conf = CONFIG + %[
|
25
|
+
queue fluent.>, fluent2.>
|
26
|
+
]
|
27
|
+
end
|
28
|
+
|
29
|
+
def ssl_conf
|
30
|
+
conf = basic_queue_conf + %[
|
31
|
+
ssl true
|
32
|
+
]
|
33
|
+
end
|
34
|
+
|
19
35
|
def create_driver(conf=CONFIG)
|
20
36
|
Fluent::Test::InputTestDriver.new(Fluent::NATSInput).configure(conf)
|
21
37
|
end
|
22
38
|
|
23
|
-
def
|
24
|
-
d = create_driver
|
39
|
+
def test_configure_basic
|
40
|
+
d = create_driver basic_queue_conf
|
25
41
|
assert_equal 4222, d.instance.port
|
26
42
|
assert_equal 'localhost', d.instance.host
|
27
43
|
assert_equal 'nats', d.instance.user
|
@@ -29,8 +45,27 @@ class NATSInputTest < Test::Unit::TestCase
|
|
29
45
|
assert_equal 'fluent.>', d.instance.queue
|
30
46
|
end
|
31
47
|
|
48
|
+
def test_configure_multiple_queue
|
49
|
+
d = create_driver multiple_queue_conf
|
50
|
+
assert_equal 4222, d.instance.port
|
51
|
+
assert_equal 'localhost', d.instance.host
|
52
|
+
assert_equal 'nats', d.instance.user
|
53
|
+
assert_equal 'nats', d.instance.password
|
54
|
+
assert_equal 'fluent.>, fluent2.>', d.instance.queue
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_configure_basic_with_ssl
|
58
|
+
d = create_driver ssl_conf
|
59
|
+
assert_equal 4222, d.instance.port
|
60
|
+
assert_equal 'localhost', d.instance.host
|
61
|
+
assert_equal 'nats', d.instance.user
|
62
|
+
assert_equal 'nats', d.instance.password
|
63
|
+
assert_equal 'fluent.>', d.instance.queue
|
64
|
+
assert_equal true, d.instance.ssl
|
65
|
+
end
|
66
|
+
|
32
67
|
def test_emit_with_credentials
|
33
|
-
d = create_driver
|
68
|
+
d = create_driver basic_queue_conf
|
34
69
|
|
35
70
|
time = Time.parse("2011-01-02 13:14:15 UTC").to_i
|
36
71
|
Fluent::Engine.now = time
|
@@ -51,13 +86,36 @@ class NATSInputTest < Test::Unit::TestCase
|
|
51
86
|
end
|
52
87
|
|
53
88
|
def test_emit_without_credentials
|
54
|
-
d = create_driver
|
89
|
+
d = create_driver basic_queue_conf
|
90
|
+
|
91
|
+
time = Time.parse("2011-01-02 13:14:15 UTC").to_i
|
92
|
+
Fluent::Engine.now = time
|
93
|
+
|
94
|
+
d.expect_emit "nats.fluent.test1", time, {"message"=>'nats', "fluent_timestamp"=>time}
|
95
|
+
d.expect_emit "nats.fluent.test2", time, {"message"=>'nats', "fluent_timestamp"=>time}
|
96
|
+
|
97
|
+
uri = "nats://#{d.instance.host}:#{d.instance.port}"
|
98
|
+
|
99
|
+
start_nats(uri)
|
100
|
+
d.run do
|
101
|
+
d.expected_emits.each { |tag, time, record|
|
102
|
+
send(uri, tag[5..-1], record)
|
103
|
+
sleep 0.5
|
104
|
+
}
|
105
|
+
end
|
106
|
+
kill_nats
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_emit_multiple_queues
|
110
|
+
d = create_driver multiple_queue_conf
|
55
111
|
|
56
112
|
time = Time.parse("2011-01-02 13:14:15 UTC").to_i
|
57
113
|
Fluent::Engine.now = time
|
58
114
|
|
59
115
|
d.expect_emit "nats.fluent.test1", time, {"message"=>'nats', "fluent_timestamp"=>time}
|
60
116
|
d.expect_emit "nats.fluent.test2", time, {"message"=>'nats', "fluent_timestamp"=>time}
|
117
|
+
d.expect_emit "nats.fluent2.test1", time, {"message"=>'nats', "fluent_timestamp"=>time}
|
118
|
+
d.expect_emit "nats.fluent2.test2", time, {"message"=>'nats', "fluent_timestamp"=>time}
|
61
119
|
|
62
120
|
uri = "nats://#{d.instance.host}:#{d.instance.port}"
|
63
121
|
|
@@ -72,6 +130,83 @@ class NATSInputTest < Test::Unit::TestCase
|
|
72
130
|
end
|
73
131
|
|
74
132
|
|
133
|
+
def test_emit_without_fluent_timestamp
|
134
|
+
d = create_driver basic_queue_conf
|
135
|
+
|
136
|
+
time = Time.now.to_i
|
137
|
+
Fluent::Engine.now = time
|
138
|
+
|
139
|
+
d.expect_emit "nats.fluent.test1", time, {"message"=>'nats'}
|
140
|
+
|
141
|
+
uri = "nats://#{d.instance.host}:#{d.instance.port}"
|
142
|
+
start_nats(uri)
|
143
|
+
d.run do
|
144
|
+
d.expected_emits.each do |tag, time, record|
|
145
|
+
send(uri, tag[5..-1], record)
|
146
|
+
sleep 0.5
|
147
|
+
end
|
148
|
+
end
|
149
|
+
kill_nats
|
150
|
+
end
|
151
|
+
|
152
|
+
def test_emit_arrays
|
153
|
+
d = create_driver basic_queue_conf
|
154
|
+
|
155
|
+
time = Time.now.to_i
|
156
|
+
Fluent::Engine.now = time
|
157
|
+
|
158
|
+
d.expect_emit "nats.fluent.empty_array", time, []
|
159
|
+
d.expect_emit "nats.fluent.string_array", time, %w(one two three)
|
160
|
+
|
161
|
+
uri = "nats://#{d.instance.host}:#{d.instance.port}"
|
162
|
+
start_nats(uri)
|
163
|
+
d.run do
|
164
|
+
d.expected_emits.each do |tag, time, record|
|
165
|
+
send(uri, tag[5..-1], record)
|
166
|
+
sleep 0.5
|
167
|
+
end
|
168
|
+
end
|
169
|
+
kill_nats
|
170
|
+
end
|
171
|
+
|
172
|
+
def test_empty_publish_string
|
173
|
+
d = create_driver basic_queue_conf
|
174
|
+
|
175
|
+
time = Time.now.to_i
|
176
|
+
Fluent::Engine.now = time
|
177
|
+
|
178
|
+
d.expect_emit "nats.fluent.nil", time, nil
|
179
|
+
|
180
|
+
uri = "nats://#{d.instance.host}:#{d.instance.port}"
|
181
|
+
start_nats(uri)
|
182
|
+
d.run do
|
183
|
+
d.expected_emits.each do |tag, time, record|
|
184
|
+
send(uri, tag[5..-1], nil)
|
185
|
+
sleep 0.5
|
186
|
+
end
|
187
|
+
end
|
188
|
+
kill_nats
|
189
|
+
end
|
190
|
+
|
191
|
+
def test_regular_publish_string
|
192
|
+
d = create_driver basic_queue_conf
|
193
|
+
|
194
|
+
time = Time.now.to_i
|
195
|
+
Fluent::Engine.now = time
|
196
|
+
|
197
|
+
d.expect_emit "nats.fluent.string", time, "Lorem ipsum dolor sit amet"
|
198
|
+
|
199
|
+
uri = "nats://#{d.instance.host}:#{d.instance.port}"
|
200
|
+
start_nats(uri)
|
201
|
+
d.run do
|
202
|
+
d.expected_emits.each do |tag, time, record|
|
203
|
+
send(uri, tag[5..-1], "Lorem ipsum dolor sit amet")
|
204
|
+
sleep 0.5
|
205
|
+
end
|
206
|
+
end
|
207
|
+
kill_nats
|
208
|
+
end
|
209
|
+
|
75
210
|
def setup
|
76
211
|
Fluent::Test.setup
|
77
212
|
end
|
@@ -84,3 +219,5 @@ class NATSInputTest < Test::Unit::TestCase
|
|
84
219
|
}
|
85
220
|
end
|
86
221
|
end
|
222
|
+
|
223
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-nats
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-02-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: fluentd
|