mirror of
https://github.com/elastic/logstash.git
synced 2025-04-25 07:07:54 -04:00
ensure plugins are correctly compiled outside of same plugin section
Fixes #5459
This commit is contained in:
parent
6b9de0b490
commit
ed46e475ea
2 changed files with 54 additions and 3 deletions
|
@ -76,6 +76,14 @@ module LogStash; module Config; module AST
|
||||||
@defered_conditionals_index = val
|
@defered_conditionals_index = val
|
||||||
end
|
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
|
class Node < Treetop::Runtime::SyntaxNode
|
||||||
def text_value_for_comments
|
def text_value_for_comments
|
||||||
text_value.gsub(/[\r\n]/, " ")
|
text_value.gsub(/[\r\n]/, " ")
|
||||||
|
@ -86,6 +94,7 @@ module LogStash; module Config; module AST
|
||||||
def compile
|
def compile
|
||||||
LogStash::Config::AST.defered_conditionals = []
|
LogStash::Config::AST.defered_conditionals = []
|
||||||
LogStash::Config::AST.defered_conditionals_index = 0
|
LogStash::Config::AST.defered_conditionals_index = 0
|
||||||
|
LogStash::Config::AST.plugin_instance_index = 0
|
||||||
code = []
|
code = []
|
||||||
|
|
||||||
code << <<-CODE
|
code << <<-CODE
|
||||||
|
@ -140,7 +149,6 @@ module LogStash; module Config; module AST
|
||||||
# like @filter_<name>_1
|
# like @filter_<name>_1
|
||||||
def initialize(*args)
|
def initialize(*args)
|
||||||
super(*args)
|
super(*args)
|
||||||
@i = 0
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Generate ruby code to initialize all the plugins.
|
# Generate ruby code to initialize all the plugins.
|
||||||
|
@ -196,9 +204,9 @@ module LogStash; module Config; module AST
|
||||||
|
|
||||||
plugins.each do |plugin|
|
plugins.each do |plugin|
|
||||||
# Unique number for every plugin.
|
# Unique number for every plugin.
|
||||||
@i += 1
|
LogStash::Config::AST.plugin_instance_index += 1
|
||||||
# store things as ivars, like @filter_grok_3
|
# 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}")
|
# puts("var=#{var.inspect}")
|
||||||
@variables[plugin] = var
|
@variables[plugin] = var
|
||||||
end
|
end
|
||||||
|
|
|
@ -144,6 +144,49 @@ describe LogStashConfigParser do
|
||||||
end
|
end
|
||||||
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
|
context "when creating two instances of the same configuration" do
|
||||||
|
|
||||||
let(:config_string) {
|
let(:config_string) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue