diff --git a/lib/fluent/plugin/grok.rb b/lib/fluent/plugin/grok.rb index eef8277..fb0b77e 100644 --- a/lib/fluent/plugin/grok.rb +++ b/lib/fluent/plugin/grok.rb @@ -33,6 +33,9 @@ def initialize(plugin, conf) if @plugin.respond_to?(:multiline_start_regexp) && @plugin.multiline_start_regexp @multiline_start_regexp = Regexp.compile(@plugin.multiline_start_regexp[1..-2]) end + if @plugin.respond_to?(:keep_time_key) + @keep_time_key = @plugin.keep_time_key + end end def add_patterns_from_file(path) @@ -68,7 +71,7 @@ def expand_pattern_expression(grok_pattern, conf) unless types.empty? _conf["types"] = types.map{|subname,type| "#{subname}:#{type}" }.join(",") end - _conf = _conf.merge("expression" => regexp, "multiline" => @multiline_mode) + _conf = _conf.merge("expression" => regexp, "multiline" => @multiline_mode, "keep_time_key" => @keep_time_key) config = Fluent::Config::Element.new("parse", nil, _conf, []) parser = Fluent::Plugin::RegexpParser.new parser.configure(config) diff --git a/test/test_grok_parser.rb b/test/test_grok_parser.rb index 2d80e5b..ec5d062 100644 --- a/test/test_grok_parser.rb +++ b/test/test_grok_parser.rb @@ -301,6 +301,26 @@ class GrokParserTest < ::Test::Unit::TestCase end end + sub_test_case "keep_time_key" do + test "true" do + d = create_driver(%[ + keep_time_key true + + pattern "%{TIMESTAMP_ISO8601:time}" + + ]) + expected = [ + { "time" => "2014-01-01T00:00:00+0900" } + ] + records = [] + d.instance.parse("Some stuff at 2014-01-01T00:00:00+0900") do |time, record| + assert_equal(event_time("2014-01-01T00:00:00+0900"), time) + records << record + end + assert_equal(expected, records) + end + end + private def create_driver(conf)