diff --git a/lib/fluent/plugin/in_http.rb b/lib/fluent/plugin/in_http.rb index efff85bbb9..3a9b34c82e 100644 --- a/lib/fluent/plugin/in_http.rb +++ b/lib/fluent/plugin/in_http.rb @@ -209,13 +209,15 @@ def on_request(path_info, params) single_record['REMOTE_ADDR'] = params['REMOTE_ADDR'] end - if single_record.has_key?(@parser_time_key) - single_time = Fluent::EventTime.from_time(Time.at(single_record[@parser_time_key])) - unless @parser and @parser.keep_time_key - single_record.delete(@parser_time_key) - end + if defined? @parser + single_time = @parser.parse_time(single_record) + single_time, single_record = @parser.convert_values(single_time, single_record) else - single_time = time + single_time = if t = single_record.delete(@parser_time_key) + Fluent::EventTime.from_time(Time.at(t)) + else + time + end end mes.add(single_time, single_record) diff --git a/test/plugin/test_in_http.rb b/test/plugin/test_in_http.rb index 25b8819a70..78bd07e21b 100644 --- a/test/plugin/test_in_http.rb +++ b/test/plugin/test_in_http.rb @@ -370,16 +370,20 @@ def test_json_with_add_http_headers assert include_http_header?(d.events[1][2]) end - def test_multi_json_with_keep_time_key + def test_multi_json_with_custom_parser d = create_driver(CONFIG + %[ @type json keep_time_key true + time_key foo + time_format %iso8601 ]) - time1 = event_time("2011-01-02 13:14:15 UTC") - time2 = event_time("2012-01-02 13:14:15 UTC") - records = [{"time"=>time1.to_i},{"time"=>time2.to_i}] + + time = event_time("2011-01-02 13:14:15 UTC") + time_s = Time.at(time).iso8601 + + records = [{"foo"=>time_s,"bar"=>"test1"},{"foo"=>time_s,"bar"=>"test2"}] tag = "tag1" res_codes = [] @@ -390,11 +394,11 @@ def test_multi_json_with_keep_time_key assert_equal ["200"], res_codes assert_equal "tag1", d.events[0][0] - assert_equal_event_time time1, d.events[0][1] + assert_equal_event_time time, d.events[0][1] assert_equal d.events[0][2], records[0] assert_equal "tag1", d.events[1][0] - assert_equal_event_time time2, d.events[1][1] + assert_equal_event_time time, d.events[1][1] assert_equal d.events[1][2], records[1] end