logstash-filter-kv 4.5.0 → 4.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dba46789cadec9a5f93b5e2922cc6ba05c1fd70100973733e6bbe3960b44512f
4
- data.tar.gz: f806099e1d9cb3ee841c856023960f78d3b3799cc1490d09d366596f9ed42c23
3
+ metadata.gz: 2127186e4a039aaadb013f982c1ed9815827b4c629979a9572a2000a961f3fb1
4
+ data.tar.gz: e79ab76e7787bb89b4aa0e901a78bc0412c3e9344ff6ac7ac23554b56f8f526b
5
5
  SHA512:
6
- metadata.gz: 4dcb8c1bc3d8edc6ac19fffc9b89a0954d7fed9ffba37f21c95e688c81100566daf04fb66f6666f58ac4a338f3611afd5bfee4d02969947dc3d8fbb86e241420
7
- data.tar.gz: 7e91c74720fc32407c2acac971d881fd03950e138ec4b0e76c67ca7087397d29ce7a4570299971cd3ec86b0234685fc87a60a7f5a14d696c6c9fa6412010a9cb
6
+ metadata.gz: 237975f6ce46e4d5e5ac94742ea4b7adc323691d22a670ea37d9ff68f111523ca0f5b6dd3f81bf8c5dd60a60b6dafd11d579e5c4fcfc383c356a43b72f8e277d
7
+ data.tar.gz: bc354d05d413b8781e0baf3076521cd6257baaa49a84650b3182fd076aa91b962558d247d9a8b55ee8485427ccc74e33e0505f97ca38b784b8b3c00333ea926b
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## 4.6.0
2
+ - Added `allow_empty_values` option [#72](https://github.com/logstash-plugins/logstash-filter-kv/pull/72)
3
+
1
4
  ## 4.5.0
2
5
  - Feat: check that target is set in ECS mode [#96](https://github.com/logstash-plugins/logstash-filter-kv/pull/96)
3
6
 
data/docs/index.asciidoc CHANGED
@@ -60,6 +60,7 @@ This plugin supports the following configuration options plus the <<plugins-{typ
60
60
  |=======================================================================
61
61
  |Setting |Input type|Required
62
62
  | <<plugins-{type}s-{plugin}-allow_duplicate_values>> |<<boolean,boolean>>|No
63
+ | <<plugins-{type}s-{plugin}-allow_empty_values>> |<<boolean,boolean>>|No
63
64
  | <<plugins-{type}s-{plugin}-default_keys>> |<<hash,hash>>|No
64
65
  | <<plugins-{type}s-{plugin}-ecs_compatibility>> | <<string,string>>|No
65
66
  | <<plugins-{type}s-{plugin}-exclude_keys>> |<<array,array>>|No
@@ -109,6 +110,17 @@ you could use this configuration:
109
110
  }
110
111
  }
111
112
 
113
+ [id="plugins-{type}s-{plugin}-allow_empty_values"]
114
+ ===== `allow_empty_values`
115
+
116
+ * Value type is <<boolean,boolean>>
117
+ * Default value is `false`
118
+
119
+ A bool option for explicitly including empty values.
120
+ When set to true, empty values will be added to the event.
121
+
122
+ NOTE: Parsing empty values typically requires <<plugins-{type}s-{plugin}-whitespace,`whitespace => strict`>>.
123
+
112
124
  [id="plugins-{type}s-{plugin}-default_keys"]
113
125
  ===== `default_keys`
114
126
 
@@ -272,6 +272,9 @@ class LogStash::Filters::KV < LogStash::Filters::Base
272
272
  # }
273
273
  config :allow_duplicate_values, :validate => :boolean, :default => true
274
274
 
275
+ # A bool option for keeping empty or nil values.
276
+ config :allow_empty_values, :validate => :boolean, :default => false
277
+
275
278
  # A boolean specifying whether to treat square brackets, angle brackets,
276
279
  # and parentheses as value "wrappers" that should be removed from the value.
277
280
  # [source,ruby]
@@ -337,6 +340,9 @@ class LogStash::Filters::KV < LogStash::Filters::Base
337
340
  # Tag to apply if kv errors
338
341
  config :tag_on_failure, :validate => :string, :default => '_kv_filter_error'
339
342
 
343
+
344
+ EMPTY_STRING = ''.freeze
345
+
340
346
  def register
341
347
  # Too late to set the regexp interruptible flag, at least warn if it is not set.
342
348
  require 'java'
@@ -569,12 +575,12 @@ class LogStash::Filters::KV < LogStash::Filters::Base
569
575
  exclude_keys = @exclude_keys.map{|key| event.sprintf(key)}
570
576
 
571
577
  text.scan(@scan_re) do |key, *value_candidates|
572
- value = value_candidates.compact.first
573
- next if value.nil? || value.empty?
578
+ value = value_candidates.compact.first || EMPTY_STRING
579
+ next if value.empty? && !@allow_empty_values
574
580
 
575
- key = @trim_key ? key.gsub(@trim_key_re, "") : key
576
- key = @remove_char_key ? key.gsub(@remove_char_key_re, "") : key
577
- key = @transform_key ? transform(key, @transform_key) : key
581
+ key = key.gsub(@trim_key_re, EMPTY_STRING) if @trim_key
582
+ key = key.gsub(@remove_char_key_re, EMPTY_STRING) if @remove_char_key
583
+ key = transform(key, @transform_key) if @transform_key
578
584
 
579
585
  # Bail out as per the values of include_keys and exclude_keys
580
586
  next if not include_keys.empty? and not include_keys.include?(key)
@@ -583,9 +589,9 @@ class LogStash::Filters::KV < LogStash::Filters::Base
583
589
 
584
590
  key = event.sprintf(@prefix) + key
585
591
 
586
- value = @trim_value ? value.gsub(@trim_value_re, "") : value
587
- value = @remove_char_value ? value.gsub(@remove_char_value_re, "") : value
588
- value = @transform_value ? transform(value, @transform_value) : value
592
+ value = value.gsub(@trim_value_re, EMPTY_STRING) if @trim_value
593
+ value = value.gsub(@remove_char_value_re, EMPTY_STRING) if @remove_char_value
594
+ value = transform(value, @transform_value) if @transform_value
589
595
 
590
596
  # Bail out if inserting duplicate value in key mapping when unique_values
591
597
  # option is set to true.
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
 
3
3
  s.name = 'logstash-filter-kv'
4
- s.version = '4.5.0'
4
+ s.version = '4.6.0'
5
5
  s.licenses = ['Apache License (2.0)']
6
6
  s.summary = "Parses key-value pairs"
7
7
  s.description = "This gem is a Logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This gem is not a stand-alone program"
@@ -721,6 +721,27 @@ describe LogStash::Filters::KV do
721
721
  end
722
722
  end
723
723
 
724
+ describe "Allowing empty values" do
725
+ config <<-CONFIG
726
+ filter {
727
+ kv {
728
+ field_split => " "
729
+ source => "source"
730
+ allow_empty_values => true
731
+ whitespace => strict
732
+ }
733
+ }
734
+ CONFIG
735
+
736
+ sample("source" => "present=one empty= emptyquoted='' present=two emptybracketed=[] endofinput=") do
737
+ insist { subject.get('[present]') } == ['one','two']
738
+ insist { subject.get('[empty]') } == ''
739
+ insist { subject.get('[emptyquoted]') } == ''
740
+ insist { subject.get('[emptybracketed]') } == ''
741
+ insist { subject.get('[endofinput]') } == ''
742
+ end
743
+ end
744
+
724
745
  describe "Allow duplicate key/value pairs by default" do
725
746
  config <<-CONFIG
726
747
  filter {
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-filter-kv
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.5.0
4
+ version: 4.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elastic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-07-14 00:00:00.000000000 Z
11
+ date: 2022-01-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -20,8 +20,8 @@ dependencies:
20
20
  - !ruby/object:Gem::Version
21
21
  version: '2.99'
22
22
  name: logstash-core-plugin-api
23
- type: :runtime
24
23
  prerelease: false
24
+ type: :runtime
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - ">="
@@ -37,8 +37,8 @@ dependencies:
37
37
  - !ruby/object:Gem::Version
38
38
  version: '1.3'
39
39
  name: logstash-mixin-ecs_compatibility_support
40
- type: :runtime
41
40
  prerelease: false
41
+ type: :runtime
42
42
  version_requirements: !ruby/object:Gem::Requirement
43
43
  requirements:
44
44
  - - "~>"
@@ -51,8 +51,8 @@ dependencies:
51
51
  - !ruby/object:Gem::Version
52
52
  version: '1.0'
53
53
  name: logstash-mixin-validator_support
54
- type: :runtime
55
54
  prerelease: false
55
+ type: :runtime
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  requirements:
58
58
  - - "~>"
@@ -65,8 +65,8 @@ dependencies:
65
65
  - !ruby/object:Gem::Version
66
66
  version: '0'
67
67
  name: logstash-devutils
68
- type: :development
69
68
  prerelease: false
69
+ type: :development
70
70
  version_requirements: !ruby/object:Gem::Requirement
71
71
  requirements:
72
72
  - - ">="
@@ -79,8 +79,8 @@ dependencies:
79
79
  - !ruby/object:Gem::Version
80
80
  version: '0'
81
81
  name: insist
82
- type: :development
83
82
  prerelease: false
83
+ type: :development
84
84
  version_requirements: !ruby/object:Gem::Requirement
85
85
  requirements:
86
86
  - - ">="
@@ -125,7 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
125
125
  - !ruby/object:Gem::Version
126
126
  version: '0'
127
127
  requirements: []
128
- rubygems_version: 3.0.6
128
+ rubygems_version: 3.1.6
129
129
  signing_key:
130
130
  specification_version: 4
131
131
  summary: Parses key-value pairs