Skip to content
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

in_http: refactoring #3047

Merged
merged 7 commits into from
Jun 22, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
in_http: define initialize to list variables
Signed-off-by: Masahiro Nakagawa <repeatedly@gmail.com>
  • Loading branch information
repeatedly committed Jun 19, 2020
commit ddddb3e856d408a6015a118f40c9efcff33c6a26
31 changes: 24 additions & 7 deletions lib/fluent/plugin/in_http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,29 @@ class HttpInput < Input

EVENT_RECORD_PARAMETER = '_event_record'

def initialize
super

@km = nil
@format_name = nil
@parser_time_key = nil

# default parsers
@parser_msgpack = nil
@parser_json = nil
@default_time_parser = nil
@default_keep_time_key = nil
@float_time_parser = nil

# <parse> configured parser
@custom_parser = nil
end

def configure(conf)
compat_parameters_convert(conf, :parser)

super

@parser = nil
m = if @parser_configs.first['@type'] == 'in_http'
@parser_msgpack = parser_create(usage: 'parser_in_http_msgpack', type: 'msgpack')
@parser_msgpack.time_key = nil
Expand All @@ -108,9 +125,9 @@ def configure(conf)
@default_keep_time_key = default_parser.keep_time_key
method(:parse_params_default)
else
@parser = parser_create
@custom_parser = parser_create
@format_name = @parser_configs.first['@type']
@parser_time_key = @parser.time_key
@parser_time_key = @custom_parser.time_key
method(:parse_params_with_parser)
end
self.singleton_class.module_eval do
Expand Down Expand Up @@ -202,9 +219,9 @@ def on_request(path_info, params)
if param_time = params['time']
param_time = param_time.to_f
single_time = param_time.zero? ? Fluent::EventTime.now : @float_time_parser.parse(param_time)
elsif @parser
single_time = @parser.parse_time(single_record)
single_time, single_record = @parser.convert_values(single_time, single_record)
elsif @custom_parser
single_time = @custom_parser.parse_time(single_record)
single_time, single_record = @custom_parser.convert_values(single_time, single_record)
else
single_time = if t = @default_keep_time_key ? single_record[@parser_time_key] : single_record.delete(@parser_time_key)
if @default_time_parser
Expand Down Expand Up @@ -307,7 +324,7 @@ def parse_params_default(params)

def parse_params_with_parser(params)
if content = params[EVENT_RECORD_PARAMETER]
@parser.parse(content) { |time, record|
@custom_parser.parse(content) { |time, record|
raise "Received event is not #{@format_name}: #{content}" if record.nil?
return time, record
}
Expand Down