fluent-plugin-nats 1.0.0 → 1.1.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
- SHA1:
3
- metadata.gz: 37e3edf9206fe66e157aa2c2d8a0ae58e2f5d934
4
- data.tar.gz: 22a579e710b96489e1a29cb67f7982409a7f5b6e
2
+ SHA256:
3
+ metadata.gz: 52d1ac0b1fcd215901c291dfa34699e6d86eefdd35bcd33533f1dd5313f0d099
4
+ data.tar.gz: 86fb83fb117dad3a4504122ea426fefd59ddd756b65d1e88aaa0cb642ef255f3
5
5
  SHA512:
6
- metadata.gz: 20518c485938cf956976a732cfe8c3c64162834af602aac5dc0eb926c64942f9308933e8de083366aa22c25442122f8941abb14c48ec686fce587e0393e82215
7
- data.tar.gz: 5a6b040380c3787da130b05d3a5c9bf93bda73e4d112289d56744714d5d4ee4f5e245a05a60d98c9f81bcd9d549fe951ad8336a17e000f88c9623cf40661d88a
6
+ metadata.gz: 935af9de50cd0525c872e1918a2da8e3a4a3b63f7d65d704cb7fd7fa46ce78f69970107e99840c79a9fc2c3631490f71f5fc7dba93ef64c5c04ce4c4db49f7d4
7
+ data.tar.gz: 439200145ab53e23a9f33d2754d8930fc5076ab63a32b952a282f46bca37a38e8ad9b8444c1ea06a1d837112533534addda1fd37c11e4437f33dca7cceacc867
data/README.md CHANGED
@@ -4,7 +4,7 @@ fluent-plugin-nats
4
4
  [NATS](https://github.com/derekcollison/nats) plugin for
5
5
  [fluentd](https://github.com/fluent/fluentd) Event Collector
6
6
 
7
- [![Build Status](https://secure.travis-ci.org/achied/fluent-plugin-nats.png)](http://travis-ci.org/achied/fluent-plugin-nats)
7
+ [![Build Status](https://travis-ci.org/cloudfoundry-community/fluent-plugin-nats.svg?branch=master)](https://travis-ci.org/cloudfoundry-community/fluent-plugin-nats)
8
8
 
9
9
  ## Requirements
10
10
 
@@ -2,7 +2,7 @@ $:.push File.expand_path("../lib", __FILE__)
2
2
 
3
3
  Gem::Specification.new do |gem|
4
4
  gem.name = "fluent-plugin-nats"
5
- gem.version = "1.0.0"
5
+ gem.version = "1.1.0"
6
6
  gem.authors = ["Eduardo Aceituno"]
7
7
  gem.email = ["achied@gmail.com"]
8
8
  gem.homepage = "https://github.com/achied/fluent-plugin-nats"
@@ -16,7 +16,7 @@ Gem::Specification.new do |gem|
16
16
  gem.require_paths = ["lib"]
17
17
 
18
18
  gem.add_dependency "eventmachine", ">= 0.12.10"
19
- gem.add_dependency "fluentd", ">= 0.14.20"
19
+ gem.add_dependency "fluentd", ">= 0.14.20", "< 2"
20
20
  gem.add_dependency "nats", ">= 0.4.22"
21
21
 
22
22
  gem.add_development_dependency "rake", ">= 0.9.2"
@@ -10,12 +10,12 @@ module Fluent
10
10
 
11
11
  desc "NATS server hostname"
12
12
  config_param :host, :string, default: "localhost"
13
+ desc "NATS server port"
14
+ config_param :port, :integer, default: 4222
13
15
  desc "Username for authorized connection"
14
16
  config_param :user, :string, default: "nats"
15
17
  desc "Password for authorized connection"
16
18
  config_param :password, :string, default: "nats", secret: true
17
- desc "NATS server port"
18
- config_param :port, :integer, default: 4222
19
19
  desc "Subscribing queue names"
20
20
  config_param :queues, :array, default: ["fluent.>"]
21
21
  config_param :queue, :string, default: "fluent.>", obsoleted: "Use `queues` instead"
@@ -43,8 +43,9 @@ module Fluent
43
43
 
44
44
  def start
45
45
  super
46
- NATS.on_error do |error_message|
47
- log.error "Server Error: #{error_message}"
46
+ NATS.on_error do |error|
47
+ log.error "Server Error:", error: error
48
+ # supervisor will restart worker
48
49
  exit!
49
50
  end
50
51
  run_reactor_thread
@@ -0,0 +1,90 @@
1
+ require "fluent/plugin/output"
2
+ require "nats/client"
3
+
4
+ module Fluent
5
+ module Plugin
6
+ class NATSOutput < Fluent::Plugin::Output
7
+ Fluent::Plugin.register_output('nats', self)
8
+
9
+ helpers :formatter, :thread, :inject
10
+
11
+ DEFAULT_FORMAT_TYPE = 'json'
12
+
13
+ desc "NATS server hostname"
14
+ config_param :host, :string, default: "localhost"
15
+ desc "NATS server port"
16
+ config_param :port, :integer, default: 4222
17
+ desc "Username for authorized connection"
18
+ config_param :user, :string, default: "nats"
19
+ desc "Password for authorized connection"
20
+ config_param :password, :string, default: "nats", secret: true
21
+ desc "Enable secure SSL/TLS connection"
22
+ config_param :ssl, :bool, default: false
23
+ desc "The max number of reconnect tries"
24
+ config_param :max_reconnect_attempts, :integer, default: 150
25
+ desc "The number of seconds to wait between reconnect tries"
26
+ config_param :reconnect_time_wait, :integer, default: 2
27
+
28
+ config_section :format do
29
+ config_set_default :@type, DEFAULT_FORMAT_TYPE
30
+ config_set_default :add_newline, false
31
+ end
32
+
33
+ def multi_workers_ready?
34
+ true
35
+ end
36
+
37
+ attr_accessor :formatter
38
+
39
+ def configure(conf)
40
+ super
41
+
42
+ @nats_config = {
43
+ uri: "nats://#{@host}:#{@port}",
44
+ ssl: @ssl,
45
+ user: @user,
46
+ pass: @password,
47
+ reconnect_time_wait: @reconnect_time_wait,
48
+ max_reconnect_attempts: @max_reconnect_attempts,
49
+ }
50
+ @formatter = formatter_create
51
+ end
52
+
53
+ def start
54
+ super
55
+ thread_create(:nats_output_main, &method(:run))
56
+ end
57
+
58
+ def shutdown
59
+ EM.next_tick do
60
+ NATS.stop
61
+ end
62
+ super
63
+ end
64
+
65
+ def run
66
+ NATS.on_error do |error|
67
+ log.error "Server Error:", error: error
68
+ # supervisor will restart worker
69
+ exit!
70
+ end
71
+ NATS.start(@nats_config) do
72
+ log.info "nats client is running for #{@nats_config[:uri]}"
73
+ end
74
+ end
75
+
76
+ def process(tag, es)
77
+ es = inject_values_to_event_stream(tag, es)
78
+ es.each do |time,record|
79
+ EM.next_tick do
80
+ NATS.publish(tag, format(tag, time, record))
81
+ end
82
+ end
83
+ end
84
+
85
+ def format(tag, time, record)
86
+ @formatter.format(tag, time, record)
87
+ end
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,80 @@
1
+ require "test_helper"
2
+ require "fluent/test/driver/output"
3
+ require "fluent/test/driver/input"
4
+ require "fluent/plugin/out_nats"
5
+ require "fluent/plugin/in_nats"
6
+ require "fluent/time"
7
+
8
+ class NATSOutputTest < Test::Unit::TestCase
9
+ include NATSTestHelper
10
+
11
+ CONFIG = %[
12
+ port 4222
13
+ host localhost
14
+ user nats
15
+ password nats
16
+ ]
17
+
18
+ CONFIG_INPUT = CONFIG + %[
19
+ queues test.>
20
+ tag nats
21
+ ]
22
+
23
+ def create_driver(conf)
24
+ Fluent::Test::Driver::Output.new(Fluent::Plugin::NATSOutput).configure(conf)
25
+ end
26
+
27
+ def create_input_driver(conf)
28
+ Fluent::Test::Driver::Input.new(Fluent::Plugin::NATSInput).configure(conf)
29
+ end
30
+
31
+ def setup
32
+ Fluent::Test.setup
33
+ @time = Time.parse("2011-01-02 13:14:15 UTC")
34
+ Timecop.freeze(@time)
35
+ end
36
+
37
+ def teardown
38
+ Timecop.return
39
+ end
40
+
41
+ test "configuration test" do
42
+ d = create_driver(CONFIG)
43
+ assert_equal 4222, d.instance.port
44
+ assert_equal "localhost", d.instance.host
45
+ assert_equal "nats", d.instance.user
46
+ assert_equal "nats", d.instance.password
47
+ end
48
+
49
+ test "publish an event to NATS" do
50
+ d = create_driver(CONFIG)
51
+ input_driver = create_input_driver(CONFIG_INPUT)
52
+
53
+ time = Fluent::EventTime.now
54
+
55
+ uri = generate_uri(d)
56
+
57
+ run_server(uri) do
58
+ input_driver.run(expect_records: 1) do
59
+ d.run(default_tag: 'test.log') do
60
+ d.feed(time, {"test" => "test1"})
61
+ end
62
+ end
63
+ end
64
+ event = input_driver.events[0]
65
+ assert_equal(event[0], 'nats.test.log')
66
+ assert_equal(event[2], {"test" => "test1"})
67
+ end
68
+
69
+ def generate_uri(driver)
70
+ user = driver.instance.user
71
+ pass = driver.instance.password
72
+ host = driver.instance.host
73
+ port = driver.instance.port
74
+ if user && pass
75
+ "nats://#{user}:#{pass}@#{host}:#{port}"
76
+ else
77
+ "nats://#{host}:#{port}"
78
+ end
79
+ end
80
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-nats
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
  - Eduardo Aceituno
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-26 00:00:00.000000000 Z
11
+ date: 2018-04-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: eventmachine
@@ -31,6 +31,9 @@ dependencies:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: 0.14.20
34
+ - - "<"
35
+ - !ruby/object:Gem::Version
36
+ version: '2'
34
37
  type: :runtime
35
38
  prerelease: false
36
39
  version_requirements: !ruby/object:Gem::Requirement
@@ -38,6 +41,9 @@ dependencies:
38
41
  - - ">="
39
42
  - !ruby/object:Gem::Version
40
43
  version: 0.14.20
44
+ - - "<"
45
+ - !ruby/object:Gem::Version
46
+ version: '2'
41
47
  - !ruby/object:Gem::Dependency
42
48
  name: nats
43
49
  requirement: !ruby/object:Gem::Requirement
@@ -109,8 +115,10 @@ files:
109
115
  - Rakefile
110
116
  - fluent-plugin-nats.gemspec
111
117
  - lib/fluent/plugin/in_nats.rb
118
+ - lib/fluent/plugin/out_nats.rb
112
119
  - test/nats-publish-message.rb
113
120
  - test/plugin/test_in_nats.rb
121
+ - test/plugin/test_out_nats.rb
114
122
  - test/test_helper.rb
115
123
  homepage: https://github.com/achied/fluent-plugin-nats
116
124
  licenses:
@@ -132,7 +140,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
132
140
  version: '0'
133
141
  requirements: []
134
142
  rubyforge_project:
135
- rubygems_version: 2.6.13
143
+ rubygems_version: 2.7.3
136
144
  signing_key:
137
145
  specification_version: 4
138
146
  summary: nats plugin for fluentd, an event collector