From 6d61cfb7d73c9970bb91ed375bdeabda9691fcd7 Mon Sep 17 00:00:00 2001 From: Fujimoto Seiji Date: Thu, 14 Jun 2018 16:00:41 +0900 Subject: [PATCH] in_http: Honor `keep_time_key` parameter in batch mode. The in_http plugin supports "batch" mode for sending multiple events in a single HTTP request. The problem is that in_http does not honor the `keep_time_key` option when processing those bulk-insertion requests. This means that "time" key in each record gets discarded unconditionally in batch mode. For example, the following request: $ curl -d '[{"time":1514736000,"key":"foo"}]' http://localhost/ will produces a log record: 2018-01-01 01:00:00.000000000 +0900 : {"key":"foo"} even if the `keep_time_key` option is enabled. This patch fixes this issue by teaching in_http to honor the option value of its parser plugin instance. Signed-off-by: Fujimoto Seiji --- lib/fluent/plugin/in_http.rb | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/fluent/plugin/in_http.rb b/lib/fluent/plugin/in_http.rb index 2458eedcba..20327db2b3 100644 --- a/lib/fluent/plugin/in_http.rb +++ b/lib/fluent/plugin/in_http.rb @@ -202,11 +202,17 @@ def on_request(path_info, params) if @add_remote_addr single_record['REMOTE_ADDR'] = params['REMOTE_ADDR'] end - single_time = if t = single_record.delete('time') - Fluent::EventTime.from_time(Time.at(t)) - else - time - end + + if single_record.has_key?('time') + single_time = Fluent::EventTime.from_time(Time.at(single_record['time'])) + else + single_time = time + end + + unless @parser and @parser.keep_time_key + single_record.delete('time') + end + mes.add(single_time, single_record) end router.emit_stream(tag, mes)