fluent-plugin-keep-forward 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 89a30d749bd28ea0efcd3b12ef903907bfc18a8a
4
+ data.tar.gz: 85572acd2c42282174cc2cfee4e2289d49223c5c
5
+ SHA512:
6
+ metadata.gz: 520e8c13dac8aa2ea721cafc891d7a72fcd61edcda97fcdf2291fd1b9e39b98d8acb1fc3aa36d02b3f99b8710eb8eafc61e0668ae11769049bc8b994c6038493
7
+ data.tar.gz: 56f82fd672b9df9e2ff338660ceaca1ee283ca166bc5ec31284295e6d80eabe5a697b8e81c3719ecf302afb39a96ff8faf73b681b59d011e73128af4c823384a
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /*.gem
2
+ ~*
3
+ #*
4
+ *~
5
+ .bundle
6
+ Gemfile.lock
7
+ .rbenv-version
8
+ vendor
9
+ doc/*
10
+ tmp/*
11
+ .yardoc
data/.rdebugrc ADDED
@@ -0,0 +1,4 @@
1
+ set autolist
2
+ set autoeval
3
+ set autoreload
4
+
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --colour
2
+ --format documentation
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.0.0-p0
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ rvm:
2
+ - 1.9.2
3
+ - 1.9.3
4
+ - 2.0.0
5
+ gemfile:
6
+ - Gemfile
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Naotoshi SEO
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,32 @@
1
+ # fluent-plugin-keep-forward [![Build Status](https://secure.travis-ci.org/sonots/fluent-plugin-keep-forward.png?branch=master)](http://travis-ci.org/sonots/fluent-plugin-keep-forward) [![Dependency Status](https://gemnasium.com/sonots/fluent-plugin-keep-forward.png)](https://gemnasium.com/sonots/fluent-plugin-keep-forward)
2
+
3
+ testing ruby: 1.9.2, 1.9.3, 2.0.0; fluentd: 0.10.x
4
+
5
+ ## About
6
+
7
+ This is an extension of fluentd out\_forward plugin to keep fowarding log data to the same node (as much as possible).
8
+
9
+ ## Configuration
10
+
11
+ Exactly same with out\_forward plugin. See http://docs.fluentd.org/articles/out_forward
12
+
13
+ ## Log
14
+
15
+ This plugin outputs log messages like
16
+
17
+ $ grep 'keep forwarding' /var/log/td-agent/td-agent.log
18
+ 2013-03-15 10:35:06 +0900: keep forwarding tag 'fluent.info' to node 'localhost:24224' host="localhost" port=24224 weight=60
19
+
20
+ You can tell the address of forwarding node easily.
21
+
22
+ ## Contributing
23
+
24
+ 1. Fork it
25
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
26
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
27
+ 4. Push to the branch (`git push origin my-new-feature`)
28
+ 5. Create new [Pull Request](../../pull/new/master)
29
+
30
+ ## Copyright
31
+
32
+ Copyright (c) 2013 Naotoshi SEO. See [LICENSE](LICENSE) for details.
data/Rakefile ADDED
@@ -0,0 +1,15 @@
1
+ # encoding: utf-8
2
+ require "bundler/gem_tasks"
3
+
4
+ require 'rspec/core'
5
+ require 'rspec/core/rake_task'
6
+ RSpec::Core::RakeTask.new(:spec) do |spec|
7
+ spec.pattern = FileList['spec/**/*_spec.rb']
8
+ end
9
+ task :default => :spec
10
+
11
+ desc 'Open an irb session preloaded with the gem library'
12
+ task :console do
13
+ sh 'irb -rubygems -I lib'
14
+ end
15
+ task :c => :console
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "fluent-plugin-keep-forward"
6
+ s.version = "0.0.1"
7
+ s.authors = ["Naotoshi SEO"]
8
+ s.email = ["sonots@gmail.com"]
9
+ s.homepage = "https://github.com/sonots/fluent-plugin-keep-forward"
10
+ s.summary = "out_foward extension to keep forwarding to a node"
11
+ s.description = s.summary
12
+
13
+ s.rubyforge_project = "fluent-plugin-keep-forward"
14
+
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ s.require_paths = ["lib"]
19
+
20
+ s.add_runtime_dependency "fluentd"
21
+ s.add_development_dependency "rake"
22
+ s.add_development_dependency "rspec"
23
+ s.add_development_dependency "pry"
24
+ end
@@ -0,0 +1,49 @@
1
+ require 'fluent/plugin/out_forward'
2
+
3
+ class Fluent::KeepForwardOutput < Fluent::ForwardOutput
4
+ Fluent::Plugin.register_output('keep_forward', self)
5
+
6
+ def write_objects(tag, es)
7
+ @node ||= {}
8
+ if @node[tag] and @node[tag].available? and @weight_array.include?(@node[tag])
9
+ begin
10
+ send_data(@node[tag], tag, es)
11
+ return
12
+ rescue
13
+ weight_send_data(tag, es)
14
+ end
15
+ else
16
+ weight_send_data(tag, es)
17
+ end
18
+ end
19
+
20
+ def weight_send_data(tag, es)
21
+ error = nil
22
+
23
+ wlen = @weight_array.length
24
+ wlen.times do
25
+ @rr = (@rr + 1) % wlen
26
+ node = @weight_array[@rr]
27
+
28
+ if node.available?
29
+ begin
30
+ send_data(node, tag, es)
31
+ @node[tag] = node
32
+ $log.info "keep forwarding tag '#{tag}' to node '#{node.name}'", :host=>node.host, :port=>node.port, :weight=>node.weight
33
+ return
34
+ rescue
35
+ # for load balancing during detecting crashed servers
36
+ error = $! # use the latest error
37
+ end
38
+ end
39
+ end
40
+
41
+ @node[tag] = nil
42
+ $log.info "keep forwarding tag '#{tag}' is lost"
43
+ if error
44
+ raise error
45
+ else
46
+ raise "no nodes are available" # TODO message
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,64 @@
1
+ # encoding: UTF-8
2
+ require_relative 'spec_helper'
3
+
4
+ shared_context 'keep_forward_init' do
5
+ before { Fluent::Test.setup }
6
+ CONFIG = %[
7
+ <server>
8
+ host localhost
9
+ port 24224
10
+ </server>
11
+ <server>
12
+ host localhost
13
+ port 24225
14
+ </server>
15
+ ]
16
+ let(:tag) { 'syslog.host1' }
17
+ let(:es) { Object.new }
18
+ let(:driver) { Fluent::Test::OutputTestDriver.new(Fluent::KeepForwardOutput, tag).configure(CONFIG).instance }
19
+ end
20
+
21
+ shared_context 'keep_forward_try_once' do
22
+ before do
23
+ # simpler version of Fluent::ForwardOutput#start method
24
+ driver.instance_variable_set(:@rand_seed, Random.new.seed)
25
+ driver.send(:rebuild_weight_array)
26
+ driver.instance_variable_set(:@rr, 0)
27
+ # try send once to cache keep_node
28
+ driver.stub(:send_data) # stub
29
+ driver.write_objects(tag, es)
30
+ end
31
+ let!(:keep_node) { driver.instance_variable_get(:@node)[tag] }
32
+ let!(:unkeep_node) { (driver.instance_variable_get(:@nodes) - [keep_node]).first }
33
+ end
34
+
35
+ describe Fluent::KeepForwardOutput do
36
+ include_context 'keep_forward_init'
37
+ include_context 'keep_forward_try_once'
38
+
39
+ describe 'keep forwarding if no problem?' do
40
+ before { driver.should_receive(:send_data).with(keep_node, tag, es) }
41
+ it { driver.write_objects(tag, es) }
42
+ end
43
+
44
+ describe 'switch if not available?' do
45
+ before { keep_node.available = false }
46
+
47
+ before { driver.should_receive(:send_data).with(unkeep_node, tag, es) }
48
+ it { driver.write_objects(tag, es) }
49
+ end
50
+
51
+ describe 'switch if not included in weight_array?' do
52
+ before { driver.instance_variable_set(:@weight_array, [unkeep_node]) }
53
+
54
+ before { driver.should_receive(:send_data).with(unkeep_node, tag, es) }
55
+ it { driver.write_objects(tag, es) }
56
+ end
57
+
58
+ describe 'switch if send_data to keep_node raises?' do
59
+ before { driver.stub(:send_data).with(keep_node, tag, es).and_raise(StandardError) }
60
+
61
+ before { driver.should_receive(:send_data).with(unkeep_node, tag, es) }
62
+ it { driver.write_objects(tag, es) }
63
+ end
64
+ end
@@ -0,0 +1,13 @@
1
+ # encoding: UTF-8
2
+ require 'rubygems'
3
+ require 'bundler'
4
+ Bundler.setup(:default, :test)
5
+ Bundler.require(:default, :test)
6
+
7
+ require 'fluent/test'
8
+ require 'rspec'
9
+ require 'pry'
10
+
11
+ $TESTING=true
12
+ $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
13
+ require 'fluent/plugin/out_keep_forward'
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-keep-forward
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Naotoshi SEO
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-03-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: fluentd
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: out_foward extension to keep forwarding to a node
70
+ email:
71
+ - sonots@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - .gitignore
77
+ - .rdebugrc
78
+ - .rspec
79
+ - .ruby-version
80
+ - .travis.yml
81
+ - Gemfile
82
+ - LICENSE
83
+ - README.md
84
+ - Rakefile
85
+ - fluent-plugin-keep-forward.gemspec
86
+ - lib/fluent/plugin/out_keep_forward.rb
87
+ - spec/out_keep_forward_spec.rb
88
+ - spec/spec_helper.rb
89
+ homepage: https://github.com/sonots/fluent-plugin-keep-forward
90
+ licenses: []
91
+ metadata: {}
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - '>='
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - '>='
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubyforge_project: fluent-plugin-keep-forward
108
+ rubygems_version: 2.0.0
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: out_foward extension to keep forwarding to a node
112
+ test_files:
113
+ - spec/out_keep_forward_spec.rb
114
+ - spec/spec_helper.rb