diff --git a/fluent-plugin-better-timestamp.gemspec b/fluent-plugin-better-timestamp.gemspec index 0b6b4a4..176a798 100644 --- a/fluent-plugin-better-timestamp.gemspec +++ b/fluent-plugin-better-timestamp.gemspec @@ -17,7 +17,8 @@ Gem::Specification.new do |gem| gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } gem.require_paths = ['lib'] - gem.add_dependency "fluentd", "~> 0.10.17" + gem.add_dependency "fluentd", [">= 0.10.17", "< 2"] gem.add_dependency "fluent-mixin-config-placeholders", ">= 0.3.0" gem.add_development_dependency "rake", ">= 0.9.2" + gem.add_development_dependency "test-unit", ">= 3.2.0" end diff --git a/lib/fluent/plugin/out_better_timestamp.rb b/lib/fluent/plugin/out_better_timestamp.rb index d25b212..fc5e104 100644 --- a/lib/fluent/plugin/out_better_timestamp.rb +++ b/lib/fluent/plugin/out_better_timestamp.rb @@ -4,6 +4,11 @@ module Fluent class BetterTimestampOutput < Output Fluent::Plugin.register_output('better_timestamp', self) + # Define `router` method of v0.12 to support v0.10 or earlier + unless method_defined?(:router) + define_method("router") { Fluent::Engine } + end + config_param :tag, :string config_param :msec_key, :string, :default => 'msec' config_param :timestamp_key, :string, :default => '@timestamp' @@ -23,13 +28,12 @@ def configure(conf) @map[k] = v end } - end def emit(tag, es, chain) es.each { |time, record| filter_record(tag, time, record) - Engine.emit(@tag, time, modify_record(time, record)) + router.emit(@tag, time, modify_record(time, record)) } chain.next diff --git a/test/out_better_timestamp.rb b/test/out_better_timestamp.rb index aeca1e6..955a9b9 100644 --- a/test/out_better_timestamp.rb +++ b/test/out_better_timestamp.rb @@ -10,7 +10,7 @@ def setup type better_timestamp tag foo.filtered msec_key msec - timestamp_key + timestamp_key @timestamp ] def create_driver(conf = CONFIG) @@ -19,9 +19,8 @@ def create_driver(conf = CONFIG) def test_configure d = create_driver - map = d.instance.instance_variable_get(:@map) - #assert_equal 'msec', map['msec_key'] + assert_equal 'msec', d.instance.msec_key end def test_remove_one_key @@ -33,8 +32,9 @@ def test_remove_one_key mapped = {} + msec = 1 d.run do - d.emit("msec" => '1', "k1" => 'v') + d.emit({"msec" => msec, "k1" => 'v'}) end assert d.records[0]['@timestamp']