From d374bb2dbccc64cea3861f02bcb78c6ce40d78ed Mon Sep 17 00:00:00 2001 From: Hiroshi Hatake Date: Wed, 4 Oct 2017 11:11:16 +0900 Subject: [PATCH 1/4] Permit to work with Fluentd v0.14 --- fluent-plugin-better-timestamp.gemspec | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 From ccf8e136758cb3d2ece80ebe6e6c6f841b1eaafe Mon Sep 17 00:00:00 2001 From: Hiroshi Hatake Date: Wed, 4 Oct 2017 11:11:46 +0900 Subject: [PATCH 2/4] Tweak for v0.14's compatible layer --- lib/fluent/plugin/out_better_timestamp.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) 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 From 1afc6c3856421601f40819e91e05f7a525b0b212 Mon Sep 17 00:00:00 2001 From: Hiroshi Hatake Date: Wed, 4 Oct 2017 11:14:39 +0900 Subject: [PATCH 3/4] Tweak test cases --- test/out_better_timestamp.rb | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/test/out_better_timestamp.rb b/test/out_better_timestamp.rb index aeca1e6..f778ef0 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,10 +32,14 @@ def test_remove_one_key mapped = {} + msec = 1 + time = Time.now + time_str = Time.at(time.to_r, msec * 1000).strftime("%Y-%m-%dT%H:%M:%S.%L%z") d.run do - d.emit("msec" => '1', "k1" => 'v') + d.emit({"msec" => msec.to_s, "k1" => 'v'}, time.to_r) end + assert_equal time_str, d.records[0]['@timestamp'] assert d.records[0]['@timestamp'] end end From 938a5b2c79fd99bb2943f4e9b7282e9114461244 Mon Sep 17 00:00:00 2001 From: Hiroshi Hatake Date: Wed, 3 Oct 2018 16:27:50 +0900 Subject: [PATCH 4/4] Remove needless operation --- test/out_better_timestamp.rb | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/test/out_better_timestamp.rb b/test/out_better_timestamp.rb index f778ef0..955a9b9 100644 --- a/test/out_better_timestamp.rb +++ b/test/out_better_timestamp.rb @@ -33,13 +33,10 @@ def test_remove_one_key mapped = {} msec = 1 - time = Time.now - time_str = Time.at(time.to_r, msec * 1000).strftime("%Y-%m-%dT%H:%M:%S.%L%z") d.run do - d.emit({"msec" => msec.to_s, "k1" => 'v'}, time.to_r) + d.emit({"msec" => msec, "k1" => 'v'}) end - assert_equal time_str, d.records[0]['@timestamp'] assert d.records[0]['@timestamp'] end end