-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support numeric times in time parser formatter #1254
Changes from 4 commits
3a8038d
77c0908
9bd7eac
9682335
aedda70
fb85e9f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,6 +44,7 @@ module CompatParameters | |
BUFFER_TIME_SLICED_PARAMS = { | ||
"time_slice_format" => nil, | ||
"time_slice_wait" => "timekey_wait", | ||
"timezone" => "timekey_zone", | ||
} | ||
|
||
PARSER_PARAMS = { | ||
|
@@ -56,6 +57,7 @@ module CompatParameters | |
"format_firstline" => "format_firstline", # MultilineParser | ||
"message_key" => "message_key", # NoneParser | ||
"with_priority" => "with_priority", # SyslogParser | ||
# There has been no parsers which can handle timezone in v0.12 | ||
} | ||
|
||
INJECT_PARAMS = { | ||
|
@@ -77,7 +79,10 @@ module CompatParameters | |
"json_parser" => "json_parser", # JSONFormatter | ||
"label_delimiter" => "label_delimiter", # LabeledTSVFormatter | ||
"output_time" => "output_time", # OutFileFormatter | ||
"output_tag" => "output_tag", # OutFileFormatter | ||
"output_tag" => "output_tag", # OutFileFormatter | ||
"localtime" => "localtime", # OutFileFormatter | ||
"utc" => "utc", # OutFileFormatter | ||
"timezone" => "timezone", # OutFileFormatter | ||
"message_key" => "message_key", # SingleValueFormatter | ||
"add_newline" => "add_newline", # SingleValueFormatter | ||
"output_type" => "output_type", # StdoutFormatter | ||
|
@@ -129,6 +134,15 @@ def compat_parameters_buffer(conf, default_chunk_key: '') | |
else | ||
raise Fluent::ConfigError, "time_slice_format only with %Y or %m is too long" | ||
end | ||
if conf.has_key?('localtime') || conf.has_key?('utc') | ||
if conf.has_key?('localtime') && conf.has_key?('utc') | ||
raise Fluent::ConfigError, "both of utc and localtime are specified, use only one of them" | ||
elsif conf.has_key?('localtime') | ||
attr['timekey_use_utc'] = !(Fluent::Config.bool_value(conf['localtime'])) | ||
elsif conf.has_key?('utc') | ||
attr['timekey_use_utc'] = Fluent::Config.bool_value(conf['utc']) | ||
end | ||
end | ||
else | ||
if chunk_key == 'time' | ||
attr['timekey'] = 86400 # TimeSliceOutput.time_slice_format default value is '%Y%m%d' | ||
|
@@ -199,6 +213,12 @@ def compat_parameters_formatter(conf) | |
# TODO: warn obsolete parameters if these are deprecated | ||
attr = compat_parameters_copy_to_subsection_attributes(conf, FORMATTER_PARAMS) | ||
|
||
# TODO: make a utility method in TimeFormatter to handle these conversion | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment is still needed? Hard to implement in TimeFormatter? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
# copies of this code: plugin_helper/compat_parameters, compat/formatter_utils and here | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "and here" can be removed. |
||
if conf.has_key?('time_as_epoch') && Fluent::Config.bool_value(conf['time_as_epoch']) | ||
attr['time_type'] = 'unixtime' | ||
end | ||
|
||
e = Fluent::Config::Element.new('format', '', attr, []) | ||
conf.elements << e | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Off topic. Ruby has
Module#attr
method so avoiding same name is better.