fluent-helper-plugin-spec 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 +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +13 -0
- data/README.md +31 -0
- data/Rakefile +1 -0
- data/fluent-helper-plugin-spec.gemspec +25 -0
- data/lib/fluent-helper-plugin-spec.rb +3 -0
- data/lib/fluent/helper/plugin_spec.rb +166 -0
- data/spec/out_retag_spec.rb +34 -0
- data/spec/util/out_retag.rb +22 -0
- metadata +113 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2e22bf34a843d4e84954ed1c448686ffe4929578
|
4
|
+
data.tar.gz: 11f79243f143bc39aca296e540cb6fcd3ac68301
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9f490e0f4954966d7fd028d23ca7e15f770602a747f478f6f29925f0e7e85f952ea8965932f30412b9013eb70a5fca2c65196ad02be17aa5cc0ad840c06e353e
|
7
|
+
data.tar.gz: af86e171a262e1d33671eb2e39ab798ac6342b78860e0a5f96ff12062f06362bf3a8aac764d0c6ee2d9329fd333c691378a536bcd6ce84714a4f5639a4746fa6
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Copyright (c) 2012- TAGOMORI Satoshi
|
2
|
+
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
you may not use this file except in compliance with the License.
|
5
|
+
You may obtain a copy of the License at
|
6
|
+
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
See the License for the specific language governing permissions and
|
13
|
+
limitations under the License.
|
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# Fluentd plugin spec helper
|
2
|
+
|
3
|
+
This is RSpec helper library for Fluentd plugins. This is for developers of fluentd plugins, not users.
|
4
|
+
|
5
|
+
**Documents are under construction**
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'fluent-helper-plugin-spec'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install fluent-helper-plugin-spec
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
TODO: Write usage instructions here
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
1. Fork it ( http://github.com/<my-github-username>/fluent-helper-plugin-spec/fork )
|
28
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
30
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
31
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "fluent-helper-plugin-spec"
|
5
|
+
spec.version = "0.0.1"
|
6
|
+
spec.authors = ["TAGOMORI Satoshi"]
|
7
|
+
spec.email = ["tagomoris@gmail.com"]
|
8
|
+
spec.summary = %q{RSpec helper for Fluentd plugin development}
|
9
|
+
spec.description = %q{RSpec helper to develop Fluentd plugin with rspec, instead of Fluentd default test/unit. This spec helper requires Ruby 2.1.}
|
10
|
+
spec.homepage = "https://github.com/tagomoris/fluent-helper-plugin-spec"
|
11
|
+
spec.license = "APLv2"
|
12
|
+
|
13
|
+
spec.files = `git ls-files -z`.split("\x0")
|
14
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
15
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
16
|
+
spec.require_paths = ["lib"]
|
17
|
+
|
18
|
+
spec.required_ruby_version = '>= 2.1.0'
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
21
|
+
spec.add_development_dependency "rake"
|
22
|
+
|
23
|
+
spec.add_runtime_dependency "fluentd"
|
24
|
+
spec.add_runtime_dependency "rspec"
|
25
|
+
end
|
@@ -0,0 +1,166 @@
|
|
1
|
+
# This file MUST NOT be required from any fluentd modules except for 'PLUGIN_spec.rb'!
|
2
|
+
|
3
|
+
require 'fluent/log'
|
4
|
+
require 'fluent/engine'
|
5
|
+
require 'fluent/plugin'
|
6
|
+
require 'fluent/config'
|
7
|
+
require 'fluent/input'
|
8
|
+
require 'fluent/output'
|
9
|
+
|
10
|
+
$log ||= Fluent::Log.new
|
11
|
+
|
12
|
+
module Fluent::PluginSpecUser
|
13
|
+
refine Fluent::EngineClass do
|
14
|
+
def emit(tag, time, record)
|
15
|
+
Fluent::Helper::PluginEmitStub.emit_event(tag, time, record)
|
16
|
+
end
|
17
|
+
def emits(tag, es)
|
18
|
+
es.each do |time, record|
|
19
|
+
Fluent::Helper::PluginEmitStub.emit_event(tag, time, record)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
module Fluent::Helper
|
26
|
+
module PluginEmitStub
|
27
|
+
def self.register_target(klass)
|
28
|
+
@@current_target = klass
|
29
|
+
@@store ||= {}
|
30
|
+
@@store[Thread.current] ||= {}
|
31
|
+
@@store[Thread.current][klass] = {} # tag => [events]
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.emit_event(tag, time, record)
|
35
|
+
@@store[Thread.current][@@current_target][tag] ||= []
|
36
|
+
@@store[Thread.current][@@current_target][tag].push( PluginSpec::Event.new(time, record) )
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.stored(tag)
|
40
|
+
@@store[Thread.current][@@current_target] || {}
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
module PluginSpec
|
45
|
+
class Driver
|
46
|
+
attr_reader :instance
|
47
|
+
|
48
|
+
def initialize(plugin_klass, conf)
|
49
|
+
@plugin_klass = plugin_klass
|
50
|
+
Fluent::Helper::PluginEmitStub.register_target(plugin_klass)
|
51
|
+
|
52
|
+
plugin = plugin_klass.new
|
53
|
+
unless plugin.is_a?(Fluent::Input) || plugin.is_a?(Fluent::Output)
|
54
|
+
raise ArgumentError, "unknown class as plugin #{plugin.class}"
|
55
|
+
end
|
56
|
+
|
57
|
+
logger = TestLogger.new
|
58
|
+
|
59
|
+
conf = Fluent::Config.parse(conf, '[test config]')
|
60
|
+
plugin.configure(conf)
|
61
|
+
|
62
|
+
plugin_loglevel = plugin.instance_variable_get(:@log_level)
|
63
|
+
if plugin_loglevel
|
64
|
+
logger.log_level = plugin_loglevel
|
65
|
+
end
|
66
|
+
plugin.log = logger
|
67
|
+
|
68
|
+
@instance = plugin
|
69
|
+
end
|
70
|
+
|
71
|
+
def pitch(tag, time, record)
|
72
|
+
@instance.emit(tag, time, record)
|
73
|
+
end
|
74
|
+
|
75
|
+
def pitches(tag, es)
|
76
|
+
@instance.emits(tag, es)
|
77
|
+
end
|
78
|
+
|
79
|
+
class BatchPitcher
|
80
|
+
def initialize(parent, tag, time=Time.now.to_i)
|
81
|
+
@parent = parent
|
82
|
+
@tag = tag
|
83
|
+
@time = time
|
84
|
+
end
|
85
|
+
def pitch(record, time=nil)
|
86
|
+
@parent.pitch(@tag, time ? time : @time, record)
|
87
|
+
end
|
88
|
+
|
89
|
+
def pitches(es)
|
90
|
+
@parent.pitches(@tag, es)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def with(tag, time=Time.now.to_i)
|
95
|
+
raise ArgumentError unless block_given?
|
96
|
+
yield BatchPitcher.new(self, tag, time)
|
97
|
+
end
|
98
|
+
|
99
|
+
def run
|
100
|
+
raise ArgumentError unless block_given?
|
101
|
+
@instance.start
|
102
|
+
yield self
|
103
|
+
@instance.shutdown
|
104
|
+
end
|
105
|
+
|
106
|
+
def events
|
107
|
+
Fluent::Helper::PluginEmitStub.stored(@plugin_klass)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def generate_driver(plugin, conf)
|
112
|
+
Driver.new(plugin, conf)
|
113
|
+
end
|
114
|
+
|
115
|
+
class Event
|
116
|
+
def initialize(time, record)
|
117
|
+
@time = time
|
118
|
+
@record = record
|
119
|
+
end
|
120
|
+
attr_reader :time, :record
|
121
|
+
alias_method :t, :time
|
122
|
+
alias_method :r, :record
|
123
|
+
end
|
124
|
+
|
125
|
+
class DummyLogDevice
|
126
|
+
attr_reader :logs
|
127
|
+
|
128
|
+
def initialize
|
129
|
+
@logs = []
|
130
|
+
end
|
131
|
+
|
132
|
+
def tty?
|
133
|
+
false
|
134
|
+
end
|
135
|
+
|
136
|
+
def puts(*args)
|
137
|
+
args.each do |arg|
|
138
|
+
write(arg + "\n")
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
def write(message)
|
143
|
+
@logs.push message
|
144
|
+
end
|
145
|
+
|
146
|
+
def flush
|
147
|
+
true
|
148
|
+
end
|
149
|
+
|
150
|
+
def close
|
151
|
+
true
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
class TestLogger < Fluent::PluginLogger
|
156
|
+
def initialize
|
157
|
+
@logdev = DummyLogDevice.new
|
158
|
+
super(Fluent::Log.new(@logdev))
|
159
|
+
end
|
160
|
+
|
161
|
+
def logs
|
162
|
+
@logdev.logs
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'fluent/helper/plugin_spec'
|
2
|
+
include Fluent::Helper::PluginSpec
|
3
|
+
|
4
|
+
require_relative 'util/out_retag'
|
5
|
+
|
6
|
+
describe Fluent::RetagOutput do
|
7
|
+
config = %[
|
8
|
+
type retag
|
9
|
+
tag yyy
|
10
|
+
]
|
11
|
+
driver = generate_driver(Fluent::RetagOutput, config)
|
12
|
+
|
13
|
+
it 'copy events' do
|
14
|
+
driver.run do |d|
|
15
|
+
t = Time.now.to_i
|
16
|
+
d.with('xxx', t) do |d|
|
17
|
+
d.pitch({"f1"=>"data1", "f2"=>"data2"})
|
18
|
+
d.pitch({"f1"=>"data1", "f2"=>"data2"})
|
19
|
+
d.pitch({"f1"=>"data1", "f2"=>"data2"})
|
20
|
+
d.pitch({"f1"=>"data1", "f2"=>"data2"})
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
expect(driver.events.keys.size).to eql(1)
|
25
|
+
expect(driver.events.keys.first).to eql('yyy')
|
26
|
+
expect(driver.events['yyy'].size).to eql(4)
|
27
|
+
driver.events['yyy'].each do |e|
|
28
|
+
expect(e.r).to eql({"f1"=>"data1", "f2"=>"data2"})
|
29
|
+
end
|
30
|
+
|
31
|
+
# p driver.instance.log.logs
|
32
|
+
expect(driver.instance.log.logs.size).to eql(4)
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'fluent/output'
|
2
|
+
|
3
|
+
module Fluent::PluginSpecUser; end
|
4
|
+
defined?(using) and using Fluent::PluginSpecUser
|
5
|
+
|
6
|
+
module Fluent
|
7
|
+
class RetagOutput < Output
|
8
|
+
Plugin.register_output('retag', self)
|
9
|
+
|
10
|
+
config_param :tag, :string
|
11
|
+
|
12
|
+
def emit(tag, time, record)
|
13
|
+
log.info('emit')
|
14
|
+
Fluent::Engine.emit(@tag, time, record)
|
15
|
+
end
|
16
|
+
|
17
|
+
def emits(tag, es)
|
18
|
+
log.debug('emits')
|
19
|
+
Fluent::Engine.emits(@tag, es)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fluent-helper-plugin-spec
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- TAGOMORI Satoshi
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-03-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.5'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
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: fluentd
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
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: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: RSpec helper to develop Fluentd plugin with rspec, instead of Fluentd
|
70
|
+
default test/unit. This spec helper requires Ruby 2.1.
|
71
|
+
email:
|
72
|
+
- tagomoris@gmail.com
|
73
|
+
executables: []
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- ".gitignore"
|
78
|
+
- Gemfile
|
79
|
+
- LICENSE.txt
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- fluent-helper-plugin-spec.gemspec
|
83
|
+
- lib/fluent-helper-plugin-spec.rb
|
84
|
+
- lib/fluent/helper/plugin_spec.rb
|
85
|
+
- spec/out_retag_spec.rb
|
86
|
+
- spec/util/out_retag.rb
|
87
|
+
homepage: https://github.com/tagomoris/fluent-helper-plugin-spec
|
88
|
+
licenses:
|
89
|
+
- APLv2
|
90
|
+
metadata: {}
|
91
|
+
post_install_message:
|
92
|
+
rdoc_options: []
|
93
|
+
require_paths:
|
94
|
+
- lib
|
95
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: 2.1.0
|
100
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
requirements: []
|
106
|
+
rubyforge_project:
|
107
|
+
rubygems_version: 2.2.2
|
108
|
+
signing_key:
|
109
|
+
specification_version: 4
|
110
|
+
summary: RSpec helper for Fluentd plugin development
|
111
|
+
test_files:
|
112
|
+
- spec/out_retag_spec.rb
|
113
|
+
- spec/util/out_retag.rb
|