fluent-plugin-kestrel 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,20 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "shoulda", ">= 0"
10
+ gem "bundler", "~> 1.0.0"
11
+ gem "rdoc", "~> 3.12"
12
+ gem "jeweler", "~> 1.8.3"
13
+ gem "rcov", ">= 0" if RUBY_VERSION < "1.9.0"
14
+ gem "simplecov", ">= 0.3.5", :require => false if RUBY_VERSION >= "1.9.0"
15
+ gem "simplecov-rcov", ">= 0" if RUBY_VERSION >= "1.9.0"
16
+ end
17
+
18
+ gem "kestrel-client", ">= 0.7.1"
19
+ gem "fluentd", ">= 0.10.10"
20
+
data/LICENSE.txt ADDED
@@ -0,0 +1,15 @@
1
+ This software is licensed under the Apache 2 license, quoted below.
2
+
3
+ Copyright (c) 2012 Junichiro Takagi <t.junichiro@gmail.com>
4
+
5
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not
6
+ use this file except in compliance with the License. You may obtain a copy of
7
+ the License at
8
+
9
+ http://www.apache.org/licenses/LICENSE-2.0
10
+
11
+ Unless required by applicable law or agreed to in writing, software
12
+ distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13
+ WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14
+ License for the specific language governing permissions and limitations under
15
+ the License.
data/README.rdoc ADDED
@@ -0,0 +1,37 @@
1
+ = fluent-plugin-kestrel
2
+
3
+ fluentd output plugin for kestrel.
4
+
5
+ fluentd is an event collector system.
6
+ see https://github.com/fluent/fluentd
7
+
8
+ kestrel is a simple, distributed message queue.
9
+ see https://github.com/robey/kestrel
10
+
11
+ == Fluentd Configuration
12
+
13
+ <match kestrel.**>
14
+ type kestrel
15
+
16
+ host localhost # kestrel host (required)
17
+ queue test # queue name of kestrel (required)
18
+
19
+ port 22133 # optional, default 22133
20
+ </match>
21
+
22
+
23
+ == Contributing to fluent-plugin-kestrel
24
+
25
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
26
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
27
+ * Fork the project.
28
+ * Start a feature/bugfix branch.
29
+ * Commit and push until you are happy with your contribution.
30
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
31
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
32
+
33
+ == Copyright
34
+
35
+ Copyright (c) 2012 Junichiro Takagi. See LICENSE.txt for
36
+ further details.
37
+
data/Rakefile ADDED
@@ -0,0 +1,60 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "fluent-plugin-kestrel"
18
+ gem.homepage = "http://github.com/tjun/fluent-plugin-kestrel"
19
+ gem.license = "Apache License, Version 2.0"
20
+ gem.summary = %Q{fluentd output plugin for kestrel.}
21
+ gem.description = %Q{fluentd output plugin for kestrel queue.}
22
+ gem.email = "t.junichiro@gmail.com"
23
+ gem.authors = ["Junichiro Takagi"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rake/testtask'
29
+ Rake::TestTask.new(:test) do |test|
30
+ test.libs << 'lib' << 'test'
31
+ test.pattern = 'test/**/test_*.rb'
32
+ test.verbose = true
33
+ end
34
+
35
+ if RUBY_VERSION =~ /^1\.8/
36
+ require 'rcov/rcovtask'
37
+ Rcov::RcovTask.new do |test|
38
+ test.libs << 'test'
39
+ test.pattern = 'test/**/test_*.rb'
40
+ test.verbose = true
41
+ test.rcov_opts << '--exclude "gems/*"'
42
+ end
43
+ else
44
+ require 'simplecov'
45
+ SimpleCov.start do
46
+ add_filter '_test'
47
+ end
48
+ end
49
+
50
+ task :default => :test
51
+
52
+ require 'rdoc/task'
53
+ Rake::RDocTask.new do |rdoc|
54
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
55
+
56
+ rdoc.rdoc_dir = 'rdoc'
57
+ rdoc.title = "fluent-plugin-kestrel #{version}"
58
+ rdoc.rdoc_files.include('README*')
59
+ rdoc.rdoc_files.include('lib/**/*.rb')
60
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,70 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "fluent-plugin-kestrel"
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Junichiro Takagi"]
12
+ s.date = "2012-02-11"
13
+ s.description = "fluentd output plugin for kestrel queue."
14
+ s.email = "t.junichiro@gmail.com"
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ "Gemfile",
22
+ "LICENSE.txt",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "fluent-plugin-kestrel.gemspec",
27
+ "lib/fluent/plugin/out_kestrel.rb",
28
+ "test/helper.rb",
29
+ "test/plugin/test_out_kestrel.rb"
30
+ ]
31
+ s.homepage = "http://github.com/tjun/fluent-plugin-kestrel"
32
+ s.licenses = ["Apache License, Version 2.0"]
33
+ s.require_paths = ["lib"]
34
+ s.rubygems_version = "1.8.15"
35
+ s.summary = "fluentd output plugin for kestrel."
36
+
37
+ if s.respond_to? :specification_version then
38
+ s.specification_version = 3
39
+
40
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
41
+ s.add_runtime_dependency(%q<kestrel-client>, [">= 0.7.1"])
42
+ s.add_runtime_dependency(%q<fluentd>, [">= 0.10.10"])
43
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
44
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
45
+ s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
46
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.3"])
47
+ s.add_development_dependency(%q<simplecov>, [">= 0.3.5"])
48
+ s.add_development_dependency(%q<simplecov-rcov>, [">= 0"])
49
+ else
50
+ s.add_dependency(%q<kestrel-client>, [">= 0.7.1"])
51
+ s.add_dependency(%q<fluentd>, [">= 0.10.10"])
52
+ s.add_dependency(%q<shoulda>, [">= 0"])
53
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
54
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
55
+ s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
56
+ s.add_dependency(%q<simplecov>, [">= 0.3.5"])
57
+ s.add_dependency(%q<simplecov-rcov>, [">= 0"])
58
+ end
59
+ else
60
+ s.add_dependency(%q<kestrel-client>, [">= 0.7.1"])
61
+ s.add_dependency(%q<fluentd>, [">= 0.10.10"])
62
+ s.add_dependency(%q<shoulda>, [">= 0"])
63
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
64
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
65
+ s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
66
+ s.add_dependency(%q<simplecov>, [">= 0.3.5"])
67
+ s.add_dependency(%q<simplecov-rcov>, [">= 0"])
68
+ end
69
+ end
70
+
@@ -0,0 +1,59 @@
1
+ module Fluent
2
+ class KestrelOutput < BufferedOutput
3
+ Fluent::Plugin.register_output('kestrel', self)
4
+ attr_reader :kestrel
5
+
6
+ config_param :host, :string, :default => nil
7
+ config_param :port, :integer, :default => 22133
8
+ config_param :queue, :string, :default => nil
9
+ config_param :ttl, :integer, :default => 0
10
+ config_param :raw, :bool, :default => false
11
+ config_param :time_format, :string, :default => nil
12
+
13
+
14
+
15
+ def initialize
16
+ super
17
+ require 'kestrel'
18
+ require 'time'
19
+ end
20
+
21
+ def configure(conf)
22
+ super
23
+
24
+ unless @queue && @host
25
+ raise ConfigError, "[kestrel config error]:'host' and 'queue' parameter must be specified."
26
+ end
27
+ @timef = TimeFormatter.new(@time_format, @localtime)
28
+ end
29
+
30
+ def start
31
+ super
32
+
33
+ @kestrel = Kestrel::Client.new(@host + ":" + @port.to_s)
34
+ end
35
+
36
+ def shutdown
37
+ super
38
+ end
39
+
40
+ def format(tag, time, record)
41
+ [tag, time, record].to_msgpack
42
+ end
43
+
44
+ def write(chunk)
45
+ chunk.open { |io|
46
+ begin
47
+ MessagePack::Unpacker.new(io).each{ |tag, time, record|
48
+ time_str = @timef.format(time)
49
+ data = "#{time_str}\t#{tag}\t#{record.to_json}"
50
+
51
+ @kestrel.set(@queue, data, ttl=@ttl, raw=@raw)
52
+ }
53
+ rescue EOFError
54
+ # EOFError always occured when reached end of chunk.
55
+ end
56
+ }
57
+ end
58
+ end
59
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,27 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+ require 'shoulda'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'fluent/test'
16
+ require 'fluent/plugin/out_kestrel'
17
+
18
+ class Test::Unit::TestCase
19
+ end
20
+
21
+ if ENV['SIMPLE_COV']
22
+ require 'simplecov'
23
+ SimpleCov.start do
24
+ add_filter 'test/'
25
+ add_filter 'pkg/'
26
+ end
27
+ end
@@ -0,0 +1,58 @@
1
+ require 'helper'
2
+
3
+ class TestFluentPluginKestrel < Test::Unit::TestCase
4
+ def setup
5
+ Fluent::Test.setup
6
+ require 'fluent/plugin/out_kestrel'
7
+ end
8
+
9
+ CONFIG = %[
10
+ type kestrel
11
+ host localhost
12
+ port 22133
13
+ queue test
14
+ ]
15
+
16
+ def create_driver(conf = CONFIG)
17
+ Fluent::Test::BufferedOutputTestDriver.new(Fluent::KestrelOutput).configure(conf)
18
+ end
19
+
20
+ def test_configure
21
+ d = create_driver(%[
22
+ type kestrel
23
+ host localhost
24
+ port 22133
25
+ queue test
26
+ ])
27
+
28
+ assert_equal 'localhost', d.instance.host
29
+ assert_equal 22133, d.instance.port
30
+ assert_equal "test", d.instance.queue
31
+ end
32
+
33
+ def test_format
34
+ d = create_driver
35
+ time = Time.parse("2011-01-02 13:14:15 UTC").to_i
36
+
37
+ d.emit({"a"=>1}, time)
38
+ d.emit({"a"=>2}, time)
39
+ d.expect_format(["test", time, {"a"=>1}].to_msgpack)
40
+ d.expect_format(["test", time, {"a"=>2}].to_msgpack)
41
+ d.run
42
+ end
43
+
44
+ def test_write
45
+ d = create_driver
46
+ time = Time.parse("2011-01-02 13:14:15 UTC").to_i
47
+
48
+ d.emit({"a"=>3}, time)
49
+ d.run
50
+
51
+ assert_equal "2011-01-02T13:14:15Z\ttest\t{\"a\":1}", d.instance.kestrel.get("test")
52
+ assert_equal "2011-01-02T13:14:15Z\ttest\t{\"a\":2}", d.instance.kestrel.get("test")
53
+ assert_equal "2011-01-02T13:14:15Z\ttest\t{\"a\":3}", d.instance.kestrel.get("test")
54
+
55
+
56
+
57
+ end
58
+ end
metadata ADDED
@@ -0,0 +1,148 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-kestrel
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Junichiro Takagi
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-02-11 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: kestrel-client
16
+ requirement: &70152932627300 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 0.7.1
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70152932627300
25
+ - !ruby/object:Gem::Dependency
26
+ name: fluentd
27
+ requirement: &70152932624980 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: 0.10.10
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70152932624980
36
+ - !ruby/object:Gem::Dependency
37
+ name: shoulda
38
+ requirement: &70152932623080 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70152932623080
47
+ - !ruby/object:Gem::Dependency
48
+ name: bundler
49
+ requirement: &70152932621340 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 1.0.0
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70152932621340
58
+ - !ruby/object:Gem::Dependency
59
+ name: rdoc
60
+ requirement: &70152932619720 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ~>
64
+ - !ruby/object:Gem::Version
65
+ version: '3.12'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *70152932619720
69
+ - !ruby/object:Gem::Dependency
70
+ name: jeweler
71
+ requirement: &70152932617180 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ~>
75
+ - !ruby/object:Gem::Version
76
+ version: 1.8.3
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *70152932617180
80
+ - !ruby/object:Gem::Dependency
81
+ name: simplecov
82
+ requirement: &70152932615540 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: 0.3.5
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: *70152932615540
91
+ - !ruby/object:Gem::Dependency
92
+ name: simplecov-rcov
93
+ requirement: &70152932614040 !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ type: :development
100
+ prerelease: false
101
+ version_requirements: *70152932614040
102
+ description: fluentd output plugin for kestrel queue.
103
+ email: t.junichiro@gmail.com
104
+ executables: []
105
+ extensions: []
106
+ extra_rdoc_files:
107
+ - LICENSE.txt
108
+ - README.rdoc
109
+ files:
110
+ - .document
111
+ - Gemfile
112
+ - LICENSE.txt
113
+ - README.rdoc
114
+ - Rakefile
115
+ - VERSION
116
+ - fluent-plugin-kestrel.gemspec
117
+ - lib/fluent/plugin/out_kestrel.rb
118
+ - test/helper.rb
119
+ - test/plugin/test_out_kestrel.rb
120
+ homepage: http://github.com/tjun/fluent-plugin-kestrel
121
+ licenses:
122
+ - Apache License, Version 2.0
123
+ post_install_message:
124
+ rdoc_options: []
125
+ require_paths:
126
+ - lib
127
+ required_ruby_version: !ruby/object:Gem::Requirement
128
+ none: false
129
+ requirements:
130
+ - - ! '>='
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ segments:
134
+ - 0
135
+ hash: 391376077064872023
136
+ required_rubygems_version: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ requirements: []
143
+ rubyforge_project:
144
+ rubygems_version: 1.8.15
145
+ signing_key:
146
+ specification_version: 3
147
+ summary: fluentd output plugin for kestrel.
148
+ test_files: []