Skip to content

Commit

Permalink
Merge pull request #2020 from fujimotos/sf/honor-keep-time-key
Browse files Browse the repository at this point in the history
in_http: Honor `keep_time_key` parameter in batch mode.
  • Loading branch information
repeatedly authored Jun 19, 2018
2 parents 5184481 + d0809c6 commit 84c2194
Show file tree
Hide file tree
Showing 2 changed files with 39 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']))

unless @parser and @parser.keep_time_key
single_record.delete('time')
end
else
single_time = time
end

mes.add(single_time, single_record)
end
router.emit_stream(tag, mes)
Expand Down
28 changes: 28 additions & 0 deletions test/plugin/test_in_http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,34 @@ def test_json_with_add_http_headers
assert include_http_header?(d.events[1][2])
end

def test_multi_json_with_keep_time_key
d = create_driver(CONFIG + %[
<parse>
@type json
keep_time_key true
</parse>
])
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}]
tag = "tag1"
res_codes = []

d.run(expect_records: 2, timeout: 5) do
res = post("/#{tag}", records.to_json, {"Content-Type"=>"application/octet-stream"})
res_codes << res.code
end
assert_equal ["200"], res_codes

assert_equal "tag1", d.events[0][0]
assert_equal_event_time time1, 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 d.events[1][2], records[1]
end

def test_application_json
d = create_driver
time = event_time("2011-01-02 13:14:15 UTC")
Expand Down

0 comments on commit 84c2194

Please sign in to comment.