avoid resetting inexisting tags field back to empty array plus specs

Fixes #6477
This commit is contained in:
Colin Surprenant 2017-01-03 17:09:56 -05:00 committed by Suyog Rao
parent 733a546e9e
commit eb00b0da4c
2 changed files with 18 additions and 3 deletions

View file

@ -34,8 +34,9 @@ module LogStash::Util
# tags is an array of string. sprintf syntax can be used.
def add_tags(new_tags, event, pluginname)
tags = event.get("tags")
tags = tags.nil? ? [] : Array(tags)
return if new_tags.empty?
tags = Array(event.get("tags")) # note that Array(nil) => []
new_tags.each do |new_tag|
new_tag = event.sprintf(new_tag)

View file

@ -248,7 +248,21 @@ describe LogStash::Filters::NOOP do
end
end
describe "remove_field on deep objects" do
describe "remove_field on tags" do
config <<-CONFIG
filter {
noop {
remove_field => ["tags"]
}
}
CONFIG
sample("tags" => "foo") do
reject { subject }.include?("tags")
end
end
describe "remove_field on deep objects" do
config <<-CONFIG
filter {
noop {