fluent-plugin-mutate_filter 1.0.3 → 1.0.5
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 +4 -4
- data/README.md +2 -0
- data/fluent-plugin-mutate_filter.gemspec +1 -1
- data/lib/fluent/plugin/filter_mutate.rb +15 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ad13425ca3ba43ede3418c4101e3a03ff9caf8c2a92d8c2102e3a505d4d30dfd
|
4
|
+
data.tar.gz: 0d6062dc6cdb02916f3f901a5f834e64fbdce6a6b9c8e5b97403625c30707b2d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8ef466b6c236fc6ea8021038624fa989fc803f1319016a8128ed96aac7f56da84c13b97aab062706bf2ada95352e06327d5c1519141ef254e0d8f30058f6599f
|
7
|
+
data.tar.gz: 9c3f9489112d32c88b5e727fbb73bd9d66d0ae85d7033dde0b25a03e4ca14aa6a0a0bb3fc0eebde04622c0ae475f76f6529b0390a82e88b82b53939d6657390d
|
data/README.md
CHANGED
@@ -95,6 +95,8 @@ Merge the value of source\_field, which may be an Array or a Map, into the key's
|
|
95
95
|
|
96
96
|
Parse a key's value from JSON to a object.
|
97
97
|
|
98
|
+
Additionally, a `@merge_root` boolean field may be defined to have the resulting object be merge into the root of the record.
|
99
|
+
|
98
100
|
##### `rename <new_name>`
|
99
101
|
|
100
102
|
Rename a key to a new key name.
|
@@ -4,8 +4,8 @@ require "fluent/plugin/mixin/mutate_event"
|
|
4
4
|
|
5
5
|
module Fluent
|
6
6
|
module Plugin
|
7
|
-
class
|
8
|
-
Fluent::Plugin.register_filter("
|
7
|
+
class MutateFilter < Fluent::Plugin::Filter
|
8
|
+
Fluent::Plugin.register_filter("mutate", self)
|
9
9
|
|
10
10
|
# Treat periods as nested field names
|
11
11
|
config_param :expand_nesting, :bool, default: true
|
@@ -62,6 +62,11 @@ module Fluent
|
|
62
62
|
end
|
63
63
|
when "parse"
|
64
64
|
data.each do |key, value|
|
65
|
+
if key == "@merge_root"
|
66
|
+
data[key] = Fluent::Config.bool_value(value)
|
67
|
+
next
|
68
|
+
end
|
69
|
+
|
65
70
|
unless VALID_PARSERS.include?(value)
|
66
71
|
raise Fluent::ConfigError, "mutate #{type} action " +
|
67
72
|
"received an invalid type for #{key}, should be one " +
|
@@ -423,6 +428,8 @@ module Fluent
|
|
423
428
|
# Lazily just support json for now
|
424
429
|
# @since 1.0.0
|
425
430
|
def parse(params, event)
|
431
|
+
merge_root = params.delete("@merge_root")
|
432
|
+
|
426
433
|
params.each do |field, parser|
|
427
434
|
value = event.get(field)
|
428
435
|
|
@@ -434,7 +441,12 @@ module Fluent
|
|
434
441
|
if (value.start_with?('{') and value.end_with?('}')) \
|
435
442
|
or (value.start_with?('[') and value.end_with?(']'))
|
436
443
|
value = JSON.load(value)
|
437
|
-
|
444
|
+
|
445
|
+
if merge_root
|
446
|
+
event.update(value)
|
447
|
+
else
|
448
|
+
event.set(field, value)
|
449
|
+
end
|
438
450
|
end
|
439
451
|
end
|
440
452
|
end
|