Skip to content

Commit

Permalink
in_http: Honor keep_time_key parameter in batch mode.
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
Fujimoto Seiji committed Jun 14, 2018
1 parent c49959c commit 6d61cfb
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions lib/fluent/plugin/in_http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 6d61cfb

Please sign in to comment.