Skip to content

Commit c6629ac

Browse files
authored
Merge pull request #56 from fluent/keep-time-key
Support keep_time_key parameter
2 parents d31f18e + a9abeee commit c6629ac

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

lib/fluent/plugin/grok.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ def initialize(plugin, conf)
3333
if @plugin.respond_to?(:multiline_start_regexp) && @plugin.multiline_start_regexp
3434
@multiline_start_regexp = Regexp.compile(@plugin.multiline_start_regexp[1..-2])
3535
end
36+
if @plugin.respond_to?(:keep_time_key)
37+
@keep_time_key = @plugin.keep_time_key
38+
end
3639
end
3740

3841
def add_patterns_from_file(path)
@@ -68,7 +71,7 @@ def expand_pattern_expression(grok_pattern, conf)
6871
unless types.empty?
6972
_conf["types"] = types.map{|subname,type| "#{subname}:#{type}" }.join(",")
7073
end
71-
_conf = _conf.merge("expression" => regexp, "multiline" => @multiline_mode)
74+
_conf = _conf.merge("expression" => regexp, "multiline" => @multiline_mode, "keep_time_key" => @keep_time_key)
7275
config = Fluent::Config::Element.new("parse", nil, _conf, [])
7376
parser = Fluent::Plugin::RegexpParser.new
7477
parser.configure(config)

test/test_grok_parser.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,26 @@ class GrokParserTest < ::Test::Unit::TestCase
301301
end
302302
end
303303

304+
sub_test_case "keep_time_key" do
305+
test "true" do
306+
d = create_driver(%[
307+
keep_time_key true
308+
<grok>
309+
pattern "%{TIMESTAMP_ISO8601:time}"
310+
</grok>
311+
])
312+
expected = [
313+
{ "time" => "2014-01-01T00:00:00+0900" }
314+
]
315+
records = []
316+
d.instance.parse("Some stuff at 2014-01-01T00:00:00+0900") do |time, record|
317+
assert_equal(event_time("2014-01-01T00:00:00+0900"), time)
318+
records << record
319+
end
320+
assert_equal(expected, records)
321+
end
322+
end
323+
304324
private
305325

306326
def create_driver(conf)

0 commit comments

Comments
 (0)