fluent-plugin-delayed 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1 @@
1
+ pkg
data/AUTHORS ADDED
@@ -0,0 +1 @@
1
+ Shuhei Tanuma <chobieee _at_ gmail.com>
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in fluent-plugin-delayed.gemspec
4
+ gemspec
@@ -0,0 +1,35 @@
1
+ = Delayed output plugin for Fluent event collector
2
+
3
+ == Architecture
4
+
5
+ if events has future time. it will be delayed insert.
6
+ Basically, we don't have to modify event time. delayed insert
7
+ looks very useful in some cases. imagine it!
8
+
9
+ now: 2011-10-22 10:00:00
10
+ |
11
+ event{
12
+ time: 2011-10-22 10:00:05, # 5 seconds future
13
+ ...
14
+ }
15
+ |
16
+ [fluentd-delayed-output]
17
+ waiting 5 seconds
18
+ (Coolio buffering events and fire when specified time has come.)
19
+ |
20
+ [emit the event]
21
+
22
+ == Restrictions
23
+
24
+ this plugin targets easily implementation.
25
+ it has a risk of disappear events if you specify long delay time.
26
+
27
+ == Quick Start
28
+
29
+ $ rake build
30
+ $ gem install pkg/fluent-plugin-delayed-0.0.1.gem
31
+
32
+ Source repository:: http://github.com/chobie/fluent-plugin-delayed
33
+ Author:: Shuhei Tanuma
34
+ Copyright:: (c) 2011 Shuhei Tanuma
35
+ License:: Apache License, Version 2.0
@@ -0,0 +1,12 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'bundler'
4
+ Bundler::GemHelper.install_tasks
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.test_files = Dir['test/plugin/*.rb']
8
+ t.ruby_opts = ['-rubygems'] if defined? Gem
9
+ t.ruby_opts << '-I.'
10
+ end
11
+
12
+ task :default => [:build]
@@ -0,0 +1,13 @@
1
+ # Memcached input
2
+ <source>
3
+ type tcp
4
+ port 24224
5
+ </source>
6
+
7
+ # match tag=debug.** and dump to console
8
+ <match debug.**>
9
+ type delayed
10
+ <store>
11
+ type stdout
12
+ </store>
13
+ </match>
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "fluent/plugin/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "fluent-plugin-delayed"
7
+ s.version = Fluent::Plugin::Delayed::VERSION
8
+ s.authors = ["Shuhei Tanuma"]
9
+ s.email = ["chobieee@gmail.com"]
10
+ s.homepage = "http://github.com/chobie/fluent-plugin-delayed"
11
+ s.summary = %q{Delayed output plugin for Fluent event collector}
12
+ s.description = %q{Delayed output plugin for Fluent event collector}
13
+
14
+ s.rubyforge_project = "fluent-plugin-delayed"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ # s.add_development_dependency "rspec"
23
+ # s.add_runtime_dependency "rest-client"
24
+ end
@@ -0,0 +1,73 @@
1
+ #
2
+ # Fluent-Plugin-Delayed
3
+ #
4
+ # Copyright (C) 2011 Shuhei Tanuma
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+ module Fluent
19
+
20
+ class DelayedEvent < ::Coolio::TimerWatcher
21
+ def initialize(tag, event, chain,output, delay)
22
+ super(delay, false)
23
+ @tag = tag
24
+ @event = event
25
+ @output = output
26
+ @chain = chain
27
+ end
28
+
29
+ def on_timer
30
+ @output.emit(@tag, @event, @chain)
31
+ detach
32
+ end
33
+ end
34
+
35
+ class DelayedOutput < Output
36
+ Plugin.register_output('delayed',self)
37
+
38
+ def initialize()
39
+ @coolio = Coolio::Loop.default
40
+ @thread = Thread.new(&method(:run))
41
+ end
42
+
43
+ def configure(conf)
44
+ conf.elements.select {|e|
45
+ e.name == 'store'
46
+ }.each {|e|
47
+ type = e['type']
48
+ @output = Plugin.new_output(type)
49
+ }
50
+ end
51
+
52
+ def emit(tag, es, chain)
53
+ es.each {|time,record|
54
+ now = Engine.now
55
+ delay = time - now
56
+
57
+ if delay < 0 then
58
+ delay = 0
59
+ end
60
+ es2 = MultiEventStream.new
61
+ es2.add(time,record)
62
+
63
+ @coolio.attach DelayedEvent.new(tag, es2, chain, @output, delay)
64
+ }
65
+ end
66
+
67
+ private
68
+ def run
69
+ @coolio.run
70
+ end
71
+ end
72
+
73
+ end
@@ -0,0 +1,7 @@
1
+ module Fluent
2
+ module Plugin
3
+ module Delayed
4
+ VERSION = "0.0.1"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,40 @@
1
+ require 'pp'
2
+ require 'test/unit'
3
+ require 'fluent/test'
4
+ require 'fluent/plugin/out_delayed'
5
+
6
+ class DealyedOutputTest < Test::Unit::TestCase
7
+ def setup
8
+ Fluent::Test.setup
9
+ end
10
+
11
+ CONFIG = %[
12
+ type delayed
13
+ ]
14
+
15
+ def create_driver(conf=CONFIG)
16
+ Fluent::Test::OutputTestDriver.new(Fluent::DelayedOutput).configure(conf)
17
+ end
18
+
19
+ def test_configure
20
+ d = create_driver
21
+ end
22
+
23
+ def test_delayed
24
+ d = create_driver
25
+
26
+ time = Time.parse("2011-01-02 13:14:15 UTC").to_i
27
+ Fluent::Engine.now = time
28
+
29
+ # Todo: i'm not sure how does these lines work. let me look around these if i have a chance.
30
+ #
31
+ # d.expect_emit "tag1", time, {"message"=>"hello"}
32
+ #
33
+ # d.run do
34
+ # d.expected_emits.each { |tag, time, record|
35
+ # assert_equal tag, "tag1"
36
+ # }
37
+ # end
38
+ end
39
+
40
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-delayed
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Shuhei Tanuma
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2011-10-31 00:00:00 +09:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Delayed output plugin for Fluent event collector
17
+ email:
18
+ - chobieee@gmail.com
19
+ executables: []
20
+
21
+ extensions: []
22
+
23
+ extra_rdoc_files: []
24
+
25
+ files:
26
+ - .gitignore
27
+ - AUTHORS
28
+ - Gemfile
29
+ - README.rdoc
30
+ - Rakefile
31
+ - example.conf
32
+ - fluent-plugin-delayed.gemspec
33
+ - lib/fluent/plugin/out_delayed.rb
34
+ - lib/fluent/plugin/version.rb
35
+ - test/plugin/out_delayed.rb
36
+ has_rdoc: true
37
+ homepage: http://github.com/chobie/fluent-plugin-delayed
38
+ licenses: []
39
+
40
+ post_install_message:
41
+ rdoc_options: []
42
+
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: "0"
50
+ version:
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: "0"
56
+ version:
57
+ requirements: []
58
+
59
+ rubyforge_project: fluent-plugin-delayed
60
+ rubygems_version: 1.3.5
61
+ signing_key:
62
+ specification_version: 3
63
+ summary: Delayed output plugin for Fluent event collector
64
+ test_files:
65
+ - test/plugin/out_delayed.rb