Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle fields that do not have a value splitter #103

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/logstash/filters/kv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ def register
Regexp.union(value_patterns)
end

@scan_re = /#{key_pattern}#{value_split_pattern}#{value_pattern}?#{Regexp::union(field_split_pattern, eof)}/
@scan_re = /(?:#{field_split_pattern})?#{key_pattern}#{value_split_pattern}#{value_pattern}?#{Regexp::union(field_split_pattern, eof)}/
@value_split_re = value_split_pattern

@logger.debug? && @logger.debug("KV scan regex", :regex => @scan_re.inspect)
Expand Down
69 changes: 69 additions & 0 deletions spec/filters/kv_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1109,6 +1109,75 @@
it_behaves_like "parse empty values"
end
end

context 'when value splitter is missing from a field' do

shared_examples 'skips valueless keys' do
it 'captures all keys with values' do
subject.filter(event)

aggregate_failures do
expect(event.to_hash).to include('k1' => 'v1')
expect(event.to_hash).to include('k2' => 'v2')
expect(event.to_hash).to_not include('missing')
end
end
end

context 'with multibyte field_split_pattern' do
let(:options) do
{
"field_split_pattern" => '__',
"value_split" => "=",
}
end

context 'at beginning of input' do
include_examples 'skips valueless keys' do
let(:message) { 'missing__k1=v1__k2=v2' }
end
end

context 'at end of input' do
include_examples 'skips valueless keys' do
let(:message) { 'k1=v1__missing__k2=v2' }
end
end

context 'in the middle of input' do
include_examples 'skips valueless keys' do
let(:message) { 'k1=v1__k2=v2__missing' }
end
end
end

context 'with field_split' do
let(:options) do
{
"field_split" => '&',
"value_split" => "=",
}
end

context 'at beginning of input' do
include_examples 'skips valueless keys' do
let(:message) { 'missing&k1=v1&k2=v2' }
end
end

context 'at end of input' do
include_examples 'skips valueless keys' do
let(:message) { 'k1=v1&missing&k2=v2' }
end
end

context 'in the middle of input' do
include_examples 'skips valueless keys' do
let(:message) { 'k1=v1&k2=v2&missing' }
end
end
end
end
end

context 'runtime errors' do
Expand Down