mirror of
https://github.com/elastic/logstash.git
synced 2025-04-24 06:37:19 -04:00
ensure plugins are correctly compiled outside of same plugin section
Fixes #5459
This commit is contained in:
parent
c5610505c7
commit
f29ff3186f
2 changed files with 54 additions and 3 deletions
|
@ -76,6 +76,14 @@ module LogStash; module Config; module AST
|
|||
@defered_conditionals_index = val
|
||||
end
|
||||
|
||||
def self.plugin_instance_index
|
||||
@plugin_instance_index
|
||||
end
|
||||
|
||||
def self.plugin_instance_index=(val)
|
||||
@plugin_instance_index = val
|
||||
end
|
||||
|
||||
class Node < Treetop::Runtime::SyntaxNode
|
||||
def text_value_for_comments
|
||||
text_value.gsub(/[\r\n]/, " ")
|
||||
|
@ -86,6 +94,7 @@ module LogStash; module Config; module AST
|
|||
def compile
|
||||
LogStash::Config::AST.defered_conditionals = []
|
||||
LogStash::Config::AST.defered_conditionals_index = 0
|
||||
LogStash::Config::AST.plugin_instance_index = 0
|
||||
code = []
|
||||
|
||||
code << <<-CODE
|
||||
|
@ -140,7 +149,6 @@ module LogStash; module Config; module AST
|
|||
# like @filter_<name>_1
|
||||
def initialize(*args)
|
||||
super(*args)
|
||||
@i = 0
|
||||
end
|
||||
|
||||
# Generate ruby code to initialize all the plugins.
|
||||
|
@ -196,9 +204,9 @@ module LogStash; module Config; module AST
|
|||
|
||||
plugins.each do |plugin|
|
||||
# Unique number for every plugin.
|
||||
@i += 1
|
||||
LogStash::Config::AST.plugin_instance_index += 1
|
||||
# store things as ivars, like @filter_grok_3
|
||||
var = :"#{plugin.plugin_type}_#{plugin.plugin_name}_#{@i}"
|
||||
var = :"#{plugin.plugin_type}_#{plugin.plugin_name}_#{LogStash::Config::AST.plugin_instance_index}"
|
||||
# puts("var=#{var.inspect}")
|
||||
@variables[plugin] = var
|
||||
end
|
||||
|
|
|
@ -144,6 +144,49 @@ describe LogStashConfigParser do
|
|||
end
|
||||
end
|
||||
|
||||
context "when using two plugin sections of the same type" do
|
||||
let(:pipeline_klass) do
|
||||
Class.new do
|
||||
def initialize(config)
|
||||
grammar = LogStashConfigParser.new
|
||||
@config = grammar.parse(config)
|
||||
@code = @config.compile
|
||||
eval(@code)
|
||||
end
|
||||
def plugin(*args);end
|
||||
end
|
||||
end
|
||||
context "(filters)" do
|
||||
let(:config_string) {
|
||||
"input { generator { } }
|
||||
filter { filter1 { } }
|
||||
filter { filter1 { } }
|
||||
output { output1 { } }"
|
||||
}
|
||||
|
||||
|
||||
it "should create a pipeline with both sections" do
|
||||
generated_objects = pipeline_klass.new(config_string).instance_variable_get("@generated_objects")
|
||||
filters = generated_objects.keys.map(&:to_s).select {|obj_name| obj_name.match(/^filter.+?_\d+$/) }
|
||||
expect(filters.size).to eq(2)
|
||||
end
|
||||
end
|
||||
|
||||
context "(filters)" do
|
||||
let(:config_string) {
|
||||
"input { generator { } }
|
||||
output { output1 { } }
|
||||
output { output1 { } }"
|
||||
}
|
||||
|
||||
|
||||
it "should create a pipeline with both sections" do
|
||||
generated_objects = pipeline_klass.new(config_string).instance_variable_get("@generated_objects")
|
||||
outputs = generated_objects.keys.map(&:to_s).select {|obj_name| obj_name.match(/^output.+?_\d+$/) }
|
||||
expect(outputs.size).to eq(2)
|
||||
end
|
||||
end
|
||||
end
|
||||
context "when creating two instances of the same configuration" do
|
||||
|
||||
let(:config_string) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue