fluent-plugin-nats 0.0.5 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +1 -0
- data/.travis.yml +14 -2
- data/README.md +2 -2
- data/Rakefile +2 -1
- data/fluent-plugin-nats.gemspec +5 -4
- data/lib/fluent/plugin/in_nats.rb +5 -5
- data/test/nats-publish-message.rb +40 -0
- data/test/plugin/test_in_nats.rb +234 -0
- data/test/test_helper.rb +18 -36
- metadata +46 -37
- data/Gemfile.lock +0 -45
- data/VERSION +0 -1
- data/test/plugin/in_nats.rb +0 -223
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 774b17902a6d2b133d83d093ae6ea1b2e1767112
|
4
|
+
data.tar.gz: 6d75ec076c1ab6e82916bd43da7101191a34d5b4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8dc09878eeee36105446dc2a07669f9cd57c55547d2c430fc1be0f944dcddaa45d94335411474a420639a07cb672078c7caaf8917f721d8136bbf16b24fd0fe7
|
7
|
+
data.tar.gz: 5f8a5cfbb0190f7600c8450d8e82afaeaaee9368da6e456d3bb11e0f61d289f430630c0d9c0bfe868d1382bee54b5212efb2ca8887ffa7a312aa039e448df746
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
@@ -1,4 +1,16 @@
|
|
1
1
|
language: ruby
|
2
2
|
rvm:
|
3
|
-
-
|
4
|
-
-
|
3
|
+
- 2.4.2
|
4
|
+
- 2.3.5
|
5
|
+
- 2.2
|
6
|
+
- 2.1
|
7
|
+
|
8
|
+
env:
|
9
|
+
global:
|
10
|
+
GNATSD_VERSION: 1.0.4
|
11
|
+
|
12
|
+
before_install:
|
13
|
+
- sudo rm -f /usr/local/bin/gnatsd
|
14
|
+
- curl -L https://github.com/nats-io/gnatsd/releases/download/v${GNATSD_VERSION}/gnatsd-v${GNATSD_VERSION}-linux-amd64.zip > /tmp/gnatsd-v${GNATSD_VERSION}-linux-amd64.zip
|
15
|
+
- unzip /tmp/gnatsd-v${GNATSD_VERSION}-linux-amd64.zip -d /tmp
|
16
|
+
- sudo mv /tmp/gnatsd-v${GNATSD_VERSION}-linux-amd64/gnatsd /usr/local/bin/gnatsd
|
data/README.md
CHANGED
@@ -12,7 +12,7 @@ Setup the NATS input:
|
|
12
12
|
|
13
13
|
~~~~~
|
14
14
|
<source>
|
15
|
-
type nats
|
15
|
+
@type nats
|
16
16
|
tag nats
|
17
17
|
host localhost
|
18
18
|
port 4222
|
@@ -27,7 +27,7 @@ Setup the match output:
|
|
27
27
|
|
28
28
|
~~~~
|
29
29
|
<match nats.fluent.**>
|
30
|
-
type stdout
|
30
|
+
@type stdout
|
31
31
|
</match>
|
32
32
|
~~~~
|
33
33
|
|
data/Rakefile
CHANGED
@@ -8,7 +8,8 @@ Rake::TestTask.new(:test) do |test|
|
|
8
8
|
test.test_files = Dir['test/plugin/*.rb']
|
9
9
|
test.ruby_opts = ['-rubygems'] if defined? Gem
|
10
10
|
test.ruby_opts << '-I.'
|
11
|
-
test.verbose =
|
11
|
+
test.verbose = false
|
12
|
+
test.warning = false
|
12
13
|
end
|
13
14
|
|
14
15
|
task :default => :test
|
data/fluent-plugin-nats.gemspec
CHANGED
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |gem|
|
5
5
|
gem.name = "fluent-plugin-nats"
|
6
|
-
gem.version =
|
6
|
+
gem.version = "0.1.0"
|
7
7
|
gem.authors = ["Eduardo Aceituno"]
|
8
8
|
gem.email = ["achied@gmail.com"]
|
9
9
|
gem.homepage = "https://github.com/achied/fluent-plugin-nats"
|
@@ -15,9 +15,10 @@ Gem::Specification.new do |gem|
|
|
15
15
|
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
16
16
|
gem.require_paths = ["lib"]
|
17
17
|
|
18
|
-
gem.add_dependency "
|
18
|
+
gem.add_dependency "eventmachine", ">= 0.12.10"
|
19
|
+
gem.add_dependency "fluentd", ">= 0.10.7", "< 0.14"
|
19
20
|
gem.add_dependency "nats", ">= 0.4.22"
|
20
|
-
|
21
|
-
|
21
|
+
|
22
22
|
gem.add_development_dependency "rake", ">= 0.9.2"
|
23
|
+
gem.add_development_dependency "test-unit", "> 3.1"
|
23
24
|
end
|
@@ -4,7 +4,7 @@ module Fluent
|
|
4
4
|
|
5
5
|
config_param :host, :string, :default => "localhost"
|
6
6
|
config_param :user, :string, :default => "nats"
|
7
|
-
config_param :password, :string, :default => "nats"
|
7
|
+
config_param :password, :string, :default => "nats", :secret => true
|
8
8
|
config_param :port, :integer, :default => 4222
|
9
9
|
config_param :queue, :string, :default => "fluent.>"
|
10
10
|
config_param :tag, :string, :default => "nats"
|
@@ -21,7 +21,7 @@ module Fluent
|
|
21
21
|
|
22
22
|
def configure(conf)
|
23
23
|
super
|
24
|
-
|
24
|
+
|
25
25
|
unless @host && @queue
|
26
26
|
raise ConfigError, "'host' and 'queue' must be all specified."
|
27
27
|
end
|
@@ -40,7 +40,7 @@ module Fluent
|
|
40
40
|
super
|
41
41
|
run_reactor_thread
|
42
42
|
@thread = Thread.new(&method(:run))
|
43
|
-
|
43
|
+
log.info "listening nats on #{@uri}/#{@queue}"
|
44
44
|
end
|
45
45
|
|
46
46
|
def shutdown
|
@@ -61,11 +61,11 @@ module Fluent
|
|
61
61
|
begin
|
62
62
|
msg_json = JSON.parse(msg)
|
63
63
|
rescue JSON::ParserError => e
|
64
|
-
|
64
|
+
log.error "Failed parsing JSON #{e.inspect}. Passing as a normal string"
|
65
65
|
msg_json = msg
|
66
66
|
end
|
67
67
|
time = Engine.now
|
68
|
-
|
68
|
+
router.emit(tag, time, msg_json || {})
|
69
69
|
end
|
70
70
|
end
|
71
71
|
}
|
@@ -0,0 +1,40 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "nats/client"
|
5
|
+
require "optparse"
|
6
|
+
require "uri"
|
7
|
+
|
8
|
+
def main(argv)
|
9
|
+
uri = nil
|
10
|
+
queue = nil
|
11
|
+
message = nil
|
12
|
+
parser = OptionParser.new
|
13
|
+
parser.on("--uri=URI", "NATS server URI") do |value|
|
14
|
+
uri = URI.parse(value)
|
15
|
+
end
|
16
|
+
parser.on("--queue=QUEUE", "Queue names") do |value|
|
17
|
+
queue = value
|
18
|
+
end
|
19
|
+
parser.on("--message=MESSAGE", "Message JSON") do |value|
|
20
|
+
message = value[1..-2]
|
21
|
+
end
|
22
|
+
begin
|
23
|
+
parser.parse!
|
24
|
+
rescue OptionParser::ParseError => ex
|
25
|
+
puts ex.message
|
26
|
+
end
|
27
|
+
options = {
|
28
|
+
uri: uri.to_s
|
29
|
+
}
|
30
|
+
options[:user] = uri.user if uri.user
|
31
|
+
options[:pass] = uri.password if uri.password
|
32
|
+
NATS.start(options) do
|
33
|
+
NATS.publish(queue, message) do
|
34
|
+
sleep 0.5
|
35
|
+
NATS.stop
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
main(ARGV)
|
@@ -0,0 +1,234 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'fluent/test'
|
3
|
+
require 'lib/fluent/plugin/in_nats.rb'
|
4
|
+
require 'nats/client'
|
5
|
+
require 'test_helper'
|
6
|
+
|
7
|
+
class NATSInputTest < Test::Unit::TestCase
|
8
|
+
include NATSTestHelper
|
9
|
+
|
10
|
+
CONFIG = %[
|
11
|
+
port 4222
|
12
|
+
host localhost
|
13
|
+
user nats
|
14
|
+
password nats
|
15
|
+
]
|
16
|
+
|
17
|
+
def basic_queue_conf
|
18
|
+
CONFIG + %[
|
19
|
+
queue fluent.>
|
20
|
+
]
|
21
|
+
end
|
22
|
+
|
23
|
+
def multiple_queue_conf
|
24
|
+
CONFIG + %[
|
25
|
+
queue fluent.>, fluent2.>
|
26
|
+
]
|
27
|
+
end
|
28
|
+
|
29
|
+
def ssl_conf
|
30
|
+
basic_queue_conf + %[
|
31
|
+
ssl true
|
32
|
+
]
|
33
|
+
end
|
34
|
+
|
35
|
+
def create_driver(conf)
|
36
|
+
Fluent::Test::InputTestDriver.new(Fluent::NATSInput).configure(conf)
|
37
|
+
end
|
38
|
+
|
39
|
+
sub_test_case "configure" do
|
40
|
+
test "basic" do
|
41
|
+
d = create_driver basic_queue_conf
|
42
|
+
assert_equal 4222, d.instance.port
|
43
|
+
assert_equal 'localhost', d.instance.host
|
44
|
+
assert_equal 'nats', d.instance.user
|
45
|
+
assert_equal 'nats', d.instance.password
|
46
|
+
assert_equal 'fluent.>', d.instance.queue
|
47
|
+
end
|
48
|
+
|
49
|
+
test "multiple queue" do
|
50
|
+
d = create_driver multiple_queue_conf
|
51
|
+
assert_equal 4222, d.instance.port
|
52
|
+
assert_equal 'localhost', d.instance.host
|
53
|
+
assert_equal 'nats', d.instance.user
|
54
|
+
assert_equal 'nats', d.instance.password
|
55
|
+
assert_equal 'fluent.>, fluent2.>', d.instance.queue
|
56
|
+
end
|
57
|
+
|
58
|
+
test "basic with ssl" do
|
59
|
+
d = create_driver ssl_conf
|
60
|
+
assert_equal 4222, d.instance.port
|
61
|
+
assert_equal 'localhost', d.instance.host
|
62
|
+
assert_equal 'nats', d.instance.user
|
63
|
+
assert_equal 'nats', d.instance.password
|
64
|
+
assert_equal 'fluent.>', d.instance.queue
|
65
|
+
assert_equal true, d.instance.ssl
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
sub_test_case "events" do
|
70
|
+
test "with credentials" do
|
71
|
+
d = create_driver basic_queue_conf
|
72
|
+
|
73
|
+
time = Time.parse("2011-01-02 13:14:15 UTC").to_i
|
74
|
+
Fluent::Engine.now = time
|
75
|
+
|
76
|
+
d.expect_emit "nats.fluent.test1", time, {"message"=>'nats', "fluent_timestamp"=>time}
|
77
|
+
d.expect_emit "nats.fluent.test2", time, {"message"=>'nats', "fluent_timestamp"=>time}
|
78
|
+
|
79
|
+
uri = generate_uri(d)
|
80
|
+
|
81
|
+
run_server(uri) do
|
82
|
+
d.run do
|
83
|
+
d.expected_emits.each { |tag, _time, record|
|
84
|
+
send(uri, tag[5..-1], record)
|
85
|
+
sleep 0.5
|
86
|
+
}
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
test "without credentials" do
|
92
|
+
d = create_driver basic_queue_conf
|
93
|
+
|
94
|
+
time = Time.parse("2011-01-02 13:14:15 UTC").to_i
|
95
|
+
Fluent::Engine.now = time
|
96
|
+
|
97
|
+
d.expect_emit "nats.fluent.test1", time, {"message"=>'nats', "fluent_timestamp"=>time}
|
98
|
+
d.expect_emit "nats.fluent.test2", time, {"message"=>'nats', "fluent_timestamp"=>time}
|
99
|
+
|
100
|
+
uri = generate_uri(d)
|
101
|
+
|
102
|
+
run_server(uri) do
|
103
|
+
d.run do
|
104
|
+
d.expected_emits.each { |tag, time, record|
|
105
|
+
send(uri, tag[5..-1], record)
|
106
|
+
sleep 0.5
|
107
|
+
}
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
test "multiple queues" do
|
113
|
+
d = create_driver multiple_queue_conf
|
114
|
+
|
115
|
+
time = Time.parse("2011-01-02 13:14:15 UTC").to_i
|
116
|
+
Fluent::Engine.now = time
|
117
|
+
|
118
|
+
d.expect_emit "nats.fluent.test1", time, {"message"=>'nats', "fluent_timestamp"=>time}
|
119
|
+
d.expect_emit "nats.fluent.test2", time, {"message"=>'nats', "fluent_timestamp"=>time}
|
120
|
+
d.expect_emit "nats.fluent2.test1", time, {"message"=>'nats', "fluent_timestamp"=>time}
|
121
|
+
d.expect_emit "nats.fluent2.test2", time, {"message"=>'nats', "fluent_timestamp"=>time}
|
122
|
+
|
123
|
+
uri = generate_uri(d)
|
124
|
+
|
125
|
+
run_server(uri) do
|
126
|
+
d.run do
|
127
|
+
d.expected_emits.each { |tag, time, record|
|
128
|
+
send(uri, tag[5..-1], record)
|
129
|
+
sleep 0.5
|
130
|
+
}
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
test "without fluent timestamp" do
|
136
|
+
d = create_driver basic_queue_conf
|
137
|
+
|
138
|
+
time = Time.now.to_i
|
139
|
+
Fluent::Engine.now = time
|
140
|
+
|
141
|
+
d.expect_emit "nats.fluent.test1", time, {"message"=>'nats'}
|
142
|
+
|
143
|
+
uri = generate_uri(d)
|
144
|
+
run_server(uri) do
|
145
|
+
d.run do
|
146
|
+
d.expected_emits.each do |tag, time, record|
|
147
|
+
send(uri, tag[5..-1], record)
|
148
|
+
sleep 0.5
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
test "arrays" do
|
155
|
+
d = create_driver basic_queue_conf
|
156
|
+
|
157
|
+
time = Time.now.to_i
|
158
|
+
Fluent::Engine.now = time
|
159
|
+
|
160
|
+
d.expect_emit "nats.fluent.empty_array", time, []
|
161
|
+
d.expect_emit "nats.fluent.string_array", time, %w(one two three)
|
162
|
+
|
163
|
+
user = d.instance.user
|
164
|
+
password = d.instance.password
|
165
|
+
uri = "nats://#{user}:#{password}@#{d.instance.host}:#{d.instance.port}"
|
166
|
+
run_server(uri) do
|
167
|
+
d.run do
|
168
|
+
d.expected_emits.each do |tag, time, record|
|
169
|
+
send(uri, tag[5..-1], record)
|
170
|
+
sleep 0.5
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
test "empty publish string" do
|
177
|
+
d = create_driver basic_queue_conf
|
178
|
+
|
179
|
+
time = Time.now.to_i
|
180
|
+
Fluent::Engine.now = time
|
181
|
+
|
182
|
+
d.expect_emit "nats.fluent.nil", time, {}
|
183
|
+
|
184
|
+
uri = generate_uri(d)
|
185
|
+
run_server(uri) do
|
186
|
+
d.run do
|
187
|
+
d.expected_emits.each do |tag, time, record|
|
188
|
+
send(uri, tag[5..-1], nil)
|
189
|
+
sleep 0.5
|
190
|
+
end
|
191
|
+
end
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
test "regular publish string" do
|
196
|
+
d = create_driver basic_queue_conf
|
197
|
+
|
198
|
+
time = Time.now.to_i
|
199
|
+
Fluent::Engine.now = time
|
200
|
+
|
201
|
+
d.expect_emit "nats.fluent.string", time, "Lorem ipsum dolor sit amet"
|
202
|
+
|
203
|
+
uri = generate_uri(d)
|
204
|
+
run_server(uri) do
|
205
|
+
d.run do
|
206
|
+
d.expected_emits.each do |tag, time, record|
|
207
|
+
send(uri, tag[5..-1], "Lorem ipsum dolor sit amet")
|
208
|
+
sleep 0.5
|
209
|
+
end
|
210
|
+
end
|
211
|
+
end
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
def setup
|
216
|
+
Fluent::Test.setup
|
217
|
+
end
|
218
|
+
|
219
|
+
def send(uri, tag, msg)
|
220
|
+
system("test/nats-publish-message.rb", *%W[--uri=#{uri} --queue=#{tag} --message='#{msg.to_json}'])
|
221
|
+
end
|
222
|
+
|
223
|
+
def generate_uri(driver)
|
224
|
+
user = driver.instance.user
|
225
|
+
pass = driver.instance.password
|
226
|
+
host = driver.instance.host
|
227
|
+
port = driver.instance.port
|
228
|
+
if user && pass
|
229
|
+
"nats://#{user}:#{pass}@#{host}:#{port}"
|
230
|
+
else
|
231
|
+
"nats://#{host}:#{port}"
|
232
|
+
end
|
233
|
+
end
|
234
|
+
end
|
data/test/test_helper.rb
CHANGED
@@ -28,44 +28,26 @@ end
|
|
28
28
|
require 'nats/client'
|
29
29
|
|
30
30
|
module NATSTestHelper
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
@pid_file = '/tmp/test-nats.pid'
|
39
|
-
args = "-p #{@uri.port} -P #{@pid_file}"
|
40
|
-
args += " --user #{@uri.user}" unless (@uri.user.nil? || @uri.user.empty?)
|
41
|
-
args += " --pass #{@uri.password}" unless (@uri.password.nil? || @uri.password.empty?)
|
42
|
-
args += " #{@flags}" if @flags
|
43
|
-
args += ' -d'
|
44
|
-
end
|
45
|
-
|
46
|
-
def kill_nats
|
47
|
-
if File.exists? @pid_file
|
48
|
-
%x[kill -9 #{server_pid} 2> /dev/null]
|
49
|
-
%x[rm #{@pid_file} 2> /dev/null]
|
50
|
-
%x[rm #{NATS::AUTOSTART_LOG_FILE} 2> /dev/null]
|
51
|
-
@pid = nil
|
31
|
+
def run_server(uri)
|
32
|
+
uri = URI.parse(uri)
|
33
|
+
unless NATS.server_running?(uri)
|
34
|
+
args = prepare_args(uri)
|
35
|
+
# We can invoke gnatsd before run test
|
36
|
+
pid = spawn("gnatsd", *args, out: "/dev/null", err: "/dev/null")
|
37
|
+
NATS.wait_for_server(uri, 10)
|
52
38
|
end
|
39
|
+
yield
|
40
|
+
rescue
|
41
|
+
raise
|
42
|
+
ensure
|
43
|
+
Process.kill(:INT, pid) if pid
|
53
44
|
end
|
54
|
-
|
55
|
-
def start_nats(uri)
|
56
|
-
|
57
|
-
args = setup_nats_server(uri)
|
58
45
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
exitstatus = $?.exitstatus
|
66
|
-
NATS.wait_for_server(@uri, 10)
|
67
|
-
exitstatus
|
46
|
+
def prepare_args(uri)
|
47
|
+
args = ["-p", uri.port.to_s]
|
48
|
+
args.push("--user", uri.user) if uri.user
|
49
|
+
args.push("--pass", uri.password) if uri.password
|
50
|
+
args.push(*@flags) if @flags
|
51
|
+
args
|
68
52
|
end
|
69
53
|
end
|
70
|
-
|
71
|
-
|
metadata
CHANGED
@@ -1,80 +1,91 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-nats
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
5
|
-
prerelease:
|
4
|
+
version: 0.1.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Eduardo Aceituno
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2017-10-25 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: eventmachine
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.12.10
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.12.10
|
14
27
|
- !ruby/object:Gem::Dependency
|
15
28
|
name: fluentd
|
16
29
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
30
|
requirements:
|
19
|
-
- -
|
31
|
+
- - ">="
|
20
32
|
- !ruby/object:Gem::Version
|
21
33
|
version: 0.10.7
|
34
|
+
- - "<"
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '0.14'
|
22
37
|
type: :runtime
|
23
38
|
prerelease: false
|
24
39
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
40
|
requirements:
|
27
|
-
- -
|
41
|
+
- - ">="
|
28
42
|
- !ruby/object:Gem::Version
|
29
43
|
version: 0.10.7
|
44
|
+
- - "<"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0.14'
|
30
47
|
- !ruby/object:Gem::Dependency
|
31
48
|
name: nats
|
32
49
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
50
|
requirements:
|
35
|
-
- -
|
51
|
+
- - ">="
|
36
52
|
- !ruby/object:Gem::Version
|
37
53
|
version: 0.4.22
|
38
54
|
type: :runtime
|
39
55
|
prerelease: false
|
40
56
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
57
|
requirements:
|
43
|
-
- -
|
58
|
+
- - ">="
|
44
59
|
- !ruby/object:Gem::Version
|
45
60
|
version: 0.4.22
|
46
61
|
- !ruby/object:Gem::Dependency
|
47
|
-
name:
|
62
|
+
name: rake
|
48
63
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
64
|
requirements:
|
51
|
-
- -
|
65
|
+
- - ">="
|
52
66
|
- !ruby/object:Gem::Version
|
53
|
-
version: 0.
|
54
|
-
type: :
|
67
|
+
version: 0.9.2
|
68
|
+
type: :development
|
55
69
|
prerelease: false
|
56
70
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
71
|
requirements:
|
59
|
-
- -
|
72
|
+
- - ">="
|
60
73
|
- !ruby/object:Gem::Version
|
61
|
-
version: 0.
|
74
|
+
version: 0.9.2
|
62
75
|
- !ruby/object:Gem::Dependency
|
63
|
-
name:
|
76
|
+
name: test-unit
|
64
77
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
78
|
requirements:
|
67
|
-
- -
|
79
|
+
- - ">"
|
68
80
|
- !ruby/object:Gem::Version
|
69
|
-
version:
|
81
|
+
version: '3.1'
|
70
82
|
type: :development
|
71
83
|
prerelease: false
|
72
84
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
85
|
requirements:
|
75
|
-
- -
|
86
|
+
- - ">"
|
76
87
|
- !ruby/object:Gem::Version
|
77
|
-
version:
|
88
|
+
version: '3.1'
|
78
89
|
description: nats plugin for fluentd, an event collector
|
79
90
|
email:
|
80
91
|
- achied@gmail.com
|
@@ -82,40 +93,38 @@ executables: []
|
|
82
93
|
extensions: []
|
83
94
|
extra_rdoc_files: []
|
84
95
|
files:
|
85
|
-
- .gitignore
|
86
|
-
- .travis.yml
|
96
|
+
- ".gitignore"
|
97
|
+
- ".travis.yml"
|
87
98
|
- COPYING
|
88
99
|
- Gemfile
|
89
|
-
- Gemfile.lock
|
90
100
|
- README.md
|
91
101
|
- Rakefile
|
92
|
-
- VERSION
|
93
102
|
- fluent-plugin-nats.gemspec
|
94
103
|
- lib/fluent/plugin/in_nats.rb
|
95
|
-
- test/
|
104
|
+
- test/nats-publish-message.rb
|
105
|
+
- test/plugin/test_in_nats.rb
|
96
106
|
- test/test_helper.rb
|
97
107
|
homepage: https://github.com/achied/fluent-plugin-nats
|
98
108
|
licenses: []
|
109
|
+
metadata: {}
|
99
110
|
post_install_message:
|
100
111
|
rdoc_options: []
|
101
112
|
require_paths:
|
102
113
|
- lib
|
103
114
|
required_ruby_version: !ruby/object:Gem::Requirement
|
104
|
-
none: false
|
105
115
|
requirements:
|
106
|
-
- -
|
116
|
+
- - ">="
|
107
117
|
- !ruby/object:Gem::Version
|
108
118
|
version: '0'
|
109
119
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
|
-
none: false
|
111
120
|
requirements:
|
112
|
-
- -
|
121
|
+
- - ">="
|
113
122
|
- !ruby/object:Gem::Version
|
114
123
|
version: '0'
|
115
124
|
requirements: []
|
116
125
|
rubyforge_project:
|
117
|
-
rubygems_version:
|
126
|
+
rubygems_version: 2.6.13
|
118
127
|
signing_key:
|
119
|
-
specification_version:
|
128
|
+
specification_version: 4
|
120
129
|
summary: nats plugin for fluentd, an event collector
|
121
130
|
test_files: []
|
data/Gemfile.lock
DELETED
@@ -1,45 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
fluent-plugin-nats (0.0.5)
|
5
|
-
eventmachine (= 0.12.10)
|
6
|
-
fluentd (>= 0.10.7)
|
7
|
-
nats (>= 0.4.22)
|
8
|
-
|
9
|
-
GEM
|
10
|
-
remote: https://rubygems.org/
|
11
|
-
specs:
|
12
|
-
cool.io (1.1.0)
|
13
|
-
iobuffer (>= 1.0.0)
|
14
|
-
daemons (1.1.9)
|
15
|
-
eventmachine (0.12.10)
|
16
|
-
fluentd (0.10.28)
|
17
|
-
cool.io (~> 1.1.0)
|
18
|
-
http_parser.rb (~> 0.5.1)
|
19
|
-
json (>= 1.4.3)
|
20
|
-
msgpack (~> 0.4.4)
|
21
|
-
yajl-ruby (~> 1.0)
|
22
|
-
http_parser.rb (0.5.3)
|
23
|
-
iobuffer (1.1.2)
|
24
|
-
json (1.7.5)
|
25
|
-
json_pure (1.7.5)
|
26
|
-
msgpack (0.4.7)
|
27
|
-
nats (0.4.28)
|
28
|
-
daemons (>= 1.1.5)
|
29
|
-
eventmachine (= 0.12.10)
|
30
|
-
json_pure (>= 1.7.3)
|
31
|
-
thin (>= 1.4.1)
|
32
|
-
rack (1.4.1)
|
33
|
-
rake (0.9.2.2)
|
34
|
-
thin (1.4.1)
|
35
|
-
daemons (>= 1.0.9)
|
36
|
-
eventmachine (>= 0.12.6)
|
37
|
-
rack (>= 1.0.0)
|
38
|
-
yajl-ruby (1.1.0)
|
39
|
-
|
40
|
-
PLATFORMS
|
41
|
-
ruby
|
42
|
-
|
43
|
-
DEPENDENCIES
|
44
|
-
fluent-plugin-nats!
|
45
|
-
rake (>= 0.9.2)
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
0.0.5
|
data/test/plugin/in_nats.rb
DELETED
@@ -1,223 +0,0 @@
|
|
1
|
-
require 'test/unit'
|
2
|
-
require 'fluent/test'
|
3
|
-
require 'lib/fluent/plugin/in_nats.rb'
|
4
|
-
require 'nats/client'
|
5
|
-
require 'test_helper'
|
6
|
-
|
7
|
-
class NATSInputTest < Test::Unit::TestCase
|
8
|
-
include NATSTestHelper
|
9
|
-
|
10
|
-
CONFIG = %[
|
11
|
-
port 4222
|
12
|
-
host localhost
|
13
|
-
user nats
|
14
|
-
password nats
|
15
|
-
]
|
16
|
-
|
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
|
-
|
35
|
-
def create_driver(conf=CONFIG)
|
36
|
-
Fluent::Test::InputTestDriver.new(Fluent::NATSInput).configure(conf)
|
37
|
-
end
|
38
|
-
|
39
|
-
def test_configure_basic
|
40
|
-
d = create_driver basic_queue_conf
|
41
|
-
assert_equal 4222, d.instance.port
|
42
|
-
assert_equal 'localhost', d.instance.host
|
43
|
-
assert_equal 'nats', d.instance.user
|
44
|
-
assert_equal 'nats', d.instance.password
|
45
|
-
assert_equal 'fluent.>', d.instance.queue
|
46
|
-
end
|
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
|
-
|
67
|
-
def test_emit_with_credentials
|
68
|
-
d = create_driver basic_queue_conf
|
69
|
-
|
70
|
-
time = Time.parse("2011-01-02 13:14:15 UTC").to_i
|
71
|
-
Fluent::Engine.now = time
|
72
|
-
|
73
|
-
d.expect_emit "nats.fluent.test1", time, {"message"=>'nats', "fluent_timestamp"=>time}
|
74
|
-
d.expect_emit "nats.fluent.test2", time, {"message"=>'nats', "fluent_timestamp"=>time}
|
75
|
-
|
76
|
-
uri = "nats://#{d.instance.user}:#{d.instance.password}@#{d.instance.host}:#{d.instance.port}"
|
77
|
-
|
78
|
-
start_nats(uri)
|
79
|
-
d.run do
|
80
|
-
d.expected_emits.each { |tag, time, record|
|
81
|
-
send(uri, tag[5..-1], record)
|
82
|
-
sleep 0.5
|
83
|
-
}
|
84
|
-
end
|
85
|
-
kill_nats
|
86
|
-
end
|
87
|
-
|
88
|
-
def test_emit_without_credentials
|
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
|
111
|
-
|
112
|
-
time = Time.parse("2011-01-02 13:14:15 UTC").to_i
|
113
|
-
Fluent::Engine.now = time
|
114
|
-
|
115
|
-
d.expect_emit "nats.fluent.test1", time, {"message"=>'nats', "fluent_timestamp"=>time}
|
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}
|
119
|
-
|
120
|
-
uri = "nats://#{d.instance.host}:#{d.instance.port}"
|
121
|
-
|
122
|
-
start_nats(uri)
|
123
|
-
d.run do
|
124
|
-
d.expected_emits.each { |tag, time, record|
|
125
|
-
send(uri, tag[5..-1], record)
|
126
|
-
sleep 0.5
|
127
|
-
}
|
128
|
-
end
|
129
|
-
kill_nats
|
130
|
-
end
|
131
|
-
|
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
|
-
|
210
|
-
def setup
|
211
|
-
Fluent::Test.setup
|
212
|
-
end
|
213
|
-
|
214
|
-
def send(uri, tag, msg)
|
215
|
-
EM.run {
|
216
|
-
n = NATS.connect(:uri => uri)
|
217
|
-
n.publish(tag,msg.to_json)
|
218
|
-
n.close
|
219
|
-
}
|
220
|
-
end
|
221
|
-
end
|
222
|
-
|
223
|
-
|