mirror of
https://github.com/elastic/logstash.git
synced 2025-04-24 06:37:19 -04:00
Merge pull request #673 from shadyabhi/fix_prefix_and_include_exclude_keys_related_bug
Fix prefix and include exclude keys related bug
This commit is contained in:
commit
ec9c1d4d1d
2 changed files with 39 additions and 2 deletions
|
@ -207,10 +207,14 @@ class LogStash::Filters::KV < LogStash::Filters::Base
|
|||
end
|
||||
text.scan(@scan_re) do |key, v1, v2, v3|
|
||||
value = v1 || v2 || v3
|
||||
key = @trimkey.nil? ? key : key.gsub(@trimkey_re, "")
|
||||
key = event.sprintf(@prefix) + key
|
||||
key = @trimkey.nil? ? key : key.gsub(@trimkey_re, "")
|
||||
|
||||
# Bail out as per the values of @include_keys and @exclude_keys
|
||||
next if not @include_keys.empty? and not @include_keys.include?(key)
|
||||
next if @exclude_keys.include?(key)
|
||||
|
||||
key = event.sprintf(@prefix) + key
|
||||
|
||||
value = @trim.nil? ? value : value.gsub(@trim_re, "")
|
||||
if kv_keys.has_key?(key)
|
||||
if kv_keys[key].is_a? Array
|
||||
|
|
|
@ -312,6 +312,39 @@ describe LogStash::Filters::KV do
|
|||
end
|
||||
end
|
||||
|
||||
describe "test include_keys with prefix" do
|
||||
config <<-CONFIG
|
||||
filter {
|
||||
kv {
|
||||
include_keys => [ "foo", "singlequoted" ]
|
||||
prefix => "__"
|
||||
}
|
||||
}
|
||||
CONFIG
|
||||
|
||||
sample "hello=world foo=bar baz=fizz doublequoted=\"hello world\" singlequoted='hello world'" do
|
||||
insist { subject["__foo"] } == "bar"
|
||||
insist { subject["__singlequoted"] } == "hello world"
|
||||
end
|
||||
end
|
||||
|
||||
describe "test exclude_keys with prefix" do
|
||||
config <<-CONFIG
|
||||
filter {
|
||||
kv {
|
||||
exclude_keys => [ "foo", "singlequoted" ]
|
||||
prefix => "__"
|
||||
}
|
||||
}
|
||||
CONFIG
|
||||
|
||||
sample "hello=world foo=bar baz=fizz doublequoted=\"hello world\" singlequoted='hello world'" do
|
||||
insist { subject["__hello"] } == "world"
|
||||
insist { subject["__baz"] } == "fizz"
|
||||
insist { subject["__doublequoted"] } == "hello world"
|
||||
end
|
||||
end
|
||||
|
||||
describe "test include_keys and exclude_keys" do
|
||||
config <<-CONFIG
|
||||
filter {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue