Revert "PERFORMANCE: Generate more optimal filter_func"

This reverts commit 99a21bc5c1.

Fixes #7943
This commit is contained in:
Armin 2017-08-08 18:12:02 +02:00 committed by Armin Braun
parent 793275c8b5
commit 5e2becbe40
3 changed files with 21 additions and 29 deletions

View file

@ -43,7 +43,7 @@ module LogStash; module Config; module AST
end end
def compile(debug_logging) def compile
LogStash::Config::AST.deferred_conditionals = [] LogStash::Config::AST.deferred_conditionals = []
LogStash::Config::AST.deferred_conditionals_index = 0 LogStash::Config::AST.deferred_conditionals_index = 0
LogStash::Config::AST.plugin_instance_index = 0 LogStash::Config::AST.plugin_instance_index = 0
@ -60,7 +60,7 @@ module LogStash; module Config; module AST
sections = recursive_select(LogStash::Config::AST::PluginSection) sections = recursive_select(LogStash::Config::AST::PluginSection)
sections.each do |s| sections.each do |s|
code << s.compile_initializer(debug_logging) code << s.compile_initializer
end end
# start inputs # start inputs
@ -75,12 +75,12 @@ module LogStash; module Config; module AST
definitions << "define_singleton_method :#{type}_func do |event|" definitions << "define_singleton_method :#{type}_func do |event|"
definitions << " targeted_outputs = []" if type == "output" definitions << " targeted_outputs = []" if type == "output"
definitions << " events = [event]" if type == "filter" definitions << " events = [event]" if type == "filter"
if debug_logging definitions << " @logger.debug? && @logger.debug(\"#{type} received\", \"event\" => event.to_hash)"
definitions << " @logger.debug(\"#{type} received\", \"event\" => event.to_hash)"
end
sections.select { |s| s.plugin_type.text_value == type }.each do |s| sections.select { |s| s.plugin_type.text_value == type }.each do |s|
definitions << s.compile.split("\n", -1).map { |e| " #{e}" } definitions << s.compile.split("\n", -1).map { |e| " #{e}" }
end end
definitions << " events" if type == "filter" definitions << " events" if type == "filter"
definitions << " targeted_outputs" if type == "output" definitions << " targeted_outputs" if type == "output"
definitions << "end" definitions << "end"
@ -104,7 +104,7 @@ module LogStash; module Config; module AST
end end
# Generate ruby code to initialize all the plugins. # Generate ruby code to initialize all the plugins.
def compile_initializer(debug_logging) def compile_initializer
generate_variables generate_variables
code = [] code = []
@variables.each do |plugin, name| @variables.each do |plugin, name|
@ -120,22 +120,14 @@ module LogStash; module Config; module AST
code << <<-CODE code << <<-CODE
@generated_objects[:#{name}_flush] = lambda do |options, &block| @generated_objects[:#{name}_flush] = lambda do |options, &block|
CODE @logger.debug? && @logger.debug(\"Flushing\", :plugin => @generated_objects[:#{name}])
if debug_logging
code << <<-CODE
@logger.debug(\"Flushing\", :plugin => @generated_objects[:#{name}])
CODE
end
code << <<-CODE
events = @generated_objects[:#{name}].flush(options) events = @generated_objects[:#{name}].flush(options)
return if events.nil? || events.empty? return if events.nil? || events.empty?
CODE
if debug_logging @logger.debug? && @logger.debug(\"Flushing\", :plugin => @generated_objects[:#{name}], :events => events.map { |x| x.to_hash })
code << <<-CODE
@logger.debug(\"Flushing\", :plugin => @generated_objects[:#{name}], :events => events.map { |x| x.to_hash })
CODE
end
code << <<-CODE
#{plugin.compile_starting_here.gsub(/^/, " ")} #{plugin.compile_starting_here.gsub(/^/, " ")}
events.each{|e| block.call(e)} events.each{|e| block.call(e)}

View file

@ -68,7 +68,7 @@ module LogStash; class BasePipeline
raise(ConfigurationError, grammar.failure_reason) if parsed_config.nil? raise(ConfigurationError, grammar.failure_reason) if parsed_config.nil?
parsed_config.process_escape_sequences = settings.get_value("config.support_escapes") parsed_config.process_escape_sequences = settings.get_value("config.support_escapes")
config_code = parsed_config.compile(@logger.debug?) config_code = parsed_config.compile
# config_code = BasePipeline.compileConfig(config_str) # config_code = BasePipeline.compileConfig(config_str)

View file

@ -64,7 +64,7 @@ describe LogStashConfigParser do
it "should compile successfully" do it "should compile successfully" do
result = subject.parse(config) result = subject.parse(config)
expect(result).not_to(be_nil) expect(result).not_to(be_nil)
expect { eval(result.compile(false)) }.not_to(raise_error) expect { eval(result.compile) }.not_to(raise_error)
end end
end end
@ -83,7 +83,7 @@ describe LogStashConfigParser do
it "should compile successfully" do it "should compile successfully" do
result = subject.parse(config) result = subject.parse(config)
expect(result).not_to(be_nil) expect(result).not_to(be_nil)
expect { eval(result.compile(false)) }.not_to(raise_error) expect { eval(result.compile) }.not_to(raise_error)
end end
end end
@ -103,7 +103,7 @@ describe LogStashConfigParser do
} }
)) ))
expect { config.compile(false) }.to raise_error(LogStash::ConfigurationError, /Duplicate keys found in your configuration: \["message"\]/) expect { config.compile }.to raise_error(LogStash::ConfigurationError, /Duplicate keys found in your configuration: \["message"\]/)
end end
it "rejects duplicate keys in nested hash" do it "rejects duplicate keys in nested hash" do
@ -122,7 +122,7 @@ describe LogStashConfigParser do
} }
)) ))
expect { config.compile(false) }.to raise_error(LogStash::ConfigurationError, /Duplicate keys found in your configuration: \["cool"\]/) expect { config.compile }.to raise_error(LogStash::ConfigurationError, /Duplicate keys found in your configuration: \["cool"\]/)
end end
it "rejects a key with multiple double quotes" do it "rejects a key with multiple double quotes" do
@ -190,7 +190,7 @@ describe LogStashConfigParser do
def initialize(config, settings) def initialize(config, settings)
grammar = LogStashConfigParser.new grammar = LogStashConfigParser.new
@config = grammar.parse(config) @config = grammar.parse(config)
@code = @config.compile(false) @code = @config.compile
eval(@code) eval(@code)
end end
def plugin(*args);end def plugin(*args);end
@ -243,7 +243,7 @@ describe LogStashConfigParser do
def initialize(config, settings) def initialize(config, settings)
grammar = LogStashConfigParser.new grammar = LogStashConfigParser.new
@config = grammar.parse(config) @config = grammar.parse(config)
@code = @config.compile(false) @code = @config.compile
eval(@code) eval(@code)
end end
def plugin(*args);end def plugin(*args);end