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 cf7a950028
commit 2ba8bfd55b
3 changed files with 21 additions and 29 deletions

View file

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

View file

@ -64,7 +64,7 @@ describe LogStashConfigParser do
it "should compile successfully" do
result = subject.parse(config)
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
@ -83,7 +83,7 @@ describe LogStashConfigParser do
it "should compile successfully" do
result = subject.parse(config)
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
@ -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
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
it "rejects a key with multiple double quotes" do
@ -190,7 +190,7 @@ describe LogStashConfigParser do
def initialize(config, settings)
grammar = LogStashConfigParser.new
@config = grammar.parse(config)
@code = @config.compile(false)
@code = @config.compile
eval(@code)
end
def plugin(*args);end
@ -243,7 +243,7 @@ describe LogStashConfigParser do
def initialize(config, settings)
grammar = LogStashConfigParser.new
@config = grammar.parse(config)
@code = @config.compile(false)
@code = @config.compile
eval(@code)
end
def plugin(*args);end