fluent-plugin-redis-publish 0.1.0

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: ec7e3d8c690899c778abb6ba96d1d2d7dbba43b3
4
+ data.tar.gz: efc34e82e35a730d3a2f474eaa58ca8a6882a358
5
+ SHA512:
6
+ metadata.gz: 4bf95771ff284925132e344df4450eed8964d1848a6ccfea226c77820c69b56f33eb0b72a3c72c1bd1d56ba13e5dc91813ff919b2c448aea39ad56e1251424d0
7
+ data.tar.gz: e7ac1e6dadc2762899b6539d30503e694928f8ab40ea6db4e83c01fb7874e0b9f7144bd22ec69ff325ad686d6e7843438e8d86beed0994e4aedec36c6ccb716b
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fluent-plugin-redis-publish.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Daisuke Murase
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,29 @@
1
+ # Fluent::Plugin::Redis::Publish
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'fluent-plugin-redis-publish'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install fluent-plugin-redis-publish
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rake/testtask'
4
+ Rake::TestTask.new(:test) do |test|
5
+ test.libs << 'lib' << 'test'
6
+ test.pattern = 'test/**/test_*.rb'
7
+ test.verbose = true
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,18 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.name = "fluent-plugin-redis-publish"
6
+ gem.version = "0.1.0"
7
+ gem.authors = ["Daisuke Murase"]
8
+ gem.email = ["typester@cpan.org"]
9
+ gem.summary = "fluent output plugin publishing logs to redis pub/sub"
10
+ gem.homepage = "https://github.com/typester/fluent-plugin-redis-publish"
11
+
12
+ gem.files = `git ls-files`.split($/)
13
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
14
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
15
+ gem.require_paths = ["lib"]
16
+ gem.add_dependency "fluentd"
17
+ gem.add_dependency "redis"
18
+ end
@@ -0,0 +1,56 @@
1
+ module Fluent
2
+ class RedisPublishOutput < Fluent::BufferedOutput
3
+ Fluent::Plugin.register_output('redis_publish', self)
4
+
5
+ config_param :host, :string, :default => '127.0.0.1'
6
+ config_param :path, :string, :default => nil
7
+ config_param :port, :integer, :default => 6379
8
+ config_param :db, :integer, :default => 0
9
+ config_param :format, :string, :default => 'json'
10
+
11
+ attr_reader :redis
12
+
13
+ def initialize
14
+ super
15
+ require 'redis'
16
+ require 'json'
17
+ require 'msgpack'
18
+ end
19
+
20
+ def configure(conf)
21
+ super
22
+ end
23
+
24
+ def start
25
+ super
26
+
27
+ if @path
28
+ @redis = Redis.new(:path => @path, :db => @db)
29
+ else
30
+ @redis = Redis.new(:host => @host, :port => @port, :db => @db);
31
+ end
32
+ end
33
+
34
+ def shutdown
35
+ super
36
+ end
37
+
38
+ def format(tag, time, record)
39
+ [tag, time, record].to_msgpack
40
+ end
41
+
42
+ def write(chunk)
43
+ @redis.pipelined do
44
+ chunk.msgpack_each do |(tag, time, record)|
45
+ record["time"] = time
46
+
47
+ if @format == "json"
48
+ @redis.publish(tag, record.to_json)
49
+ elsif @format == "msgpack"
50
+ @redis.publish(tag, record.to_msgpack)
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
data/test/helpers.rb ADDED
@@ -0,0 +1,29 @@
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
+
12
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
13
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
14
+ require 'fluent/test'
15
+ unless ENV.has_key?('VERBOSE')
16
+ nulllogger = Object.new
17
+ nulllogger.instance_eval {|obj|
18
+ def method_missing(method, *args)
19
+ # pass
20
+ end
21
+ }
22
+ $log = nulllogger
23
+ end
24
+
25
+ require 'fluent/plugin/out_redis_publish'
26
+
27
+ class Test::Unit::TestCase
28
+ end
29
+
@@ -0,0 +1,72 @@
1
+ require 'helpers'
2
+
3
+ require 'redis'
4
+
5
+ $channel = nil
6
+ $message = nil
7
+
8
+ class Redis
9
+ def initialize(options = {})
10
+ end
11
+
12
+ def pipelined
13
+ yield self
14
+ end
15
+
16
+ def publish(channel, message)
17
+ $channel = channel
18
+ $message = message
19
+ end
20
+ end
21
+
22
+ class RedisPublishOutputTest < Test::Unit::TestCase
23
+ def setup
24
+ Fluent::Test.setup
25
+ end
26
+
27
+ CONFIG1 = %[
28
+ ]
29
+ CONFIG2 = %[
30
+ host 192.168.2.3
31
+ port 9999
32
+ db 3
33
+ ]
34
+ CONFIG3 = %[
35
+ path /tmp/foo.sock
36
+ ]
37
+
38
+ def create_driver(conf)
39
+ Fluent::Test::BufferedOutputTestDriver.new(Fluent::RedisPublishOutput).configure(conf)
40
+ end
41
+
42
+ def test_configure
43
+ # defaults
44
+ d = create_driver(CONFIG1)
45
+ assert_equal "127.0.0.1", d.instance.host
46
+ assert_equal 6379, d.instance.port
47
+ assert_equal nil, d.instance.path
48
+ assert_equal 0, d.instance.db
49
+
50
+ # host port db
51
+ d = create_driver(CONFIG2)
52
+ assert_equal "192.168.2.3", d.instance.host
53
+ assert_equal 9999, d.instance.port
54
+ assert_equal nil, d.instance.path
55
+ assert_equal 3, d.instance.db
56
+
57
+ # path
58
+ d = create_driver(CONFIG3)
59
+ assert_equal "/tmp/foo.sock", d.instance.path
60
+ end
61
+
62
+ def test_write
63
+ d = create_driver(CONFIG1)
64
+
65
+ time = Time.parse("2011-01-02 13:14:15 UTC").to_i
66
+ d.emit({ "foo" => "bar" }, time)
67
+ d.run
68
+
69
+ assert_equal "test", $channel
70
+ assert_equal(%Q[{"foo":"bar","time":#{time}}], $message)
71
+ end
72
+ end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-redis-publish
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Daisuke Murase
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-11-13 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: redis
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description:
42
+ email:
43
+ - typester@cpan.org
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - .gitignore
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - fluent-plugin-redis-publish.gemspec
54
+ - lib/fluent/plugin/out_redis_publish.rb
55
+ - test/helpers.rb
56
+ - test/plugin/test_out_redis_publish.rb
57
+ homepage: https://github.com/typester/fluent-plugin-redis-publish
58
+ licenses: []
59
+ metadata: {}
60
+ post_install_message:
61
+ rdoc_options: []
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ requirements: []
75
+ rubyforge_project:
76
+ rubygems_version: 2.0.3
77
+ signing_key:
78
+ specification_version: 4
79
+ summary: fluent output plugin publishing logs to redis pub/sub
80
+ test_files:
81
+ - test/helpers.rb
82
+ - test/plugin/test_out_redis_publish.rb