logstash-filter-esquerystring 1.2.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA256:
3
- metadata.gz: '0608e5bf3e3a027b7ebfcbd6eb83fdef7de8caea701c20add1d4cccfa62a5c92'
4
- data.tar.gz: d7bdabec91119b6ed833fe789f0c2413d31faa616fcea8e4c3d87ef55dc011f8
2
+ SHA1:
3
+ metadata.gz: 0bc48d1cf1d787b54b63d96f00195787056a2cc8
4
+ data.tar.gz: ff744149a3c8702e851bc720505ab36481f30eae
5
5
  SHA512:
6
- metadata.gz: 3ad22fc8ece75dcceeacfa366a5777f76c1280b5a180e5676c3dc619e5e9fc19771c53c0727fa71a80695fc9cb5e7c836ca96b63c30ca6de51fc907d5b821651
7
- data.tar.gz: 8dbe2b99216417fba9080ded313b3d7702ba50588b21828b97cbc9ca4489eaed9db1943eac4ca0f9f4bf9d3db0dfc85d3271b420c0a142070befb492404ff42d
6
+ metadata.gz: 67f92b43df01f7a3bf3a9c94f8a23eb03ae00237233e537681669df95696eb1991c4707a9ab023891fad9dc549cc574f45938f6d5c541fac0c35f00962c9c935
7
+ data.tar.gz: 9e65a1a31e2f3f4c4b85850ec73094698b91cf2a7909dd44ce3bab16f8632067f2b308dac981d0629898177e2a575af018b3e54a3f1f24f49f44fe80220a3186
@@ -7,6 +7,8 @@ class LogStash::Filters::Esquerystring < LogStash::Filters::Base
7
7
 
8
8
  config :source, :validate => :array, :required => true
9
9
  config :target, :validate => :string, :required => true
10
+ config :maxlength, :validate => :number, :default => 4096, :required => false
11
+ config :length_autofix, :validate => :boolean, :default => false, :required => false
10
12
 
11
13
  public
12
14
  def register
@@ -27,8 +29,23 @@ class LogStash::Filters::Esquerystring < LogStash::Filters::Base
27
29
  end
28
30
 
29
31
  return if values.length == 0
30
- values = "(" + values.uniq.map { |x| '"' + x + '"' }.join(" OR ") + ")"
31
- event.set(@target, values)
32
+ values = values.uniq.map { |x| '"' + x + '"' }
33
+ values_str = "(" + values.join(" OR ") + ")"
34
+ if values_str.length > @maxlength
35
+ msg = "Produced too long query string (>#{@maxlength}): #{values_str}"
36
+ if @length_autofix
37
+ while values_str.length > @maxlength
38
+ values.pop
39
+ values_str = "(" + values.join(" OR ") + ")"
40
+ end
41
+ @logger.warn(msg + "; Autofixed to: #{values_str}")
42
+ event.set(@target, values_str)
43
+ else
44
+ @logger.error(msg)
45
+ end
46
+ else
47
+ event.set(@target, values_str)
48
+ end
32
49
  end # def filter
33
50
 
34
51
  end # class LogStash::Filters::Esquerystring
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
 
3
3
  s.name = 'logstash-filter-esquerystring'
4
- s.version = '1.2.0'
4
+ s.version = '1.3.0'
5
5
  s.licenses = ['Apache-2.0']
6
6
  s.summary = "This filter converts values of source field to elasticsearch query string"
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"
@@ -94,4 +94,38 @@ describe LogStash::Filters::Esquerystring do
94
94
  insist { subject.get("dst") } == '("arg1" OR "arg2")'
95
95
  end
96
96
  end
97
+
98
+ describe "esquerystring string with too long array and without autofix" do
99
+ config <<-CONFIG
100
+ filter {
101
+ esquerystring {
102
+ source => "src"
103
+ target => "dst"
104
+ maxlength => 20
105
+ length_autofix => false
106
+ }
107
+ }
108
+ CONFIG
109
+
110
+ sample("src" => ["arg1", "arg2", "arg3", "arg4"]) do
111
+ insist { subject.get("dst") } == nil
112
+ end
113
+ end
114
+
115
+ describe "esquerystring string with too long array and with autofix" do
116
+ config <<-CONFIG
117
+ filter {
118
+ esquerystring {
119
+ source => "src"
120
+ target => "dst"
121
+ maxlength => 20
122
+ length_autofix => true
123
+ }
124
+ }
125
+ CONFIG
126
+
127
+ sample("src" => ["arg1", "arg2", "arg3", "arg4"]) do
128
+ insist { subject.get("dst") } == '("arg1" OR "arg2")'
129
+ end
130
+ end
97
131
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-filter-esquerystring
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elastic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-13 00:00:00.000000000 Z
11
+ date: 2018-01-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -84,7 +84,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
84
84
  version: '0'
85
85
  requirements: []
86
86
  rubyforge_project:
87
- rubygems_version: 2.6.11
87
+ rubygems_version: 2.6.14
88
88
  signing_key:
89
89
  specification_version: 4
90
90
  summary: This filter converts values of source field to elasticsearch query string