Merge config values in LIR

Fixes #10832
This commit is contained in:
Dan Hermann 2019-05-28 12:38:55 -05:00
parent 3d84827174
commit 8685d1d483
2 changed files with 29 additions and 1 deletions

View file

@ -111,7 +111,7 @@ module LogStashCompilerLSCLGrammar; module LogStash; module Compiler; module LSC
# hash value; e.g., `{"match" => {"baz" => "bar"}, "match" => {"foo" => "bulb"}}` is
# interpreted as `{"match" => {"baz" => "bar", "foo" => "blub"}}`.
# (NOTE: this bypasses `AST::Hash`'s ability to detect duplicate keys)
hash[k] = existing.merge(v)
hash[k] = ::LogStash::Util.hash_merge_many(existing, v)
elsif existing.kind_of?(::Array)
hash[k] = existing.push(*v)
else

View file

@ -252,6 +252,34 @@ describe LogStash::Compiler do
expect(c_plugin).to ir_eql(j.iPlugin(rand_meta, FILTER, "grok", expected_plugin_args))
end
describe "a filter plugin with a repeated hash directive with duplicated keys" do
let(:source) { "input { } filter { #{plugin_source} } output { } " }
let(:plugin_source) do
%q[
grok {
match => { "message" => "foo" }
match => { "message" => "bar" }
break_on_match => false
}
]
end
subject(:c_plugin) { compiled[:filter] }
let(:expected_plugin_args) do
{
"match" => {
"message" => ["foo", "bar"]
},
"break_on_match" => "false"
}
end
it "should merge the values of the duplicate keys into an array" do
expect(c_plugin).to ir_eql(j.iPlugin(rand_meta, FILTER, "grok", expected_plugin_args))
end
end
describe "a filter plugin that has nested Hash directives" do
let(:source) { "input { } filter { #{plugin_source} } output { } " }
let(:plugin_source) do