fluent-plugin-debug 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/.rspec +2 -0
- data/.travis.yml +6 -0
- data/CHANGELOG.md +4 -0
- data/Gemfile +3 -0
- data/LICENSE +22 -0
- data/README.md +103 -0
- data/Rakefile +15 -0
- data/examples/debug_all.conf +16 -0
- data/fluent-plugin-debug.gemspec +25 -0
- data/lib/fluent/plugin/in_debug.rb +54 -0
- data/spec/in_debug_spec.rb +65 -0
- data/spec/spec_helper.rb +14 -0
- metadata +128 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 879b946f7b4406574b8b82bd67a624c7da4e3dcd
|
4
|
+
data.tar.gz: ddb297209634c9a15ee05791134a9d92e4db4e95
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 04db20cbc22e0f833e9df9d05f40080e9e16ad0eee296b447d2071a33575e0fce5b0a065b16c0047d4c38adbca15b564ad8fa022edd1302ada0a741561bd00ab
|
7
|
+
data.tar.gz: 18f640c3fcacfd39a76975680f7d8c51fe9b9b26eca45d4f38ee8e233425fbcae3a9c03df3605bc0b15d89d6b288eb972922a15c4bbc076eae0585cec85a5cb7
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
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,103 @@
|
|
1
|
+
# fluent-plugin-debug
|
2
|
+
|
3
|
+
[](http://travis-ci.org/sonots/fluent-plugin-debug)
|
4
|
+
[](https://codeclimate.com/github/sonots/fluent-plugin-debug)
|
5
|
+
|
6
|
+
Fluentd plugin to investigate incoming messages in a short-hand.
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Use RubyGems:
|
11
|
+
|
12
|
+
gem install fluent-plugin-debug
|
13
|
+
|
14
|
+
## What is this for?
|
15
|
+
|
16
|
+
Do you use `out_copy` and `out_stdout` to see incoming messages?
|
17
|
+
|
18
|
+
```apache
|
19
|
+
<match **>
|
20
|
+
type copy
|
21
|
+
<store>
|
22
|
+
type stdout
|
23
|
+
</store>
|
24
|
+
<store>
|
25
|
+
type file
|
26
|
+
# blah blah
|
27
|
+
</store>
|
28
|
+
</match>
|
29
|
+
```
|
30
|
+
|
31
|
+
This plugin enables to write the same thing in a short-hand, by just adding `debug true`, as:
|
32
|
+
|
33
|
+
```apache
|
34
|
+
<match **>
|
35
|
+
type file
|
36
|
+
debug true
|
37
|
+
# blash blah
|
38
|
+
</match>
|
39
|
+
```
|
40
|
+
|
41
|
+
## Configuration
|
42
|
+
|
43
|
+
This plugin is doing something tricky, which extends arbitrary plugins so that they can use `debug` option parameter.
|
44
|
+
|
45
|
+
```apache
|
46
|
+
<source>
|
47
|
+
type debug # This makes available the `debug` option for all output plugins
|
48
|
+
</source>
|
49
|
+
|
50
|
+
<match **>
|
51
|
+
type file
|
52
|
+
debug true # Now you can use `debug true`
|
53
|
+
</match>
|
54
|
+
```
|
55
|
+
|
56
|
+
If you are lazy to write even `debug true`, you may use `debug_all` option.
|
57
|
+
|
58
|
+
```apache
|
59
|
+
<source>
|
60
|
+
type debug
|
61
|
+
debug_all true # This makes turn on the `debug` option for all output plugins
|
62
|
+
</source>
|
63
|
+
|
64
|
+
<match **>
|
65
|
+
type file # Now you don't need even to add `debug true`
|
66
|
+
</match>
|
67
|
+
```
|
68
|
+
|
69
|
+
## Options
|
70
|
+
|
71
|
+
### Options (source)
|
72
|
+
|
73
|
+
* debug_all
|
74
|
+
|
75
|
+
* Apply `debug true` for all output plugins
|
76
|
+
|
77
|
+
### Options (output plugins)
|
78
|
+
|
79
|
+
This plugin extends all output plugins and enables to use the following options:
|
80
|
+
|
81
|
+
* debug (bool)
|
82
|
+
|
83
|
+
* Enable to output the incoming messages
|
84
|
+
|
85
|
+
## ChangeLog
|
86
|
+
|
87
|
+
See [CHANGELOG.md](CHANGELOG.md) for details.
|
88
|
+
|
89
|
+
## Note
|
90
|
+
|
91
|
+
This plugin is dedicated to [@hirose31](https://github.com/hirose31).
|
92
|
+
|
93
|
+
## Contributing
|
94
|
+
|
95
|
+
1. Fork it
|
96
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
97
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
98
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
99
|
+
5. Create new [Pull Request](../../pull/new/master)
|
100
|
+
|
101
|
+
## Copyright
|
102
|
+
|
103
|
+
Copyright (c) 2014 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,25 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
$:.push File.expand_path('../lib', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.name = "fluent-plugin-debug"
|
6
|
+
gem.version = "0.0.1"
|
7
|
+
gem.authors = ["Naotoshi Seo"]
|
8
|
+
gem.email = "sonots@gmail.com"
|
9
|
+
gem.homepage = "https://github.com/sonots/fluent-plugin-debug"
|
10
|
+
gem.description = "Fluentd plugin to investigate incoming messages in a short-hand"
|
11
|
+
gem.summary = gem.description
|
12
|
+
gem.licenses = ["MIT"]
|
13
|
+
gem.has_rdoc = false
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split("\n")
|
16
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
17
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
18
|
+
gem.require_paths = ['lib']
|
19
|
+
|
20
|
+
gem.add_dependency "fluentd", "~> 0.10.17"
|
21
|
+
gem.add_development_dependency "rake"
|
22
|
+
gem.add_development_dependency "rspec"
|
23
|
+
gem.add_development_dependency "pry"
|
24
|
+
gem.add_development_dependency "pry-nav"
|
25
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'fluent/input'
|
2
|
+
|
3
|
+
module Fluent
|
4
|
+
class DebugInput < Input
|
5
|
+
Plugin.register_input('debug', self)
|
6
|
+
config_param :debug_all, :bool, :default => false
|
7
|
+
|
8
|
+
def configure(conf)
|
9
|
+
super
|
10
|
+
Debuggable.extend_configure(::Fluent::Output)
|
11
|
+
end
|
12
|
+
|
13
|
+
def start
|
14
|
+
# Engine.matches are created after input plugins are configured, so matches are empty in #configure
|
15
|
+
# cf. https://github.com/fluent/fluentd/blob/56f198ecf5ca95dcddef7bdc21b5a309468670e3/lib/fluent/engine.rb#L123
|
16
|
+
# #start is called after that, so we can access to Engine.matches here
|
17
|
+
super
|
18
|
+
if @debug_all
|
19
|
+
Engine.matches.each do |match|
|
20
|
+
Debuggable.extend_emit(match.output)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# WOW! WHAT A FUCKING META PROGRAMMING!
|
27
|
+
class Debuggable
|
28
|
+
def self.extend_emit(obj)
|
29
|
+
klass = obj.singleton_class
|
30
|
+
unless klass.method_defined?(:emit_without_debug)
|
31
|
+
klass.__send__(:alias_method, :emit_without_debug, :emit)
|
32
|
+
klass.__send__(:define_method, :emit_with_debug) do |tag, es, chain|
|
33
|
+
es.each do |time, record|
|
34
|
+
$log.write "#{Time.at(time).localtime} #{tag}: #{Yajl.dump(record)}\n"
|
35
|
+
end
|
36
|
+
emit_without_debug(tag, es, chain)
|
37
|
+
end
|
38
|
+
klass.__send__(:alias_method, :emit, :emit_with_debug)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.extend_configure(klass)
|
43
|
+
unless klass.method_defined?(:configure_without_debug)
|
44
|
+
klass.config_param :debug, :bool, :default => false
|
45
|
+
klass.__send__(:alias_method, :configure_without_debug, :configure)
|
46
|
+
klass.__send__(:define_method, :configure_with_debug) do |conf|
|
47
|
+
configure_without_debug(conf)
|
48
|
+
Debuggable.extend_emit(self) if conf['debug']
|
49
|
+
end
|
50
|
+
klass.__send__(:alias_method, :configure, :configure_with_debug)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require_relative 'spec_helper'
|
3
|
+
require 'fluent/plugin/out_stdout'
|
4
|
+
|
5
|
+
# Capture the log output of the block given
|
6
|
+
def capture_log(&block)
|
7
|
+
tmp = $log
|
8
|
+
$log = StringIO.new
|
9
|
+
yield
|
10
|
+
return $log.string
|
11
|
+
ensure
|
12
|
+
$log = tmp
|
13
|
+
end
|
14
|
+
|
15
|
+
describe Fluent::DebugInput do
|
16
|
+
before { Fluent::Test.setup }
|
17
|
+
|
18
|
+
def create_driver(conf=%[])
|
19
|
+
Fluent::Test::InputTestDriver.new(Fluent::DebugInput).configure(conf)
|
20
|
+
end
|
21
|
+
|
22
|
+
describe 'test configure' do
|
23
|
+
it { expect { create_driver }.not_to raise_error }
|
24
|
+
it { expect { create_driver(%[debug_all true]) }.not_to raise_error }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "debug_all" do
|
29
|
+
# There is not suitable test driver ...
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "extends Fluent::StdoutOutput" do
|
33
|
+
before { Fluent::Test.setup }
|
34
|
+
|
35
|
+
def create_driver(conf=CONFIG, tag = 'test')
|
36
|
+
Fluent::Test::OutputTestDriver.new(Fluent::StdoutOutput, tag).configure(conf)
|
37
|
+
end
|
38
|
+
let(:driver) { create_driver(config) }
|
39
|
+
|
40
|
+
describe 'test configure' do
|
41
|
+
let(:config) { %[debug true] }
|
42
|
+
let(:subject) { driver.instance }
|
43
|
+
its(:debug) { should == true }
|
44
|
+
end
|
45
|
+
|
46
|
+
describe 'test emit' do
|
47
|
+
let(:config) { %[debug true] }
|
48
|
+
|
49
|
+
before {
|
50
|
+
time = Fluent::Engine.now
|
51
|
+
Fluent::Engine.stub(:now).and_return(time)
|
52
|
+
}
|
53
|
+
|
54
|
+
it 'should flush' do
|
55
|
+
d = driver.instance
|
56
|
+
out = capture_log do
|
57
|
+
chain = Fluent::NullOutputChain.instance
|
58
|
+
d.emit('tag', Fluent::OneEventStream.new(0, {'a'=>1}), chain)
|
59
|
+
end
|
60
|
+
debug_stdout, out_stdout = out.split("\n")
|
61
|
+
debug_stdout.should_not be_nil
|
62
|
+
debug_stdout.should == out_stdout
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'rubygems'
|
3
|
+
require 'bundler'
|
4
|
+
require 'fluent/load'
|
5
|
+
Bundler.setup(:default, :test)
|
6
|
+
Bundler.require(:default, :test)
|
7
|
+
|
8
|
+
require 'fluent/test'
|
9
|
+
require 'rspec'
|
10
|
+
require 'pry'
|
11
|
+
|
12
|
+
$TESTING=true
|
13
|
+
$:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
|
14
|
+
require 'fluent/plugin/in_debug'
|
metadata
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fluent-plugin-debug
|
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: 2014-04-25 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.10.17
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.10.17
|
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
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry-nav
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: Fluentd plugin to investigate incoming messages in a short-hand
|
84
|
+
email: sonots@gmail.com
|
85
|
+
executables: []
|
86
|
+
extensions: []
|
87
|
+
extra_rdoc_files: []
|
88
|
+
files:
|
89
|
+
- ".gitignore"
|
90
|
+
- ".rspec"
|
91
|
+
- ".travis.yml"
|
92
|
+
- CHANGELOG.md
|
93
|
+
- Gemfile
|
94
|
+
- LICENSE
|
95
|
+
- README.md
|
96
|
+
- Rakefile
|
97
|
+
- examples/debug_all.conf
|
98
|
+
- fluent-plugin-debug.gemspec
|
99
|
+
- lib/fluent/plugin/in_debug.rb
|
100
|
+
- spec/in_debug_spec.rb
|
101
|
+
- spec/spec_helper.rb
|
102
|
+
homepage: https://github.com/sonots/fluent-plugin-debug
|
103
|
+
licenses:
|
104
|
+
- MIT
|
105
|
+
metadata: {}
|
106
|
+
post_install_message:
|
107
|
+
rdoc_options: []
|
108
|
+
require_paths:
|
109
|
+
- lib
|
110
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0'
|
115
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - ">="
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
requirements: []
|
121
|
+
rubyforge_project:
|
122
|
+
rubygems_version: 2.2.2
|
123
|
+
signing_key:
|
124
|
+
specification_version: 4
|
125
|
+
summary: Fluentd plugin to investigate incoming messages in a short-hand
|
126
|
+
test_files:
|
127
|
+
- spec/in_debug_spec.rb
|
128
|
+
- spec/spec_helper.rb
|