logstash-filter-mutate 3.4.0 → 3.5.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: d864cb702460a9b6b7ab2d3bcf7983df039730306118771e0e62e2f87754c31c
4
- data.tar.gz: ee2729fb05d2a18426d8419b917df4137ca90bfd5e45fa4a99a1f32e2ebb5317
3
+ metadata.gz: 69f20a428551c3f5ddd1667b08cc5b8138f66f8e966aeb797ccda27684dd4e13
4
+ data.tar.gz: 0c0875f25f5feb9beba83a08ddb0c1576f11a72c3596c2d0c4fd7acc3ac715ed
5
5
  SHA512:
6
- metadata.gz: 0e01156ec1b9be737f2a291a95a270a1a07e90fac8e62ffbebbc1a81db9d983bda817a7539bd9827b4d919abe4defe6cbf1d3755d51e38c76c26a520d90846ca
7
- data.tar.gz: 7998a5a7475514816ab8d83f3749dcb7a54c88a2f510da66b57711c4b7282be70b4290f24b3dc2f71872fb8193824d00f02c8f99d67ed4710fc83ace5a396abf
6
+ metadata.gz: 93692404a440374e0b958222b3ee13dac1d1e54822c3fb119e3fdfc1af328a644aef58cc5f4f92dcf3ee20820c17f773504f4d3ed44f91e7982ab5033829984c
7
+ data.tar.gz: 73a58d81336dc139c41c1c50e55d90c59a7cadd3016864cfc5affd96766241940e203efb24b1b9cb6d79608997f0492d80be4ffa501bc02242b25c18d5dcd809
@@ -83,6 +83,7 @@ This plugin supports the following configuration options plus the <<plugins-{typ
83
83
  | <<plugins-{type}s-{plugin}-update>> |<<hash,hash>>|No
84
84
  | <<plugins-{type}s-{plugin}-uppercase>> |<<array,array>>|No
85
85
  | <<plugins-{type}s-{plugin}-capitalize>> |<<array,array>>|No
86
+ | <<plugins-{type}s-{plugin}-tag_on_failure>> |<<string,string>>|No
86
87
  |=======================================================================
87
88
 
88
89
  Also see <<plugins-{type}s-{plugin}-common-options>> for a list of options supported by all
@@ -372,5 +373,14 @@ Example:
372
373
  }
373
374
  }
374
375
 
376
+ [id="plugins-{type}s-{plugin}-tag_on_failure"]
377
+ ===== `tag_on_failure`
378
+
379
+ * Value type is <<string,string>>
380
+ * The default value for this setting is `_mutate_error`
381
+
382
+ If a failure occurs during the application of this mutate filter, the rest of
383
+ the operations are aborted and the provided tag is added to the event.
384
+
375
385
  [id="plugins-{type}s-{plugin}-common-options"]
376
386
  include::{include_path}/{type}.asciidoc[]
@@ -207,6 +207,9 @@ class LogStash::Filters::Mutate < LogStash::Filters::Base
207
207
  # }
208
208
  config :copy, :validate => :hash
209
209
 
210
+ # Tag to apply if the operation errors
211
+ config :tag_on_failure, :validate => :string, :default => '_mutate_error'
212
+
210
213
  TRUE_REGEX = (/^(true|t|yes|y|1|1.0)$/i).freeze
211
214
  FALSE_REGEX = (/^(false|f|no|n|0|0.0)$/i).freeze
212
215
  CONVERT_PREFIX = "convert_".freeze
@@ -262,6 +265,11 @@ class LogStash::Filters::Mutate < LogStash::Filters::Base
262
265
  copy(event) if @copy
263
266
 
264
267
  filter_matched(event)
268
+ rescue => ex
269
+ meta = { :exception => ex.message }
270
+ meta[:backtrace] = ex.backtrace if logger.debug?
271
+ logger.warn('Exception caught while applying mutate filter', meta)
272
+ event.tag(@tag_on_failure)
265
273
  end
266
274
 
267
275
  private
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
 
3
3
  s.name = 'logstash-filter-mutate'
4
- s.version = '3.4.0'
4
+ s.version = '3.5.0'
5
5
  s.licenses = ['Apache License (2.0)']
6
6
  s.summary = "Performs mutations on fields"
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"
@@ -23,6 +23,56 @@ module LogStash::Environment
23
23
  end
24
24
  end
25
25
 
26
+ logstash_version = Gem::Version.create(LOGSTASH_CORE_VERSION)
27
+
28
+ if (Gem::Requirement.create('~> 7.0').satisfied_by?(logstash_version) ||
29
+ (Gem::Requirement.create('~> 6.4').satisfied_by?(logstash_version) && LogStash::SETTINGS.get('config.field_reference.parser') == 'STRICT'))
30
+ describe LogStash::Filters::Mutate do
31
+ let(:config) { Hash.new }
32
+ subject(:mutate_filter) { LogStash::Filters::Mutate.new(config) }
33
+
34
+ before(:each) { mutate_filter.register }
35
+
36
+ let(:event) { LogStash::Event.new(attrs) }
37
+
38
+ context 'when operation would cause an error' do
39
+
40
+ let(:invalid_field_name) { "[[][[[[]message" }
41
+ let(:config) do
42
+ super().merge("add_field" => {invalid_field_name => "nope"})
43
+ end
44
+
45
+ shared_examples('catch and tag error') do
46
+ let(:expected_tag) { '_mutate_error' }
47
+
48
+ let(:event) { LogStash::Event.new({"message" => "foo"})}
49
+
50
+ context 'when the event is filtered' do
51
+ before(:each) { mutate_filter.filter(event) }
52
+ it 'does not raise an exception' do
53
+ # noop
54
+ end
55
+
56
+ it 'tags the event with the expected tag' do
57
+ expect(event).to include('tags')
58
+ expect(event.get('tags')).to include(expected_tag)
59
+ end
60
+ end
61
+ end
62
+
63
+ context 'when `tag_on_failure` is not provided' do
64
+ include_examples 'catch and tag error'
65
+ end
66
+
67
+ context 'when `tag_on_failure` is provided' do
68
+ include_examples 'catch and tag error' do
69
+ let(:expected_tag) { 'my_custom_tag' }
70
+ let(:config) { super().merge('tag_on_failure' => expected_tag) }
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
26
76
 
27
77
  describe LogStash::Filters::Mutate do
28
78
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-filter-mutate
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.4.0
4
+ version: 3.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elastic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-02-04 00:00:00.000000000 Z
11
+ date: 2019-06-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement