fluent-plugin-mutate_filter 1.0.2 → 1.0.3

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
2
  SHA256:
3
- metadata.gz: db927fe75f56601c192cfa5fd529914924e5687657a378689f6f8592bf5086e3
4
- data.tar.gz: 1ff7de058212f4a1fe40b7551aaba991bb639adc1f826ebdc1c2d9c32f330842
3
+ metadata.gz: 79f746bd9c44d86ef7ab074a10776185edd537fb420d0cdef9c4f73ae7caa043
4
+ data.tar.gz: baeed48ef9eced0336745871771a724ebcd759e48f09f700b367a60abe0af97c
5
5
  SHA512:
6
- metadata.gz: 22493004009aec2f36b024b9e6974420f2adf2afa22440ca94c824510beb8bf943d8c72b2f0aaa7725af303d25aa60654da0180262b67928ebe9eff8563f409f
7
- data.tar.gz: 87685349ff798b6e423d125fd23709d0e195d11d00d55826de8094142fd2d293405f18c5db5735cde2a98bf3372a1ac552010407198b056e7ab8aadeb8a81a1b
6
+ metadata.gz: f1bc65b2293d7bd5bacd2141f6ab9c9c1986c01f9a7bbe687636daef2fe5cc86765b674a6d56131b6e7b36e61ec85044c872e484fc5c101510d9079850d1c125
7
+ data.tar.gz: 9a79a1e2cb37ffbc1c04690fde427f8a995b61f0008ba94a843ba9975ce5ae37e1be73fe432c06b73c563507874e9b5d16cb8a3d8e8be10f0291615cdc3fae08
@@ -3,7 +3,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
 
4
4
  Gem::Specification.new do |spec|
5
5
  spec.name = "fluent-plugin-mutate_filter"
6
- spec.version = "1.0.2"
6
+ spec.version = "1.0.3"
7
7
  spec.authors = ["Jonathan Serafini"]
8
8
  spec.email = ["jonathan@serafini.ca"]
9
9
 
@@ -4,8 +4,8 @@ require "fluent/plugin/mixin/mutate_event"
4
4
 
5
5
  module Fluent
6
6
  module Plugin
7
- class MutateFilter < Fluent::Plugin::Filter
8
- Fluent::Plugin.register_filter("mutate", self)
7
+ class MutateFilter2 < Fluent::Plugin::Filter
8
+ Fluent::Plugin.register_filter("mutate2", self)
9
9
 
10
10
  # Treat periods as nested field names
11
11
  config_param :expand_nesting, :bool, default: true
@@ -171,31 +171,27 @@ module Fluent
171
171
  def expand_references(event, string)
172
172
  new_string = ''
173
173
 
174
- position = 0
175
- matches = string.scan(TEMPLATE_TAG_REGEXP).map{|m| $~}
176
-
177
- matches.each do |match|
174
+ while match = string.match(TEMPLATE_TAG_REGEXP) do
178
175
  reference_tag = match[0][2..-2]
179
176
  reference_value = case reference_tag
180
177
  when "event_time" then event.event_time.to_s
181
178
  when "event_tag" then event.event_tag
182
179
  else event.get(reference_tag.downcase).to_s
183
180
  end
184
- if reference_value.nil?
181
+
182
+ if reference_value == ""
185
183
  @log.error "failed to replace tag", field: reference_tag.downcase
186
184
  reference_value = match.to_s
187
185
  end
188
186
 
189
187
  start = match.offset(0).first
190
- new_string << string[position..(start-1)] if start > 0
188
+ new_string << string[0..(start-1)] if start > 0
191
189
  new_string << reference_value
192
- position = match.offset(0).last
193
- end
194
190
 
195
- if position < string.size
196
- new_string << string[position..-1]
191
+ string = string[match.offset(0).last..-1]
197
192
  end
198
193
 
194
+ new_string << string
199
195
  new_string
200
196
  end
201
197
 
@@ -205,30 +201,26 @@ module Fluent
205
201
  def expand_environment(event, string)
206
202
  new_string = ''
207
203
 
208
- position = 0
209
- matches = string.scan(ENVIRONMENT_TAG_REGEXP).map{|m| $~}
210
-
211
- matches.each do |match|
204
+ while match = string.match(ENVIRONMENT_TAG_REGEXP) do
212
205
  reference_tag = match[0][3..-2]
213
206
  reference_value = case reference_tag
214
207
  when "hostname" then Socket.gethostname
215
208
  else ENV[reference_tag]
216
209
  end
217
- if reference_value.nil?
210
+
211
+ if reference_value == ""
218
212
  @log.error "failed to replace tag", field: reference_tag
219
213
  reference_value = match.to_s
220
214
  end
221
215
 
222
216
  start = match.offset(0).first
223
- new_string << string[position..(start-1)] if start > 0
217
+ new_string << string[0..(start-1)] if start > 0
224
218
  new_string << reference_value
225
- position = match.offset(0).last
226
- end
227
219
 
228
- if position < string.size
229
- new_string << string[position..-1]
220
+ string = string[match.offset(0).last..-1]
230
221
  end
231
222
 
223
+ new_string << string
232
224
  new_string
233
225
  end
234
226
 
@@ -29,9 +29,22 @@ module Fluent
29
29
  end
30
30
 
31
31
  def prune
32
- delete_proc = proc do |_,v|
33
- v.delete_if(&delete_proc) if v.respond_to?(:delete_if)
34
- v.nil? || v.respond_to?(:empty?) && v.empty?
32
+ delete_proc = proc do |*args|
33
+ v = args[-1]
34
+
35
+ if v.respond_to?(:delete_if)
36
+ v.delete_if(&delete_proc)
37
+ end
38
+
39
+ if v.respond_to?(:strip)
40
+ v = v.strip
41
+ end
42
+
43
+ if v.respond_to?(:empty?) and v.empty?
44
+ v = nil
45
+ end
46
+
47
+ v.nil?
35
48
  end
36
49
 
37
50
  @record.delete_if(&delete_proc)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-mutate_filter
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Serafini